Skip to content

Instantly share code, notes, and snippets.

@zircote
Created April 15, 2014 18:02
Show Gist options
  • Save zircote/10753537 to your computer and use it in GitHub Desktop.
Save zircote/10753537 to your computer and use it in GitHub Desktop.
class PeriodicInterval(object):
"""
:see: http://en.wikipedia.org/wiki/Iso8601#Durations
"""
def __init__(self, second=None, minute=None, hour=None, day=None, week=None, month=None, year=None):
"""
:param second:
:param minute:
:param hour:
:param day:
:param week:
:param month:
:param year:
:return:
"""
self.second = second
self.minute = minute
self.hour = hour
self.day = day
self.week = week
self.month = month
self.year = year
def __repr__(self):
return unicode(self.__str__())
def __str__(self):
result = "P"
if self.year is not None:
result = "%s%sY" % (result, self.year)
if self.month is not None:
result = "%s%sM" % (result, self.month)
if self.day is not None:
result = "%s%sD" % (result, self.day)
if self.second or self.hour or self.minute is not None:
result = "%sT" % result
if self.hour is not None:
result = "%s%sH" % (result, self.hour)
if self.minute is not None:
result = "%s%sM" % (result, self.minute)
if self.second is not None:
result = "%s%sS" % (result, self.second)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment