[pywin32-bugs] [ pywin32-Bugs-2209864 ] PyTime's .msec method always returns 0
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2008-10-30 15:06:04
|
Bugs item #2209864, was opened at 2008-10-30 16:36 Message generated for change (Comment added) made by davidfraser You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2209864&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: win32 Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: David Fraser (davidfraser) Assigned to: Nobody/Anonymous (nobody) Summary: PyTime's .msec method always returns 0 Initial Comment: PyTime stores times internally as DATE objects, which support fractional second resolution (since they are just a double number of days). However the method to retrieve attributes including msec uses the Win32 VariantTimeToSystemTime function to convert the m_time to a SYSTEMTIME. This function is known not to convert the fractional part of seconds (see http://support.microsoft.com/kb/297463, and http://www.codeproject.com/KB/datetime/SysTimeToVarTimeWMillisec.aspx for some example workaround code). So although the fractional part is actually stored in the PyTime object, it cannot be retrieved. ---------------------------------------------------------------------- >Comment By: David Fraser (davidfraser) Date: 2008-10-30 17:06 Message: I've attached a very simple patch that calculates the .msec value on request. Note that since .msec has never returned anything but 0, and the builtin datetime object has a microsecond attribute, it may be worthwhile to repurpose this .msec attribute to mean "microseconds" rather than "seconds" It would also be worthwhile to patch the various Time constructors to ensure that they preserve sub-second resolution if given (e.g. pywintypes.Time(time.time()) currently discards it) File Added: pywin32-pytime-calc-msec.patch ---------------------------------------------------------------------- Comment By: David Fraser (davidfraser) Date: 2008-10-30 16:47 Message: A fairly simple workaround is to convert the PyTime directly to a float. For example, the following code converts to datetime: def WinPyTimeToDate(pytime): """Converts a pywintypes.PyTime object into a date object""" microseconds = int(((float(pytime)*24*60*60) % 1)*1000000) return date(pytime.year, pytime.month, pytime.day, pytime.hour, pytime.minute, pytime.second, microseconds) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2209864&group_id=78018 |