Opened 18 years ago
Closed 18 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)
follow-up: 2 comment:1 by , 18 years ago
| Resolution: | → Rejected |
|---|---|
| Status: | new → closed |
comment:2 by , 18 years ago
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
follow-up: 4 comment:3 by , 18 years ago
| Resolution: | Rejected |
|---|---|
| Status: | closed → reopened |
comment:4 by , 18 years ago
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 by , 18 years ago
| Milestone: | → 3.2.13.8 |
|---|---|
| Owner: | set to |
| Resolution: | → Fixed |
| Status: | reopened → closed |
Fixed in version: 3.2.13.8

They both return the same if you run both the old example and add your code in.