Correct way to handle file times

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Correct way to handle file times

Post by *Dalai »

Hello to everyone,

Important: This thread is not about returning any timestamps to TC but handling them within a plugin.

The thread Wrong timestamp in RAR files modified in other time zone got me thinking about the method of retrieving the file times in my Startups plugin. Currently it uses GetFileAttributesEx() to retrieve the file times, which are then converted to local time via FileTimeToLocalFileTime(). This produces the same results as in Explorer and TC, but only on Win2k and XP (on FAT32 and NTFS). On Win7 the times are one hour off for some of the files, depending on DST, regardless of file-system.

Because of this I changed the implementation to use FileTimeToSystemTime() and SystemTimeToTzSpecificLocalTime() functions. Now the timestamps are correct (i.e. the same as in Explorer/TC) on Win7 but not anymore on Win2k and XP :?. So I tried GetFileTime() instead of GetFileAttributesEx(), because that's what MS suggests to use in their File Times article. The result remains the same :(. For now I have included an if-condition that checks the OS version and calls the functions accordingly (FileTimeToLocalFileTime up to XP, the other two functions on newer Windows versions). However, I highly doubt that's what I'm supposed to do.

What's the correct way to do it? How does TC do it?

[EDIT] Typo [/EDIT]

Regards
Dalai
Last edited by Dalai on 2017-11-29, 14:46 UTC, edited 1 time in total.
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

There is no function which works correctly in all cases.

TC uses the old FileTimeToLocalFileTime() on Windows XP and older, and the newer FileTimeToSystemTime() and SystemTimeToTzSpecificLocalTime() on all newer systems.

You can also override this with NewTimeZoneMethod flag in wincmd.ini, but I think you can neglect this - only a small minority of users will set this flag.
Author of Total Commander
https://www.ghisler.com
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

Thank you for your answer!
ghisler(Author) wrote:There is no function which works correctly in all cases.
Uh, OK. That's not what I was expecting to read, although it's rather typical for MS, I think...
TC uses the old FileTimeToLocalFileTime() on Windows XP and older, and the newer FileTimeToSystemTime() and SystemTimeToTzSpecificLocalTime() on all newer systems.
OK, that's the same way I doubted I was supposed to be doing, and I can leave it as it is.
You can also override this with NewTimeZoneMethod flag in wincmd.ini, but I think you can neglect this - only a small minority of users will set this flag.
Well, I certainly can't expect users to set a flag in their wincmd.ini which affects timestamps shown in TC in general, so I'll stick with what I have now.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Post Reply