Skip to content

Commit b6727d2

Browse files
committed
Add two isoformat() methods. One for Date and one for Interval.
This permits the dicttoxml library to print these data types. The dicttoxml library is optional and can be used by the rest interface to support xml output.
1 parent a58f8c0 commit b6727d2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

roundup/date.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,16 @@ def formal(self, sep='.', sec='%02d'):
615615
return f%(self.year, self.month, self.day, self.hour, self.minute,
616616
self.second)
617617

618+
def isoformat(self):
619+
''' Represent the date/time in isoformat standard
620+
621+
Originally needed for xml output support using
622+
dicttoxml in the rest interface.
623+
'''
624+
f = '%%04d-%%02d-%%02d%s%%02d:%%02d:%s'%("T", "%02.6d")
625+
return f%(self.year, self.month, self.day, self.hour, self.minute,
626+
self.second)
627+
618628
def pretty(self, format='%d %B %Y'):
619629
''' print up the date date using a pretty format...
620630
@@ -1075,6 +1085,15 @@ def serialise(self):
10751085
return '%s%04d%02d%02d%02d%02d%02d'%(sign, self.year, self.month,
10761086
self.day, self.hour, self.minute, self.second)
10771087

1088+
def isoformat(self):
1089+
'''Represent interval as an ISO 8061 duration (absolute value)
1090+
1091+
Originally needed for xml output support using
1092+
dicttoxml in the rest interface.
1093+
'''
1094+
return 'P%04dY%02dM%02dDT%02dH%02dM%02dS'%(self.year, self.month,
1095+
self.day, self.hour, self.minute, self.second)
1096+
10781097
def as_seconds(self):
10791098
'''Calculate the Interval as a number of seconds.
10801099

0 commit comments

Comments
 (0)