Home » U++ Library support » U++ Core » DST issue in Time()
DST issue in Time() [message #49666] |
Tue, 27 March 2018 09:08 |
|
koldo
Messages: 3394 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
Please check if we handle Daylight saving time properly in Windows.
I have checked it in C: local NTFS disk from Windows 10 and actual code does not report right hour.
However, from a Linux virtual machine, same code report properly the file time
Actual code for Windows:Time::Time(FileTime filetime) {
SYSTEMTIME tm;
FileTime ft;
FileTimeToLocalFileTime(&filetime, &ft);
FileTimeToSystemTime(&ft, &tm);
*this = Time(tm.wYear, tm.wMonth, tm.wDay, tm.wHour, tm.wMinute, tm.wSecond);
}
Proposed code:Time::Time(FileTime filetime) {
SYSTEMTIME tm, tml;
FileTimeToSystemTime(&filetime, &tm);
SystemTimeToTzSpecificLocalTime(NULL, &tm, &tml);
*this = Time(tml.wYear, tml.wMonth, tml.wDay, tml.wHour, tml.wMinute, tml.wSecond);
}
See this:To account for daylight saving time when converting a file time to a local time, use the following sequence of functions in place of using FileTimeToLocalFileTime:
FileTimeToSystemTime
SystemTimeToTzSpecificLocalTime
Best regards
Iñaki
|
|
|
Re: DST issue in Time() [message #49667 is a reply to message #49666] |
Tue, 27 March 2018 15:49 |
|
mirek
Messages: 14039 Registered: November 2005
|
Ultimate Member |
|
|
koldo wrote on Tue, 27 March 2018 09:08Hello all
Please check if we handle Daylight saving time properly in Windows.
I have checked it in C: local NTFS disk from Windows 10 and actual code does not report right hour.
However, from a Linux virtual machine, same code report properly the file time
Actual code for Windows:Time::Time(FileTime filetime) {
SYSTEMTIME tm;
FileTime ft;
FileTimeToLocalFileTime(&filetime, &ft);
FileTimeToSystemTime(&ft, &tm);
*this = Time(tm.wYear, tm.wMonth, tm.wDay, tm.wHour, tm.wMinute, tm.wSecond);
}
Proposed code:Time::Time(FileTime filetime) {
SYSTEMTIME tm, tml;
FileTimeToSystemTime(&filetime, &tm);
SystemTimeToTzSpecificLocalTime(NULL, &tm, &tml);
*this = Time(tml.wYear, tml.wMonth, tml.wDay, tml.wHour, tml.wMinute, tml.wSecond);
}
See this:To account for daylight saving time when converting a file time to a local time, use the following sequence of functions in place of using FileTimeToLocalFileTime:
FileTimeToSystemTime
SystemTimeToTzSpecificLocalTime
Can you give me some context? E.g. testcase?
So far, I have tried with FileSel and time is reported correctly (for file that I have just saved and I have DST active here).
Mirek
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Sep 20 14:59:08 CEST 2024
Total time taken to generate the page: 0.03054 seconds
|