From 03a0fcdd1f70687e66c83e060ea43481a4593053 Mon Sep 17 00:00:00 2001 From: adustman Date: Thu, 10 Jul 2003 15:58:56 +0000 Subject: [PATCH] Add support for Python 2.3 datetime classes. --- MySQLdb/CHANGELOG | 2 + MySQLdb/MySQLdb/times.py | 87 +++------------------------------------- 2 files changed, 8 insertions(+), 81 deletions(-) diff --git a/MySQLdb/CHANGELOG b/MySQLdb/CHANGELOG index 9f446f1..6491ba6 100644 --- a/MySQLdb/CHANGELOG +++ b/MySQLdb/CHANGELOG @@ -1,5 +1,7 @@ 0.9.3a2 + * Add some support for Python 2.3 datetime classes. + * Removed some casts in _mysql_init() that caused problems with Python 2.3. The type for tp_free was changed from destructor to freefunc. Removing the casts make both 2.2 and 2.3 happy. diff --git a/MySQLdb/MySQLdb/times.py b/MySQLdb/MySQLdb/times.py index 4431b4d..5ffc1d5 100644 --- a/MySQLdb/MySQLdb/times.py +++ b/MySQLdb/MySQLdb/times.py @@ -3,93 +3,18 @@ This module provides some Date and Time classes for dealing with MySQL data. """ -from time import strftime, localtime from _mysql import string_literal try: - try: - # new packaging - from mx.DateTime import Date, Time, Timestamp, ISO, \ - DateTimeType, DateTimeDeltaType - except ImportError: - # old packaging, deprecated - from DateTime import Date, Time, Timestamp, ISO, \ - DateTimeType, DateTimeDeltaType - - def DateFromTicks(ticks): - """Convert UNIX ticks into a mx.DateTime.Date.""" - return apply(Date, localtime(ticks)[:3]) - - def TimeFromTicks(ticks): - """Convert UNIX ticks into a mx.DateTime.Time.""" - return apply(Time, localtime(ticks)[3:6]) - - def TimestampFromTicks(ticks): - """Convert UNIX ticks into a mx.DateTime.Timestamp.""" - return apply(Timestamp, localtime(ticks)[:6]) - - def format_DATE(d): - """Format a DateTime object as an ISO date.""" - return d.strftime("%Y-%m-%d") - - def format_TIME(d): - """Format a DateTime object as a time value.""" - return d.strftime("%H:%M:%S") - - def format_TIMESTAMP(d): - """Format a DateTime object as an ISO timestamp.""" - return d.strftime("%Y-%m-%d %H:%M:%S") - - def DateTime_or_None(s): - try: return ISO.ParseDateTime(s) - except: return None - - def TimeDelta_or_None(s): - try: return ISO.ParseTimeDelta(s) - except: return None - - def Date_or_None(s): - try: return ISO.ParseDate(s) - except: return None - + from pytimes import * except ImportError: - # no DateTime? We'll muddle through somehow. - - DateTimeDeltaType = "DateTimeDeltaType" - DateTimeType = "DateTimeType" - - def Date(year, month, day): - """Construct an ISO date string.""" - return "%04d-%02d-%02d" % (year, month, day) + try: + from mxdatetimes import * - def Time(hour, min, sec): - """Construct a TIME string.""" - return "%02d:%02d:%02d" % (hour, min, sec) - - def Timestamp(year, month, day, hour, min, sec): - """Construct an ISO timestamp.""" - return "%04d-%02d-%02d %02d:%02d:%02d" % \ - (year, month, day, hour, min, sec) - - def DateFromTicks(ticks): - """Convert UNIX ticks to ISO date format.""" - return strftime("%Y-%m-%d", localtime(ticks)) - - def TimeFromTicks(ticks): - """Convert UNIX ticks to time format.""" - return strftime("%H:%M:%S", localtime(ticks)) - - def TimestampFromTicks(ticks): - """Convert UNIX ticks to ISO timestamp format.""" - return strftime("%Y-%m-%d %H:%M:%S", localtime(ticks)) - - def format_DATE(d): - """Format a date as a date (does nothing, you don't have mx.DateTime).""" - return d - - format_TIME = format_TIMESTAMP = format_DATE - TimeDelta_or_None = Date_or_None = DateTime_or_None = format_DATE + except ImportError: + # no DateTime? We'll muddle through somehow. + from stringtimes import * def DateTime2literal(d, c): """Format a DateTime object as an ISO timestamp."""