13.11.04 22:35:03, Martin Stjernholm wrote:
buf->st_mtime = (time_t)((((INT64)findbuf.ftLastWriteTime.dwHighDateTime << 32)
- findbuf.ftLastWriteTime.dwLowDateTime - 116444736000000000) / 10000000);
Does that work in the transition between DST and non-DST time?
Yes.
FILETIME holds the number of 100-nanosecond intervals since January 1, 1601 00:00 UTC.
time_t holds the number of seconds since January 1, 1970 00:00 UTC.
The reference points are absolute points in time - the notion of days and time-of-day doesn't come into it at all; thus timezones, DST and all that becomes irrelevant. You simply have to compensate the different reference points in time (the subtraction) and go from 100-nanoseconds to seconds (the division).
With this in mind I doubt that SystemTimeToTzSpecificLocalTime only does that simple calculation, at least on post-W9x system.
The calculation it does is actually even simpler. That function works on SYSTEMTIME structures, which hold a date and time split into year, month, day, hour and so on. This representation is dependent on the timezone and DST, in contrast to FILETIME or time_t.
If you use FileTimeToSystemTime to convert a FILETIME into the SYSTEMTIME representation, you get GMT time. Now if you want to know what time that was in *your* timezone, say GMT+02:00, you feed that SYSTEMTIME to SystemTimeToTzSpecificLocalTime. That function will now simply add 2 to the "hour" member of SYSTEMTIME and cope with overflows into the day, month and year members. Nothing more.
Now __loctotime_t does exactly the opposite - take a SYSTEMTIME specifying the date and time in the local timezone, adjust the time and maybe date to get GMT time, and then convert that into the time_t representation.
So SystemTimeToTzSpecificLocalTime and the first part of __loctotime_t exactly cancel each other out! I'd be quite surprised if that was indeed part of a KB article or coding sample, especially considering that http://msdn.microsoft.com/library/en-us/sysinfo/base/converting_a_time_t_val... describes the right way to do it.
Axel