[Checkins] SVN: DateTime/trunk/src/DateTime/ further py3k work

Hano Schlichting cvs-admin at zope.org
Sat Feb 23 15:05:49 UTC 2013


Log message for revision 129711:
  further py3k work
  

Changed:
  U   DateTime/trunk/src/DateTime/DateTime.py
  U   DateTime/trunk/src/DateTime/DateTime.txt
  U   DateTime/trunk/src/DateTime/pytz.txt
  U   DateTime/trunk/src/DateTime/tests/test_datetime.py

-=-
Modified: DateTime/trunk/src/DateTime/DateTime.py
===================================================================
--- DateTime/trunk/src/DateTime/DateTime.py	2013-02-23 14:41:20 UTC (rev 129710)
+++ DateTime/trunk/src/DateTime/DateTime.py	2013-02-23 15:05:48 UTC (rev 129711)
@@ -36,8 +36,10 @@
     import copyreg as copy_reg
     basestring = str
     long = int
+    explicit_unicode_type = type(None)
 else:
     import copy_reg
+    explicit_unicode_type = unicode
 
 default_datefmt = None
 
@@ -1242,6 +1244,8 @@
         Revised to give more correct results through comparison of
         long integer microseconds.
         """
+        if t is None:
+            t = 0
         if isinstance(t, float):
             return self._micros > long(t * 1000000)
         try:
@@ -1263,6 +1267,8 @@
         Revised to give more correct results through comparison of
         long integer microseconds.
         """
+        if t is None:
+            t = 0
         if isinstance(t, float):
             return self._micros >= long(t * 1000000)
         try:
@@ -1283,6 +1289,8 @@
         Revised to give more correct results through comparison of
         long integer microseconds.
         """
+        if t is None:
+            t = 0
         if isinstance(t, float):
             return self._micros == long(t * 1000000)
         try:
@@ -1328,6 +1336,8 @@
         Revised to give more correct results through comparison of
         long integer microseconds.
         """
+        if t is None:
+            t = 0
         if isinstance(t, float):
             return self._micros < long(t * 1000000)
         try:
