[Zope-Checkins] CVS: Packages/DateTime - DateTime.py:1.85.12.13
Jens Vagelpohl
jens at dataflake.org
Tue Nov 9 12:50:07 EST 2004
Update of /cvs-repository/Packages/DateTime
In directory cvs.zope.org:/tmp/cvs-serv10859/lib/python/DateTime
Modified Files:
Tag: Zope-2_7-branch
DateTime.py
Log Message:
- Collector #1569/DateTime: Added a new ISO8601-method that will
return correctly formatted ISO 8601-representations to augment
the ISO method which isn't compliant with ISO 8601.
=== Packages/DateTime/DateTime.py 1.85.12.12 => 1.85.12.13 ===
--- Packages/DateTime/DateTime.py:1.85.12.12 Mon Nov 8 13:50:43 2004
+++ Packages/DateTime/DateTime.py Tue Nov 9 12:49:36 2004
@@ -462,6 +462,12 @@
_tzoffset() is the negative of what time.localzone and time.altzone is."""
return "%+03d%02d" % divmod( (seconds/60), 60)
+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)
+
class DateTime:
"""DateTime objects represent instants in time and provide
@@ -1587,13 +1593,33 @@
def ISO(self):
- """Return the object in ISO standard format
+ """Return the object in ISO standard format. Note:
+ this is *not* ISO 8601-format! See the ISO8601 and
+ HTML4 methods below for ISO 8601-compliant output
Dates are output as: YYYY-MM-DD HH:MM:SS
"""
return "%.4d-%.2d-%.2d %.2d:%.2d:%.2d" % (
self._year, self._month, self._day,
self._hour, self._minute, self._second)
+
+ def ISO8601(self):
+ """Return the object in ISO 8601-compatible format containing
+ the date, time with seconds-precision and the time zone
+ identifier - see http://www.w3.org/TR/NOTE-datetime
+
+ Dates are output as: YYYY-MM-DDTHH:MM:SSTZD
+ T is a literal character.
+ TZD is Time Zone Designator, format +HH:MM or -HH:MM
+
+ The HTML4 method below offers the same formatting, but converts
+ to UTC before returning the value and sets the TZD "Z"
+ """
+ tzoffset = _tzoffset2iso8601zone(_tzoffset(self._tz, self._t))
+
+ return "%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d%s" % (
+ self._year, self._month, self._day,
+ self._hour, self._minute, self._second, tzoffset)
def HTML4(self):
"""Return the object in the format used in the HTML4.0 specification,
More information about the Zope-Checkins
mailing list