FileModifyDate reported differently on Linux and Windows

Started by Xlnt, February 02, 2015, 06:53:13 PM

Previous topic - Next topic

Xlnt

Quote from: Phil Harvey on February 12, 2015, 07:00:05 AM
Nice.  Thanks for testing this!  It looks like I don't have to worry about rounding after all.  This is a good thing because the simple solution of adding 0.5 then truncating to integer won't work for times before 1970 (negative time_t's are allowed on some systems).
You definitely don't want to round, because a time of 00:00:00.777 will become 00:00:01.000, which would be confusing (I think). Just verified this, the built-in stat function will truncate milliseconds, and so do Windows Explorer and ls -l --time-style="+%Y-%m-%d %H:%M:%S".

I didn't know negative time_t values were allowed. I did some testing, but neither stat (from the GNU tools) nor ExifTool seem to handle dates before 1970 very well. I guess I have a system that doesn't support it? I could post some details.

I noticed that when shifting (e.g. -FileModifyDate+=1) or copying (e.g. "-FileModifyDate<FileAccessDate") file times on Windows, the milliseconds part gets somewhere lost. Although not really important, can this be prevented?

I also tested the script with 32-bit perl without 64-bit int support and it ran fine. Whereas the use integer approach failed horribly, as expected.

Quote from: Phil Harvey on February 12, 2015, 07:00:05 AM
Edit: I was reading about the FILETIME structure, and it seems that the lsw always comes first.  So it looks as if word order may not be a problem.

I believe this is true.

Phil Harvey

Quote from: Xlnt on February 12, 2015, 04:10:41 PM
You definitely don't want to round, because a time of 00:00:00.777 will become 00:00:01.000, which would be confusing (I think).

I agree.  I realized this, but hadn't thought enough about it to decide how it should behave.

QuoteJust verified this, the built-in stat function will truncate milliseconds

Great.  No rounding then.

QuoteI noticed that when shifting (e.g. -FileModifyDate+=1) or copying (e.g. "-FileModifyDate<FileAccessDate") file times on Windows, the milliseconds part gets somewhere lost. Although not really important, can this be prevented?

I'll think about this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

Quote from: Phil Harvey on February 12, 2015, 04:54:12 PM
QuoteI noticed that when shifting (e.g. -FileModifyDate+=1) or copying (e.g. "-FileModifyDate<FileAccessDate") file times on Windows, the milliseconds part gets somewhere lost. Although not really important, can this be prevented?

I'll think about this.

The way things work, the time shift is applied to the converted value of the date/time tag.  For filesystem date/time tags, the converted value does not include factional seconds, so these are lost during the shift.  It would require much effort to change this, so is probably not worthwhile.

- Phil

P.S. Since you taught me how to import Win32::API functions, I am now able to fix the remaining Windows Unicode file name problems (although I am still ignoring CopyFileAttrs).  In total, ExifTool now contains a rather substantial amount of ugly Windows patch code.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

Version 9.85 is now available.  Please let me know if you have any problems with it.

Thanks again for all your work on this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Xlnt

Quote from: Phil Harvey on February 14, 2015, 09:50:20 AM
Version 9.85 is now available.  Please let me know if you have any problems with it.

Version 9.85 shows the dates with correct daylight saving time offset. Thank you!

Phil Harvey

The honours are really yours for the fantastic job you did in researching, coding and testing the solution to this problem.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).