def _compute_values(cls, standard, rule):
        # Remember to support also time zones that differ from UTC by not
        # exact hours (e.g. Australia/Adelaide)
        if not rule:
            now = _datetime.datetime.now()
            nextdate = _datetime.datetime(now.year, now.month, now.day,
                                    now.hour) + _datetime.timedelta(hours=1)
            refstart = int(_time.mktime(nextdate.timetuple())) - \
                                                UTCOffset.compute2_current()

            values = {
                'reference_start': refstart,
                'interval': 86400,
                'overlaps': 0,
                'bgap': 86400 - 3600,
                'end_relative_time': 3600,
                'inclusive': False,
                'end_type': 0,
                'time_standard': standard,
            }
        else:
            values = {
                'reference_start': rule[0],
                'interval': rule[1],
                'overlaps': rule[2],
                'bgap': rule[3],
                'end_relative_time': rule[4] if rule[4] is not None else 3600,
                'inclusive': rule[5],
                'end_type': rule[6][0],
                'time_standard': standard,
            }

        wstart = _datetime.datetime.utcfromtimestamp(
                                            values['reference_start'])
        wend = _datetime.datetime.utcfromtimestamp(
                                            values['reference_start'] +
                                            values['end_relative_time'])

        values['interval_number'], values['interval_unit'] = \
                                        TimeSpanCtrl.compute_widget_values(
                                        values['interval'])

        values['end_relative_number'], values['end_relative_unit'] = \
                                        TimeSpanCtrl.compute_widget_values(
                                        values['end_relative_time'])

        values.update({
            'start_year': wstart.year,
            'start_month': wstart.month - 1,
            'start_day': wstart.day,
            'start_hour': wstart.hour,
            'start_minute': wstart.minute,
            'end_year': wend.year,
            'end_month': wend.month - 1,
            'end_day': wend.day,
            'end_hour': wend.hour,
            'end_minute': wend.minute,
        })

        return values
Example #2
0
    def _compute_values(cls, standard, rule):
        # Remember to support also time zones that differ from UTC by not
        # exact hours (e.g. Australia/Adelaide)
        if not rule:
            now = _datetime.datetime.now()
            nextdate = _datetime.datetime(now.year, now.month, now.day,
                                    now.hour) + _datetime.timedelta(hours=1)
            refstart = int(_time.mktime(nextdate.timetuple())) - \
                                                UTCOffset.compute2_current()
            currw = nextdate.weekday()

            values = {
                'reference_start': refstart,
                'interval': 604800,
                'overlaps': 0,
                'bgap': 604800 - 3600,
                'end_relative_time': 3600,
                'alarm_relative_time': 0,
                'end_type': 0,
                'alarm_type': 0,
                'time_standard': standard,
            }
        else:
            values = {
                'reference_start': rule[0],
                'interval': rule[1],
                'overlaps': rule[2],
                'bgap': rule[3],
                'end_relative_time': rule[4] if rule[4] is not None else 3600,
                'alarm_relative_time': rule[5] if rule[5] is not None else 0,
                'end_type': rule[6][1],
                'alarm_type': rule[6][2],
                'time_standard': standard,
            }

            currw = _datetime.datetime.utcfromtimestamp(
                                        values['reference_start']).weekday()

        values['end_relative_number'], values['end_relative_unit'] = \
                                TimeSpanCtrl.compute_widget_values(
                                values['end_relative_time'])

        # ralarm could be negative
        values['alarm_relative_number'], values['alarm_relative_unit'] = \
                                TimeSpanCtrl.compute_widget_values(
                                max((0, values['alarm_relative_time'])))

        rrstart = values['reference_start'] % 86400

        rrend = rrstart + values['end_relative_time']
        values['end_next_day'] = False

        # End time could be set after 23:59 of the start day
        if rrend > 86399:
            rrend = rrend % 86400
            values['end_next_day'] = True

        rralarm = rrstart - values['alarm_relative_time']
        values['alarm_previous_day'] = False

        # Alarm time could be set before 00:00 of the start day
        if rralarm < 0:
            rralarm = 86400 - abs(rralarm) % 86400
            values['alarm_previous_day'] = True

        values.update({
            'start_weekday': WeekDayHourCtrl.compute_widget_day(currw),
            'start_hour': rrstart // 3600,
            'start_minute': rrstart % 3600 // 60,
            'end_hour': rrend // 3600,
            'end_minute': rrend % 3600 // 60,
            'alarm_hour': rralarm // 3600,
            'alarm_minute': rralarm % 3600 // 60,
        })

        return values
    def _compute_values(cls, standard, rule):
        # Remember to support also time zones that differ from UTC by not
        # exact hours (e.g. Australia/Adelaide)
        if not rule:
            now = _datetime.datetime.now()
            nextdate = _datetime.datetime(now.year, now.month, now.day, now.hour) + _datetime.timedelta(hours=1)
            refstart = int(_time.mktime(nextdate.timetuple())) - UTCOffset.compute2_current()

            values = {
                "reference_start": refstart,
                "interval": 2551443,
                "overlaps": 0,
                "bgap": 2551443 - 3600,
                "end_relative_time": 3600,
                "alarm_relative_time": 0,
                "end_type": 0,
                "alarm_type": 0,
                "time_standard": standard,
            }
        else:
            values = {
                "reference_start": rule[0],
                "interval": rule[1],
                "overlaps": rule[2],
                "bgap": rule[3],
                "end_relative_time": rule[4] if rule[4] is not None else 3600,
                "alarm_relative_time": rule[5] if rule[5] is not None else 0,
                "end_type": rule[6][1],
                "alarm_type": rule[6][2],
                "time_standard": standard,
            }

        wstart = _datetime.datetime.utcfromtimestamp(values["reference_start"])
        wend = _datetime.datetime.utcfromtimestamp(values["reference_start"] + values["end_relative_time"])
        walarm = _datetime.datetime.utcfromtimestamp(values["reference_start"] - values["alarm_relative_time"])

        values["end_relative_number"], values["end_relative_unit"] = TimeSpanCtrl.compute_widget_values(
            values["end_relative_time"]
        )

        # ralarm could be negative
        values["alarm_relative_number"], values["alarm_relative_unit"] = TimeSpanCtrl.compute_widget_values(
            max((0, values["alarm_relative_time"]))
        )

        values.update(
            {
                "start_year": wstart.year,
                "start_month": wstart.month - 1,
                "start_day": wstart.day,
                "start_hour": wstart.hour,
                "start_minute": wstart.minute,
                "end_year": wend.year,
                "end_month": wend.month - 1,
                "end_day": wend.day,
                "end_hour": wend.hour,
                "end_minute": wend.minute,
                "alarm_year": walarm.year,
                "alarm_month": walarm.month - 1,
                "alarm_day": walarm.day,
                "alarm_hour": walarm.hour,
                "alarm_minute": walarm.minute,
            }
        )

        return values
