changeset 2702:eb4e7b8d52a2

handle Py2.3+ datetime objects as Date specs [SF#971300]
author Richard Jones <richard@users.sourceforge.net>
date Wed, 29 Sep 2004 07:27:09 +0000
parents 460c07a2dff1
children d760b549bdf0
files CHANGES.txt doc/index.txt roundup/date.py test/test_dates.py
diffstat 4 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Wed Sep 29 07:26:17 2004 +0000
+++ b/CHANGES.txt	Wed Sep 29 07:27:09 2004 +0000
@@ -38,6 +38,7 @@
 - less specific messages for login failures (thanks Chris Withers)
 - Reject raised against email messages should result in email rejection, not
   discarding of the message
+- handle Py2.3+ datetime objects as Date specs (sf bug 971300)
 
 
 2004-07-21 0.7.6
--- a/doc/index.txt	Wed Sep 29 07:26:17 2004 +0000
+++ b/doc/index.txt	Wed Sep 29 07:27:09 2004 +0000
@@ -119,6 +119,7 @@
 John P. Rouillard,
 Ollie Rutherfurd,
 Toby Sargeant,
+Gregor Schmid,
 Florian Schulze,
 Klamer Schutte,
 Dougal Scott,
--- a/roundup/date.py	Wed Sep 29 07:26:17 2004 +0000
+++ b/roundup/date.py	Wed Sep 29 07:27:09 2004 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 #
-# $Id: date.py,v 1.74 2004-07-04 05:07:19 richard Exp $
+# $Id: date.py,v 1.75 2004-09-29 07:27:08 richard Exp $
 
 """Date, time and time interval handling.
 """
@@ -25,6 +25,12 @@
 from types import *
 import i18n
 
+try:
+    import datetime
+    have_datetime = 1
+except:
+    have_datetime = 0
+
 def _add_granularity(src, order, value = 1):
     '''Increment first non-None value in src dictionary ordered by 'order'
     parameter
@@ -126,6 +132,11 @@
         if type(spec) == type(''):
             self.set(spec, offset=offset, add_granularity=add_granularity)
             return
+        elif have_datetime and isinstance(spec, datetime.datetime):
+            # Python 2.3+ datetime object
+            y,m,d,H,M,S,x,x,x = spec.timetuple()
+            S += spec.microsecond/1000000.
+            spec = (y,m,d,H,M,S,x,x,x)
         elif hasattr(spec, 'tuple'):
             spec = spec.tuple()
         elif isinstance(spec, Date):
--- a/test/test_dates.py	Wed Sep 29 07:26:17 2004 +0000
+++ b/test/test_dates.py	Wed Sep 29 07:27:09 2004 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: test_dates.py,v 1.32 2004-04-18 05:31:03 richard Exp $
+# $Id: test_dates.py,v 1.33 2004-09-29 07:27:09 richard Exp $
 from __future__ import nested_scopes
 
 import unittest, time
@@ -372,6 +372,14 @@
         ae('-1y', '1 year ago')
         ae('-2y', '2 years ago')
 
+    def testPyDatetime(self):
+        try:
+            import datetime
+        except:
+            return
+        d = datetime.datetime.now()
+        Date(d)
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(DateTestCase))

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