Commit 9c397df3 authored by Andreas Jung's avatar Andreas Jung

      - Collector #1780: DateTime.strftime() now handles dates <= 1900 or
        >= 2038
parent 52e2f970
......@@ -31,6 +31,11 @@ Zope Changes
Bugs fixed
- Collector #1780: DateTime.strftime() now handles dates <= 1900 or
>= 2038
- Collector #1775: turning off debug mode by default
- Collector #1784: fixed handling of multiple attributes in ZCTextIndex
- Don't copy '.svn' directories from skeleton into an instance
......
......@@ -18,6 +18,7 @@ __version__='$Revision: 1.99 $'[11:-2]
import re, math, DateTimeZone
from time import time, gmtime, localtime
from time import daylight, timezone, altzone, strftime
from datetime import datetime
default_datefmt = None
......@@ -1481,7 +1482,15 @@ class DateTime:
def strftime(self, format):
# Format the date/time using the *current timezone representation*.
return strftime(format, safelocaltime(self.timeTime()))
x = _calcDependentSecond2(self._year, self._month, self._day,
self._hour, self._minute, self._second)
ltz = self._calcTimezoneName(x, 0)
tzdiff = _tzoffset(ltz, self._t) - _tzoffset(self._tz, self._t)
zself = self + tzdiff/86400.0
microseconds = int((zself._second - zself._nearsec) * 1000000)
return datetime(zself._year, zself._month, zself._day, zself._hour,
zself._minute, int(zself._nearsec),
microseconds).strftime(format)
# General formats from previous DateTime
def Date(self):
......
......@@ -360,6 +360,20 @@ class DateTimeTests(unittest.TestCase):
dt_localstring = dt_local.strftime(format)
self.assertEqual(dt_string, dt_localstring)
def testStrftimeFarDates(self):
'''Checks strftime in dates <= 1900 or >= 2038'''
dt = DateTime('1900/01/30')
self.assertEqual(dt.strftime('%d/%m/%Y'), '30/01/1900')
dt = DateTime('2040/01/30')
self.assertEqual(dt.strftime('%d/%m/%Y'), '30/01/2040')
def testZoneInFarDates(self):
'''Checks time zone in dates <= 1900 or >= 2038'''
dt1 = DateTime('2040/01/30 14:33 GMT+1')
dt2 = DateTime('2040/01/30 11:33 GMT-2')
self.assertEqual(dt1.strftime('%d/%m/%Y %H:%M'), dt2.strftime('%d/%m/%Y %H:%M'))
def test_suite():
return unittest.makeSuite(DateTimeTests)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment