Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » DST issue in Time()
DST issue in Time() [message #49666] Tue, 27 March 2018 09:08 Go to next message
koldo is currently offline  koldo
Messages: 3355
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 Smile

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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Tue, 27 March 2018 09:08
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 Smile

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
Re: DST issue in Time() [message #49669 is a reply to message #49667] Tue, 27 March 2018 23:23 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Mirek

It has happened in my own C: disk. It is not possible to give you a test case because it is as simple as doing a FileGetTime(fileName), but used for files in my Windows 10 NTFS system.


Best regards
Iñaki
Re: DST issue in Time() [message #49673 is a reply to message #49669] Thu, 29 March 2018 12:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I can see it now, sorry. Applied.

(The problem was that I was testing with current "summer" file, while the problem appears to manifest with "winter" files).

What about

FileTime Time::AsFileTime() const

? Needs fixing too?

(Do not have time right now to check).
Re: DST issue in Time() [message #49675 is a reply to message #49673] Fri, 30 March 2018 23:03 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Thank you Mirek

It seems it is not necessary to change AsFileTime().
It uses LocalFileTimeToFileTime, that is explained here and it says "LocalFileTimeToFileTime uses the current settings for the time zone and daylight saving time. Therefore, if it is daylight saving time, this function will take daylight saving time into account, even if the time you are converting is in standard time"


Best regards
Iñaki
Re: DST issue in Time() [message #49676 is a reply to message #49675] Sat, 31 March 2018 07:36 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thanks!
Previous Topic: Curious problem wth Vector
Next Topic: [BUG #1854] SegFault when calling CParser::NoSkipComments() before term initialisation
Goto Forum:
  


Current Time: Fri Mar 29 13:06:24 CET 2024

Total time taken to generate the page: 0.01712 seconds