@@ -1348,6 +1358,8 @@
         Revised to give more correct results through comparison of
         long integer microseconds.
         """
+        if t is None:
+            t = 0
         if isinstance(t, float):
             return self._micros <= long(t * 1000000)
         try:
@@ -1537,9 +1549,16 @@
         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,
+        unicode_format = False
+        if isinstance(format, explicit_unicode_type):
+            format = format.encode('utf-8')
+            unicode_format = True
+        ds = datetime(zself._year, zself._month, zself._day, zself._hour,
                zself._minute, int(zself._nearsec),
                microseconds).strftime(format)
+        if unicode_format:
+            return ds.decode('utf-8')
+        return ds
 
     # General formats from previous DateTime
     def Date(self):

Modified: DateTime/trunk/src/DateTime/DateTime.txt
===================================================================
--- DateTime/trunk/src/DateTime/DateTime.txt	2013-02-23 14:41:20 UTC (rev 129710)
+++ DateTime/trunk/src/DateTime/DateTime.txt	2013-02-23 15:05:48 UTC (rev 129711)
@@ -111,13 +111,13 @@
 
     >>> x = DateTime('1997/3/9 1:45pm')
     >>> x.parts() # doctest: +ELLIPSIS
-    (1997, 3, 9, 13, 45, 0.0, ...)
+    (1997, 3, 9, 13, 45, ...)
 
   o Specified time in local machine zone, verbose format:
 
     >>> y = DateTime('Mar 9, 1997 13:45:00')
     >>> y.parts() # doctest: +ELLIPSIS
-    (1997, 3, 9, 13, 45, 0.0, ...)
+    (1997, 3, 9, 13, 45, ...)
     >>> y == x
     True
 
@@ -330,8 +330,8 @@
 * ``parts()`` returns a tuple containing the calendar year, month,
   day, hour, minute second and timezone of the object
 
-    >>> dt.parts()
-    (1997, 3, 9, 13, 45, 0.0, 'US/Eastern')
+    >>> y.parts() # doctest: +ELLIPSIS
+    (1997, 3, 9, 13, 45, ... 'US/Eastern')
 
 * ``timezone()`` returns the timezone in which the object is represented:
 
@@ -432,13 +432,13 @@
 
 * ``second()`` returns the second:
 
-    >>> dt.second()
-    0.0
+    >>> dt.second() == 0
+    True
 
 * ``millis()`` returns the milliseconds since the epoch in GMT.
 
-    >>> dt.millis()
-    857933100000L
+    >>> dt.millis() == 857933100000
+    True
 
 strftime()
 ~~~~~~~~~~
@@ -603,7 +603,7 @@
 DateTimes can be repr()'ed; the result will be a string indicating how
 to make a DateTime object like this:
 
-  >>> `dt`
+  >>> repr(dt)
   "DateTime('1997/03/09 13:45:00 US/Eastern')"
 
 When we convert them into a string, we get a nicer string that could
@@ -743,10 +743,13 @@
 
 Two DateTimes cannot be added:
 
-  >>> dt + dt
-  Traceback (most recent call last):
-  ...
-  DateTimeError: Cannot add two DateTimes
+  >>> from DateTime.interfaces import DateTimeError
+  >>> try:
+  ...     dt + dt
+  ...     print('fail')
+  ... except DateTimeError:
+  ...     print('ok')
+  ok
 
 Either a DateTime or a number may be subtracted from a DateTime,
 however, a DateTime may not be subtracted from a number:
@@ -761,11 +764,9 @@
   TypeError: unsupported operand type(s) for -: 'int' and 'DateTime'
 
 DateTimes can also be converted to integers (number of seconds since
-the epoch), longs (not too long ;)) and floats:
+the epoch) and floats:
 
   >>> int(dt)
   857933100
-  >>> long(dt)
-  857933100L
   >>> float(dt)
   857933100.0

Modified: DateTime/trunk/src/DateTime/pytz.txt
===================================================================
--- DateTime/trunk/src/DateTime/pytz.txt	2013-02-23 14:41:20 UTC (rev 129710)
+++ DateTime/trunk/src/DateTime/pytz.txt	2013-02-23 15:05:48 UTC (rev 129711)
@@ -58,10 +58,13 @@
 
 Of course pytz doesn't know about everything.
 
-    >>> d = DateTime('July 21, 1969 Moon/Eastern')
-    Traceback (most recent call last):
-    ...
-    SyntaxError: July 21, 1969 Moon/Eastern
+    >>> from DateTime.interfaces import SyntaxError
+    >>> try:
+    ...     d = DateTime('July 21, 1969 Moon/Eastern')
+    ...     print('fail')
+    ... except SyntaxError:
+    ...     print('ok')
+    ok
 
 You can still use zone names that DateTime defines that aren't part of
 the pytz database.
@@ -112,7 +115,7 @@
 
     >>> from DateTime.DateTime import _TZINFO
     >>> _TZINFO #doctest: +ELLIPSIS
-    <DateTime.pytz_support.PytzCache instance at ...>
+    <DateTime.pytz_support.PytzCache ...>
 
 The cache maps time zone names to time zone instances.
 

Modified: DateTime/trunk/src/DateTime/tests/test_datetime.py
===================================================================
--- DateTime/trunk/src/DateTime/tests/test_datetime.py	2013-02-23 14:41:20 UTC (rev 129710)
+++ DateTime/trunk/src/DateTime/tests/test_datetime.py	2013-02-23 15:05:48 UTC (rev 129711)
@@ -26,6 +26,7 @@
 
 if sys.version_info > (3, ):
     import pickle
+    unicode = str
 else:
     import cPickle as pickle
 
@@ -238,10 +239,10 @@
 
     def test_pickle_old(self):
         dt = DateTime('2002/5/2 8:00am GMT+0')
-        data = ('(cDateTime.DateTime\nDateTime\nq\x01Noq\x02}q\x03(U\x05_amonq'
-            '\x04U\x03Mayq\x05U\x05_adayq\x06U\x03Thuq\x07U\x05_pmonq\x08h'
-            '\x05U\x05_hourq\tK\x08U\x05_fmonq\nh\x05U\x05_pdayq\x0bU\x04T'
-            'hu.q\x0cU\x05_fdayq\rU\x08Thursdayq\x0eU\x03_pmq\x0fU\x02amq'
+        data = ('(cDateTime.DateTime\nDateTime\nq\x01Noq\x02}q\x03(U\x05'
+            '_amonq\x04U\x03Mayq\x05U\x05_adayq\x06U\x03Thuq\x07U\x05_pmonq'
+            '\x08h\x05U\x05_hourq\tK\x08U\x05_fmonq\nh\x05U\x05_pdayq\x0bU'
+            '\x04Thu.q\x0cU\x05_fdayq\rU\x08Thursdayq\x0eU\x03_pmq\x0fU\x02amq'
             '\x10U\x02_tq\x11GA\xcehy\x00\x00\x00\x00U\x07_minuteq\x12K\x00U'
             '\x07_microsq\x13L1020326400000000L\nU\x02_dq\x14G@\xe2\x12j\xaa'
             '\xaa\xaa\xabU\x07_secondq\x15G\x00\x00\x00\x00\x00\x00\x00\x00U'
@@ -256,9 +257,9 @@
 
     def test_pickle_old_without_micros(self):
         dt = DateTime('2002/5/2 8:00am GMT+0')
-        data = ('(cDateTime.DateTime\nDateTime\nq\x01Noq\x02}q\x03(U\x05_amonq'
-            '\x04U\x03Mayq\x05U\x05_adayq\x06U\x03Thuq\x07U\x05_pmonq\x08h'
-            '\x05U\x05_hourq\tK\x08U\x05_fmonq\nh\x05U\x05_pdayq\x0bU'
+        data = ('(cDateTime.DateTime\nDateTime\nq\x01Noq\x02}q\x03(U\x05'
+            '_amonq\x04U\x03Mayq\x05U\x05_adayq\x06U\x03Thuq\x07U\x05_pmonq'
+            '\x08h\x05U\x05_hourq\tK\x08U\x05_fmonq\nh\x05U\x05_pdayq\x0bU'
             '\x04Thu.q\x0cU\x05_fdayq\rU\x08Thursdayq\x0eU\x03_pmq\x0fU'
             '\x02amq\x10U\x02_tq\x11GA\xcehy\x00\x00\x00\x00U\x07_minuteq'
             '\x12K\x00U\x02_dq\x13G@\xe2\x12j\xaa\xaa\xaa\xabU\x07_secondq'



More information about the checkins mailing list