Example #1
0
    def __init__(self, year=None, month=None, day=None, week=None, day_of_week=None, hour=None, minute=None,
                 second=None, start_date=None, end_date=None, timezone=None):
        if timezone:
            timezone = astimezone(timezone)
        elif start_date and start_date.tzinfo:
            timezone = start_date.tzinfo
        elif end_date and end_date.tzinfo:
            timezone = end_date.tzinfo
        else:
            timezone = get_localzone()
        BaseTrigger.__init__(self, timezone)
        self.start_date = convert_to_datetime(start_date, self.timezone, 'start_date')
        self.end_date = convert_to_datetime(end_date, self.timezone, 'end_date')

        values = dict((key, value) for (key, value) in six.iteritems(locals())
                      if key in self.FIELD_NAMES and value is not None)
        self.fields = []
        assign_defaults = False
        for field_name in self.FIELD_NAMES:
            if field_name in values:
                exprs = values.pop(field_name)
                is_default = False
                assign_defaults = not values
            elif assign_defaults:
                exprs = DEFAULT_VALUES[field_name]
                is_default = True
            else:
                exprs = '*'
                is_default = True

            field_class = self.FIELDS_MAP[field_name]
            field = field_class(field_name, exprs, is_default)
            self.fields.append(field)
Example #2
0
 def __init__(self, weeks=0, days=0, hours=0, minutes=0, seconds=0, start_date=None, end_date=None, timezone=None):
     if timezone:
         timezone = astimezone(timezone)
     elif start_date and start_date.tzinfo:
         timezone = start_date.tzinfo
     elif end_date and end_date.tzinfo:
         timezone = end_date.tzinfo
     else:
         timezone = get_localzone()
     BaseTrigger.__init__(self, timezone)
     self.interval = timedelta(weeks=weeks, days=days, hours=hours, minutes=minutes, seconds=seconds)
     self.interval_length = timedelta_seconds(self.interval)
     if self.interval_length == 0:
         self.interval = timedelta(seconds=1)
         self.interval_length = 1
     start_date = start_date or (datetime.now(self.timezone) + self.interval)
     self.start_date = convert_to_datetime(start_date, self.timezone, 'start_date')
     self.end_date = convert_to_datetime(end_date, self.timezone, 'end_date')