comparison roundup/date.py @ 5637:43970d92323e

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.
author John Rouillard <rouilj@ieee.org>
date Fri, 08 Mar 2019 21:32:57 -0500
parents e2382945d302
children 936275dfe1fa
comparison
equal deleted inserted replaced
5636:528b902f98fc 5637:43970d92323e
610 """Return this date as a string in the yyyy-mm-dd.hh:mm:ss format.""" 610 """Return this date as a string in the yyyy-mm-dd.hh:mm:ss format."""
611 return self.formal() 611 return self.formal()
612 612
613 def formal(self, sep='.', sec='%02d'): 613 def formal(self, sep='.', sec='%02d'):
614 f = '%%04d-%%02d-%%02d%s%%02d:%%02d:%s'%(sep, sec) 614 f = '%%04d-%%02d-%%02d%s%%02d:%%02d:%s'%(sep, sec)
615 return f%(self.year, self.month, self.day, self.hour, self.minute,
616 self.second)
617
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")
615 return f%(self.year, self.month, self.day, self.hour, self.minute, 625 return f%(self.year, self.month, self.day, self.hour, self.minute,
616 self.second) 626 self.second)
617 627
618 def pretty(self, format='%d %B %Y'): 628 def pretty(self, format='%d %B %Y'):
619 ''' print up the date date using a pretty format... 629 ''' print up the date date using a pretty format...
1073 def serialise(self): 1083 def serialise(self):
1074 sign = self.sign > 0 and '+' or '-' 1084 sign = self.sign > 0 and '+' or '-'
1075 return '%s%04d%02d%02d%02d%02d%02d'%(sign, self.year, self.month, 1085 return '%s%04d%02d%02d%02d%02d%02d'%(sign, self.year, self.month,
1076 self.day, self.hour, self.minute, self.second) 1086 self.day, self.hour, self.minute, self.second)
1077 1087
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
1078 def as_seconds(self): 1097 def as_seconds(self):
1079 '''Calculate the Interval as a number of seconds. 1098 '''Calculate the Interval as a number of seconds.
1080 1099
1081 Months are counted as 30 days, years as 365 days. Returns a Long 1100 Months are counted as 30 days, years as 365 days. Returns a Long
1082 int. 1101 int.

Roundup Issue Tracker: http://roundup-tracker.org/