--- lib/python/DateTime/DateTime.py-orig 2008-07-16 10:42:24.000000000 +0200 +++ lib/python/DateTime/DateTime.py 2008-09-08 16:20:47.000000000 +0200 @@ -124,14 +124,7 @@ localzone = altzone else: localzone = timezone - offset=(-localzone/(60*60.0)) - majorOffset=int(offset) - if majorOffset != 0 : - minorOffset=abs(int((offset % majorOffset) * 60.0)) - else: minorOffset = 0 - m=majorOffset >= 0 and '+' or '' - lz='%s%0.02d%0.02d' % (m, majorOffset, minorOffset) - _localzone = _cache._zmap[('GMT%s' % lz).lower()] + _localzone = _cache._zmap['gmt'+_tzoffset2rfc822zone(-localzone)] except: _localzone = '' return _localzone @@ -279,13 +272,19 @@ """Takes an offset, such as from _tzoffset(), and returns an rfc822 compliant zone specification. Please note that the result of _tzoffset() is the negative of what time.localzone and time.altzone is.""" - return "%+03d%02d" % divmod( (seconds/60), 60) + hoff, moff = divmod(abs(seconds)/60, 60) + if seconds<0: + hoff = -hoff + return "%+03d%02d"%(hoff, moff) def _tzoffset2iso8601zone(seconds): """Takes an offset, such as from _tzoffset(), and returns an ISO 8601 compliant zone specification. Please note that the result of _tzoffset() is the negative of what time.localzone and time.altzone is.""" - return "%+03d:%02d" % divmod( (seconds/60), 60) + hoff, moff = divmod(abs(seconds)/60, 60) + if seconds<0: + hoff = -hoff + return "%+03d:%02d"%(hoff, moff) class DateTime: @@ -1459,32 +1452,32 @@ # General formats from previous DateTime def Date(self): """Return the date string for the object.""" - return "%s/%2.2d/%2.2d" % (self._year, self._month, self._day) + return "%s/%02d/%02d" % (self._year, self._month, self._day) def Time(self): """Return the time string for an object to the nearest second.""" - return '%2.2d:%2.2d:%2.2d' % (self._hour,self._minute,self._nearsec) + return '%02d:%02d:%02d' % (self._hour,self._minute,self._nearsec) def TimeMinutes(self): """Return the time string for an object not showing seconds.""" - return '%2.2d:%2.2d' % (self._hour,self._minute) + return '%02d:%02d' % (self._hour,self._minute) def AMPM(self): """Return the time string for an object to the nearest second.""" - return '%2.2d:%2.2d:%2.2d %s' % ( + return '%02d:%02d:%02d %s' % ( self._pmhour,self._minute,self._nearsec,self._pm) def AMPMMinutes(self): """Return the time string for an object not showing seconds.""" - return '%2.2d:%2.2d %s' % (self._pmhour,self._minute,self._pm) + return '%02d:%02d %s' % (self._pmhour,self._minute,self._pm) def PreciseTime(self): """Return the time string for the object.""" - return '%2.2d:%2.2d:%06.3f' % (self._hour,self._minute,self._second) + return '%02d:%02d:%06.3f' % (self._hour,self._minute,self._second) def PreciseAMPM(self): """Return the time string for the object.""" - return '%2.2d:%2.2d:%06.3f %s' % ( + return '%02d:%02d:%06.3f %s' % ( self._pmhour,self._minute,self._second,self._pm) def yy(self): @@ -1502,7 +1495,7 @@ def rfc822(self): """Return the date in RFC 822 format.""" tzoffset = _tzoffset2rfc822zone(_tzoffset(self._tz, self._t)) - return '%s, %2.2d %s %d %2.2d:%2.2d:%2.2d %s' % ( + return '%s, %02d %s %d %02d:%02d:%02d %s' % ( self._aday,self._day,self._amon,self._year, self._hour,self._minute,self._nearsec,tzoffset) @@ -1511,7 +1504,7 @@ """Return a string representing the object\'s value in the format: March 1, 1997 1:45 pm. """ - return '%s %s, %4.4d %s:%2.2d %s' % ( + return '%s %s, %04d %s:%02d %s' % ( self._fmon,self._day,self._year,self._pmhour, self._minute,self._pm) @@ -1519,7 +1512,7 @@ """Return a string representing the object\'s value in the format: March 1, 1997 1:45 pm US/Eastern. """ - return '%s %s, %4.4d %d:%2.2d %s %s' % ( + return '%s %s, %04d %d:%02d %s %s' % ( self._fmon,self._day,self._year,self._pmhour, self._minute,self._pm,self._tz) @@ -1527,7 +1520,7 @@ """Return a string representing the object\'s value in the format: Mar 1, 1997 1:45 pm. """ - return '%s %s, %4.4d %s:%2.2d %s' % ( + return '%s %s, %04d %s:%02d %s' % ( self._amon,self._day,self._year,self._pmhour, self._minute,self._pm) @@ -1535,7 +1528,7 @@ """Return a string representing the object\'s value in the format: Mar 1, 1997 1:45 pm US/Eastern. """ - return '%s %s, %4.4d %d:%2.2d %s %s' % ( + return '%s %s, %04d %d:%02d %s %s' % ( self._amon,self._day,self._year,self._pmhour, self._minute,self._pm,self._tz) @@ -1543,7 +1536,7 @@ """Return a string representing the object\'s value in the format: Mar. 1, 1997 1:45 pm. """ - return '%s %s, %4.4d %s:%2.2d %s' % ( + return '%s %s, %04d %s:%02d %s' % ( self._pmon,self._day,self._year,self._pmhour, self._minute,self._pm) @@ -1551,7 +1544,7 @@ """Return a string representing the object\'s value in the format: Mar. 1, 1997 1:45 pm US/Eastern. """ - return '%s %s, %4.4d %d:%2.2d %s %s' % ( + return '%s %s, %04d %d:%02d %s %s' % ( self._pmon,self._day,self._year,self._pmhour, self._minute,self._pm,self._tz) @@ -1563,7 +1556,7 @@ Dates are output as: YYYY-MM-DD HH:MM:SS """ - return "%.4d-%.2d-%.2d %.2d:%.2d:%.2d" % ( + return "%04d-%02d-%02d %02d:%02d:%02d" % ( self._year, self._month, self._day, self._hour, self._minute, self._second) @@ -1584,11 +1577,11 @@ to UTC before returning the value and sets the TZD "Z". """ if self.timezoneNaive(): - return "%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d" % ( + return "%04d-%02d-%02dT%02d:%02d:%02d" % ( self._year, self._month, self._day, self._hour, self._minute, self._second) tzoffset = _tzoffset2iso8601zone(_tzoffset(self._tz, self._t)) - return "%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d%s" % ( + return "%04d-%02d-%02dT%02d:%02d:%02d%s" % ( self._year, self._month, self._day, self._hour, self._minute, self._second, tzoffset) @@ -1603,7 +1596,7 @@ The time is in UTC. """ newdate = self.toZone('UTC') - return "%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2dZ" % ( + return "%04d-%02d-%02dT%02d:%02d:%02dZ" % ( newdate._year, newdate._month, newdate._day, newdate._hour, newdate._minute, newdate._second) @@ -1674,16 +1667,16 @@ h,mn,s,t = self._hour,self._minute,self._second,self._tz if h == mn == s == 0: # hh:mm:ss all zero -- suppress the time. - return '%4.4d/%2.2d/%2.2d' % (y, m, d) + return '%04d/%02d/%02d' % (y, m, d) elif s == int(s): # A whole number of seconds -- suppress milliseconds. - return '%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d %s' % ( + return '%04d/%02d/%02d %02d:%02d:%02d %s' % ( y, m, d, h, mn, s, t) else: # s is already rounded to the nearest microsecond, and # it's not a whole number of seconds. Be sure to print # 2 digits before the decimal point. - return '%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%06.6f %s' % ( + return '%04d/%02d/%02d %02d:%02d:%09.6f %s' % ( y, m, d, h, mn, s, t) def __cmp__(self,obj):