Re: Support for Python's datetime module?

[email protected] Wed, 28 Sep 2005 13:15:59 -0500
Newsgroups gmane.comp.python.sybase
Message-ID <[email protected]>
    me> It doesn't look like Python's datetime module is supported in 0.37
    me> of the Python Sybase module.

I think the attached patch gets you at least part of the way there.

Skip

_______________________________________________
Python-sybase mailing list
[email protected]
https://www.object-craft.com.au/cgi-bin/mailman/listinfo/python-sybase
Sybase.diff (application/octet-stream, 1.4 KB)
--- Sybase.py.~1~	2005-04-06 17:46:43.000000000 -0500
+++ Sybase.py	2005-09-28 13:12:20.461986000 -0500
@@ -4,15 +4,25 @@
 # LICENCE - see LICENCE file distributed with this software for details.
 #
 try:
-    import DateTime
+    from DateTime import DateTime as DT
     use_datetime = 1
 except ImportError:
     try:
-        import mx.DateTime
-        DateTime = mx.DateTime
+        from mx.DateTime import DateTime as DT
         use_datetime = 1
     except ImportError:
-        use_datetime = 0
+        try:
+            from datetime import datetime as py_datetime
+            use_datetime = 1
+        except ImportError:
+            use_datetime = 0
+        else:
+            def DT(year, month, day, hour, minute, second):
+                usec = int(1000000 * (second - int(second)))
+                second = int(second)
+                return py_datetime(year, month, day,
+                                   hour, minute, second, usec)
+
 import sys
 import time
 import string
@@ -225,9 +235,9 @@
 
 def _column_value(val):
     if use_datetime and type(val) is DateTimeType:
-        return DateTime.DateTime(val.year, val.month + 1, val.day,
-                                 val.hour, val.minute,
-                                 val.second + val.msecond / 1000.0)
+        return DT(val.year, val.month + 1, val.day,
+                  val.hour, val.minute,
+                  val.second + val.msecond / 1000.0)
     else:
         return val