thirdparty/google_appengine/google/appengine/cron/groctimespecification.py
changeset 2172 ac7bd3b467ff
parent 1278 a7766286a7be
child 2864 2e0b0af889be
equal deleted inserted replaced
2171:83d96aadd228 2172:ac7bd3b467ff
    65   """
    65   """
    66   parser = groc.CreateParser(schedule)
    66   parser = groc.CreateParser(schedule)
    67   parser.timespec()
    67   parser.timespec()
    68 
    68 
    69   if parser.interval_mins:
    69   if parser.interval_mins:
    70     return IntervalTimeSpecification(parser.interval_mins, parser.period_string)
    70     return IntervalTimeSpecification(parser.interval_mins,
       
    71                                      parser.period_string)
    71   else:
    72   else:
    72     return SpecificTimeSpecification(parser.ordinal_set, parser.weekday_set,
    73     return SpecificTimeSpecification(parser.ordinal_set, parser.weekday_set,
    73                                      parser.month_set, None, parser.time_string)
    74                                      parser.month_set,
       
    75                                      None,
       
    76                                      parser.time_string)
    74 
    77 
    75 
    78 
    76 class TimeSpecification(object):
    79 class TimeSpecification(object):
    77   """Base class for time specifications."""
    80   """Base class for time specifications."""
    78 
    81 
   109 class IntervalTimeSpecification(TimeSpecification):
   112 class IntervalTimeSpecification(TimeSpecification):
   110   """A time specification for a given interval.
   113   """A time specification for a given interval.
   111 
   114 
   112   An Interval type spec runs at the given fixed interval. It has two
   115   An Interval type spec runs at the given fixed interval. It has two
   113   attributes:
   116   attributes:
   114   period   - the type of interval, either "hours" or "minutes"
   117   period - the type of interval, either "hours" or "minutes"
   115   interval - the number of units of type period.
   118   interval - the number of units of type period.
   116   timezone - the timezone for this specification. Not used in this class.
       
   117   """
   119   """
   118 
   120 
   119   def __init__(self, interval, period, timezone=None):
   121   def __init__(self, interval, period):
   120     super(IntervalTimeSpecification, self).__init__(self)
   122     super(IntervalTimeSpecification, self).__init__(self)
   121     self.interval = interval
   123     self.interval = interval
   122     self.period = period
   124     self.period = period
   123 
   125 
   124   def GetMatch(self, t):
   126   def GetMatch(self, t):
   184       self.monthdays = set()
   186       self.monthdays = set()
   185     else:
   187     else:
   186       self.monthdays = set(monthdays)
   188       self.monthdays = set(monthdays)
   187     hourstr, minutestr = timestr.split(':')
   189     hourstr, minutestr = timestr.split(':')
   188     self.time = datetime.time(int(hourstr), int(minutestr))
   190     self.time = datetime.time(int(hourstr), int(minutestr))
   189     if timezone and pytz is not None:
   191     if timezone:
       
   192       if pytz is None:
       
   193         raise ValueError("need pytz in order to specify a timezone")
   190       self.timezone = pytz.timezone(timezone)
   194       self.timezone = pytz.timezone(timezone)
   191 
   195 
   192   def _MatchingDays(self, year, month):
   196   def _MatchingDays(self, year, month):
   193     """Returns matching days for the given year and month.
   197     """Returns matching days for the given year and month.
   194 
   198