Opened 16 years ago
Closed 16 years ago
#503 closed Bug (Fixed)
_Date_Time_FileTimeToLocalFileTime() - Helpfile example is incorrect
Reported by: | cbruce | Owned by: | Gary |
---|---|---|---|
Milestone: | 3.2.13.8 | Component: | Documentation |
Version: | 3.2.12.1 | Severity: | None |
Keywords: | Date Time FileTime example | Cc: |
Description
The helpfile example uses _Date_Time_EncodeFileTime() to create an initial value to work with. The problem is that this creates a LOCAL time value and not a UTC time value.
Since FileTimes are stored as UTC time, when _Date_Time_FileTimeToLocalFileTime() is passed a LOCAL time value, it applies the UTC to LOCAL conversion and the returned value is not what was intended.
Here's the example with corrections:
*
#include <GuiConstantsEx.au3> #include <Date.au3> #include <WindowsConstants.au3> Global $iMemo _Main() Func _Main() ; --------------- FROM --------------- ;Local $hGUI, $tFile, $tLocal ; --------------- TO --------------- Local $hGUI, $tSystem, $tFile, $tLocal ; -------------------------------------- ; Create GUI $hGUI = GUICreate("Time", 400, 300) $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; --------------- FROM --------------- ;; Encode a file time ;$tFile = _Date_Time_EncodeFileTime(@MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC) ; --------------- TO --------------- ; Get system time $tSystem = _Date_Time_GetSystemTime() $tFile = _Date_Time_SystemTimeToFileTime(DllStructGetPtr($tSystem)) ; -------------------------------------- $tLocal = _Date_Time_FileTimeToLocalFileTime(DllStructGetPtr($tFile)) MemoWrite("Local file time .: " & _Date_Time_FileTimeToStr($tLocal)) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>_Main ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite
*
Thank you all for your time and effort.
Respectfully,
Bruce Huber
Attachments (0)
Change History (5)
comment:1 follow-up: ↓ 2 Changed 16 years ago by Gary
- Resolution set to Rejected
- Status changed from new to closed
comment:2 in reply to: ↑ 1 Changed 16 years ago by anonymous
Replying to Gary:
They both return the same if you run both the old example and add your code in.
Hello Gary - You don't happen to live in Greenwich do you? (Since local and UTC would be the same there, you wouldn't see a difference.)
Here's my run of the original example:
; with _Date_Time_EncodeFileTime()
; Local file time .: 08/08/2008 07:53:11
Followed by my run of my submitted example:
; with _Date_Time_GetSystemTime() and _Date_Time_SystemTimeToFileTime()
; Local file time .: 08/08/2008 12:54:03
And the second one was the correct local time.
Thank you,
Bruce
comment:3 follow-up: ↓ 4 Changed 16 years ago by Gary
- Resolution Rejected deleted
- Status changed from closed to reopened
comment:4 in reply to: ↑ 3 Changed 16 years ago by cbruce
Replying to Gary:
I apologize for my original sloppiness - here is a more accurate description:
I am on Central Daylight Time (CDT) and here's my run of the original example:
; with _Date_Time_EncodeFileTime()
; Local file time .: 08/08/2008 07:53:11
Followed by my run of my submitted example:
; with _Date_Time_GetSystemTime() and _Date_Time_SystemTimeToFileTime()
; Local file time .: 08/08/2008 12:54:03
My example gave the correct local time, and the original example was 5 hours behind.
This is to be expected, since the original example is providing _Date_Time_EncodeFileTime() with the current LOCAL time and my example is using _Date_Time_GetSystemTime(), which is providing _Date_Time_FileTimeToLocalFileTime() with UTC time.
Original example from help file:
#include <GuiConstantsEx.au3> #include <Date.au3> #include <WindowsConstants.au3> Global $iMemo _Main() Func _Main() Local $hGUI, $tFile, $tLocal ; Create GUI $hGUI = GUICreate("Time", 400, 300) $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; Encode a file time $tFile = _Date_Time_EncodeFileTime(@MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC) $tLocal = _Date_Time_FileTimeToLocalFileTime(DllStructGetPtr($tFile)) MemoWrite("Local file time .: " & _Date_Time_FileTimeToStr($tLocal)) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>_Main ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite
My corrected version of the example:
#include <GuiConstantsEx.au3> #include <Date.au3> #include <WindowsConstants.au3> Global $iMemo _Main() Func _Main() Local $hGUI, $tSystem, $tFile, $tLocal ; Create GUI $hGUI = GUICreate("Time", 400, 300) $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; Get system time $tSystem = _Date_Time_GetSystemTime() $tFile = _Date_Time_SystemTimeToFileTime(DllStructGetPtr($tSystem)) $tLocal = _Date_Time_FileTimeToLocalFileTime(DllStructGetPtr($tFile)) MemoWrite("Local file time .: " & _Date_Time_FileTimeToStr($tLocal)) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>_Main ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite
Again, thank you for your effort,
Bruce
comment:5 Changed 16 years ago by Gary
- Milestone set to 3.2.13.8
- Owner set to Gary
- Resolution set to Fixed
- Status changed from reopened to closed
Fixed in version: 3.2.13.8
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
They both return the same if you run both the old example and add your code in.