def retrieve_vfp_datetime(bytes, fielddef, *ignore):
"""
returns the date/time stored in bytes; dates <= 01/01/1981 00:00:00
may not be accurate; BC dates are nulled.
"""
# two four-byte integers store the date and time.
# millesecords are discarded from time
if bytes == array('B', [0] * 8):
cls = fielddef[EMPTY]
if cls is NoneType:
return None
return cls()
cls = fielddef[CLASS]
time = unpack_long_int(bytes[4:])
microseconds = (time % 1000) * 1000
time = time // 1000 # int(round(time, -3)) // 1000 discard milliseconds
hours = time // 3600
mins = time % 3600 // 60
secs = time % 3600 % 60
time = datetime.time(hours, mins, secs, microseconds)
possible = unpack_long_int(bytes[:4])
possible -= VFPTIME
possible = max(0, possible)
date = datetime.date.fromordinal(possible)
return cls(date.year, date.month, date.day, time.hour, time.minute, time.second, time.microsecond)
评论列表
文章目录