Example #4
0
    def _compute_values(cls, standard, rule):
        # Remember to support also time zones that differ from UTC by not
        # exact hours (e.g. Australia/Adelaide)
        if not rule:
            now = _datetime.datetime.now()
            nextdate = _datetime.datetime(now.year, now.month, now.day,
                                    now.hour) + _datetime.timedelta(hours=1)
            start = int(_time.mktime(nextdate.timetuple())) - \
                                                UTCOffset.compute2_current()

            values = {
                'start_unix_time': start,
                'end_unix_time': start + 3600,
                'alarm_unix_time': start,
                'end_type': 0,
                'alarm_type': 0,
                'time_standard': standard,
            }
        else:
            values = {
                'start_unix_time': rule[0],
                'end_unix_time': rule[1] if rule[1] else rule[0] + 3600,
                'alarm_unix_time': rule[2] if rule[2] else rule[0],
                'end_type': rule[3][0],
                'alarm_type': rule[3][1],
                'time_standard': standard,
            }

        wstart = _datetime.datetime.utcfromtimestamp(values['start_unix_time'])
        wend = _datetime.datetime.utcfromtimestamp(values['end_unix_time'])
        walarm = _datetime.datetime.utcfromtimestamp(values['alarm_unix_time'])

        values['end_relative_number'], values['end_relative_unit'] = \
                                        TimeSpanCtrl.compute_widget_values(
                                        values['end_unix_time'] -
                                        values['start_unix_time'])

        values['alarm_relative_number'], values['alarm_relative_unit'] = \
                                        TimeSpanCtrl.compute_widget_values(
                                        max((0, values['start_unix_time'] -
                                        values['alarm_unix_time'])))

        values.update({
            'start_year': wstart.year,
            'start_month': wstart.month - 1,
            'start_day': wstart.day,
            'start_hour': wstart.hour,
            'start_minute': wstart.minute,
            'end_year': wend.year,
            'end_month': wend.month - 1,
            'end_day': wend.day,
            'end_hour': wend.hour,
            'end_minute': wend.minute,
            'alarm_year': walarm.year,
            'alarm_month': walarm.month - 1,
            'alarm_day': walarm.day,
            'alarm_hour': walarm.hour,
            'alarm_minute': walarm.minute,
        })

        return values