def getInterval(self, when=0):
"""Get the interval that contains the time **when**.
>>> import calendar
>>> from farfetchd.schedule import ScheduledInterval
>>> sched = ScheduledInterval(1, 'month')
>>> when = calendar.timegm((2007, 12, 12, 0, 0, 0))
>>> sched.getInterval(when)
'2007-12'
>>> then = calendar.timegm((2014, 05, 13, 20, 25, 13))
>>> sched.getInterval(then)
'2014-05'
:param int when: The time which we're trying to find the corresponding
interval for. Given in Unix seconds, for example, taken from
:func:`calendar.timegm`.
:rtype: str
:returns: A timestamp in the form ``YEAR-MONTH[-DAY[-HOUR]]``. It's
specificity depends on what type of interval we're using. For
example, if using ``"month"``, the return value would be something
like ``"2013-12"``.
"""
date = fromUnixSeconds(self.intervalStart(when))
fstr = "%04Y-%02m"
if self.intervalPeriod != 'month':
fstr += "-%02d"
if self.intervalPeriod != 'day':
fstr += " %02H"
if self.intervalPeriod != 'hour':
fstr += ":%02M"
if self.intervalPeriod == 'minute':
fstr += ":%02S"
return date.strftime(fstr)
评论列表
文章目录