Author: cito
Date: Sun Aug 14 12:25:24 2011
New Revision: 431
Log:
Support date and time as input types (ticket #40).
Modified:
trunk/module/pgdb.py
Modified: trunk/module/pgdb.py
==============================================================================
--- trunk/module/pgdb.py Sun Jul 17 11:10:42 2011 (r430)
+++ trunk/module/pgdb.py Sun Aug 14 12:25:24 2011 (r431)
@@ -64,12 +64,13 @@
"""
from _pg import *
-import time, sys
+import sys
try:
frozenset
except NameError: # Python < 2.4
from sets import ImmutableSet as frozenset
-from datetime import datetime, timedelta
+from datetime import date, time, datetime, timedelta
+from time import localtime
try: # use Decimal if available
from decimal import Decimal
set_decimal(Decimal)
@@ -215,7 +216,7 @@
def _quote(self, val):
"""Quote value depending on its type."""
- if isinstance(val, datetime):
+ if isinstance(val, (datetime, date, time, timedelta)):
val = str(val)
elif isinstance(val, unicode):
val = val.encode( 'utf8' )
@@ -590,27 +591,27 @@
def Date(year, month, day):
"""Construct an object holding a date value."""
- return datetime(year, month, day)
+ return date(year, month, day)
-def Time(hour, minute, second):
+def Time(hour, minute=0, second=0, microsecond=0):
"""Construct an object holding a time value."""
- return timedelta(hour, minute, second)
+ return time(hour, minute, second, microsecond)
-def Timestamp(year, month, day, hour, minute, second):
+def Timestamp(year, month, day, hour=0, minute=0, second=0, microsecond=0):
"""construct an object holding a time stamp value."""
- return datetime(year, month, day, hour, minute, second)
+ return datetime(year, month, day, hour, minute, second, microsecond)
def DateFromTicks(ticks):
"""Construct an object holding a date value from the given ticks value."""
- return Date(*time.localtime(ticks)[:3])
+ return Date(*localtime(ticks)[:3])
def TimeFromTicks(ticks):
"""construct an object holding a time value from the given ticks value."""
- return Time(*time.localtime(ticks)[3:6])
+ return Time(*localtime(ticks)[3:6])
def TimestampFromTicks(ticks):
"""construct an object holding a time stamp from the given ticks value."""
- return Timestamp(*time.localtime(ticks)[:6])
+ return Timestamp(*localtime(ticks)[:6])
class Binary(str):
"""construct an object capable of holding a binary (long) string value."""
_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql