2
2
3
3
This module provides some Date and Time classes for dealing with MySQL data.
4
4
5
- Use Python datetime module to handle date and time columns."""
6
-
7
- import math
5
+ Use Python datetime module to handle date and time columns.
6
+ """
8
7
from time import localtime
9
8
from datetime import date , datetime , time , timedelta
10
9
from _mysql import string_literal
@@ -33,12 +32,19 @@ def TimestampFromTicks(ticks):
33
32
34
33
def format_TIMEDELTA (v ):
35
34
seconds = int (v .seconds ) % 60
36
- minutes = int (v .seconds / 60 ) % 60
37
- hours = int (v .seconds / 3600 ) % 24
35
+ minutes = int (v .seconds // 60 ) % 60
36
+ hours = int (v .seconds // 3600 ) % 24
38
37
return '%d %d:%d:%d' % (v .days , hours , minutes , seconds )
39
38
40
39
def format_TIMESTAMP (d ):
41
- return d .isoformat (" " )
40
+ """
41
+ :type d: datetime.datetime
42
+ """
43
+ if d .microsecond :
44
+ fmt = "{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}.{0.microsecond:06}"
45
+ else :
46
+ fmt = "{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}"
47
+ return fmt .format (d )
42
48
43
49
44
50
def DateTime_or_None (s ):
@@ -102,14 +108,12 @@ def Time_or_None(s):
102
108
def Date_or_None (s ):
103
109
try :
104
110
return date (* [ int (x ) for x in s .split ('-' ,2 )])
105
- except (SystemExit , KeyboardInterrupt ):
106
- raise
107
- except :
111
+ except (TypeError , ValueError ):
108
112
return None
109
113
110
114
def DateTime2literal (d , c ):
111
115
"""Format a DateTime object as an ISO timestamp."""
112
- return string_literal (format_TIMESTAMP (d ),c )
116
+ return string_literal (format_TIMESTAMP (d ), c )
113
117
114
118
def DateTimeDelta2literal (d , c ):
115
119
"""Format a DateTimeDelta object as a time."""
0 commit comments