def intervalStart(self, when=0):
"""Get the start time of the interval that contains **when**.
:param int when: The time which we're trying to determine the start of
interval that contains it. This should be given in Unix seconds,
for example, taken from :func:`calendar.timegm`.
:rtype: int
:returns: The Unix epoch timestamp for the start time of the interval
that contains **when**.
"""
# Convert `when`s which are floats, i.e. from time.time(), to ints:
when = int(math.ceil(when))
if self.intervalPeriod == 'month':
# For months, we always start at the beginning of the month.
date = fromUnixSeconds(when)
months = (date.year * 12) + (date.month - 1)
months -= (months % self.intervalCount)
month = months % 12 + 1
return toUnixSeconds((months // 12, month, 1, 0, 0, 0))
elif self.intervalPeriod == 'day':
# For days, we start at the beginning of a day.
when -= when % (86400 * self.intervalCount)
return when
elif self.intervalPeriod == 'hour':
# For hours, we start at the beginning of an hour.
when -= when % (3600 * self.intervalCount)
return when
elif self.intervalPeriod == 'minute':
when -= when % (60 * self.intervalCount)
return when
elif self.intervalPeriod == 'second':
when -= when % self.intervalCount
return when
评论列表
文章目录