@@ -177,6 +177,12 @@ def __add_fsp_to_time(self, time, column):
177177 For more details about new date format:
178178 http://dev.mysql.com/doc/internals/en/date-and-time-data-type-representation.html
179179 """
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 ):
180186 read = 0
181187 if column .fsp == 1 or column .fsp == 2 :
182188 read = 1
@@ -187,10 +193,11 @@ def __add_fsp_to_time(self, time, column):
187193 if read > 0 :
188194 microsecond = self .packet .read_int_be_by_size (read )
189195 if column .fsp % 2 :
190- time = time . replace ( microsecond = int (microsecond / 10 ) )
196+ return int (microsecond / 10 )
191197 else :
192- time = time .replace (microsecond = microsecond )
193- return time
198+ return microsecond
199+
200+ return 0
194201
195202 def __read_string (self , size , column ):
196203 string = self .packet .read_length_coded_pascal_string (size )
@@ -223,10 +230,10 @@ def __read_bit(self, column):
223230
224231 def __read_time (self ):
225232 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 ))
230237 return date
231238
232239 def __read_time2 (self , column ):
@@ -241,11 +248,20 @@ def __read_time2(self, column):
241248 24 bits = 3 bytes
242249 """
243250 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
249265
250266 def __read_date (self ):
251267 time = self .packet .read_uint24 ()
0 commit comments