@@ -177,6 +177,12 @@ def __add_fsp_to_time(self, time, column):
177
177
For more details about new date format:
178
178
http://dev.mysql.com/doc/internals/en/date-and-time-data-type-representation.html
179
179
"""
180
+ microsecond = self .__read_fsp (column )
181
+ if microsecond > 0 :
182
+ time = time .replace (microsecond = microsecond )
183
+ return time
184
+
185
+ def __read_fsp (self , column ):
180
186
read = 0
181
187
if column .fsp == 1 or column .fsp == 2 :
182
188
read = 1
@@ -187,10 +193,11 @@ def __add_fsp_to_time(self, time, column):
187
193
if read > 0 :
188
194
microsecond = self .packet .read_int_be_by_size (read )
189
195
if column .fsp % 2 :
190
- time = time . replace ( microsecond = int (microsecond / 10 ) )
196
+ return int (microsecond / 10 )
191
197
else :
192
- time = time .replace (microsecond = microsecond )
193
- return time
198
+ return microsecond
199
+
200
+ return 0
194
201
195
202
def __read_string (self , size , column ):
196
203
string = self .packet .read_length_coded_pascal_string (size )
@@ -223,10 +230,10 @@ def __read_bit(self, column):
223
230
224
231
def __read_time (self ):
225
232
time = self .packet .read_uint24 ()
226
- date = datetime .time (
227
- hour = int (time / 10000 ),
228
- minute = int ((time % 10000 ) / 100 ),
229
- second = int (time % 100 ))
233
+ date = datetime .timedelta (
234
+ hours = int (time / 10000 ),
235
+ minutes = int ((time % 10000 ) / 100 ),
236
+ seconds = int (time % 100 ))
230
237
return date
231
238
232
239
def __read_time2 (self , column ):
@@ -241,11 +248,20 @@ def __read_time2(self, column):
241
248
24 bits = 3 bytes
242
249
"""
243
250
data = self .packet .read_int_be_by_size (3 )
244
- t = datetime .time (
245
- hour = self .__read_binary_slice (data , 2 , 10 , 24 ),
246
- minute = self .__read_binary_slice (data , 12 , 6 , 24 ),
247
- second = self .__read_binary_slice (data , 18 , 6 , 24 ))
248
- return self .__add_fsp_to_time (t , column )
251
+
252
+ sign = 1 if self .__read_binary_slice (data , 0 , 1 , 24 ) else - 1
253
+ if sign == - 1 :
254
+ # negative integers are stored as 2's compliment
255
+ # hence take 2's compliment again to get the right value.
256
+ data = ~ data + 1
257
+
258
+ t = datetime .timedelta (
259
+ hours = sign * self .__read_binary_slice (data , 2 , 10 , 24 ),
260
+ minutes = self .__read_binary_slice (data , 12 , 6 , 24 ),
261
+ seconds = self .__read_binary_slice (data , 18 , 6 , 24 ),
262
+ microseconds = self .__read_fsp (column )
263
+ )
264
+ return t
249
265
250
266
def __read_date (self ):
251
267
time = self .packet .read_uint24 ()
0 commit comments