Time zone insanity on Windows

Today’s cpan-outdated | cpanm brought with it an interesting test failure in Mojolicious:

#   Failed test 'Last-Modified: Sat, 21 Feb 2015 05:08:18 GMT'
#   at t\mojolicious\app.t line 405.
#          got: 'Sat, 21 Feb 2015 06:08:18 GMT'
#     expected: 'Sat, 21 Feb 2015 05:08:18 GMT'

#   Failed test '304 Not Modified'
#   at t\mojolicious\app.t line 425.
#          got: '200'
#     expected: '304'

#   Failed test 'exact match for content'
#   at t\mojolicious\app.t line 425.
#          got: 'Hello Mojo from a development static file!
# '
#     expected: ''
# Looks like you failed 3 tests of 440.
t\mojolicious\app.t ........................ 

Recent EST-EDT switchover still on my mind, I was struck by the exact one hour difference between the got and expected values, and the fact that the file’s date was before the switchover.

I am not familiar with the Mojolicious codebase, I didn’t really know where to begin, so I opened an issue.

Eventually, Sebastian Riedel fixed the issue simply by obtaining the file’s date information in exactly the same way in the test as the server does, and this spurious test failure was eliminated (especially since the server was reporting the correct date).

I was not aware of this Windows insanity before, but apparently enough people knew about it that there is a CPAN module Win32::UTCFileTime) to deal with it.

Watch this:

Let’s try to create a file using Cygwin’s touch:

C:\...\Temp> c:\opt\cygwin64\bin\touch -t 201502210108.00 test-file.txt
C:\...\Temp> dir
2015-02-21  02:08 AM                 0 test-file.txt

Yes, because clocks were moved an hour ahead on March 1st, I now have a file with a time that is an hour past the time I asked to be used.

Let’s see what perl does with this:

C:\...Temp> perl -E "say scalar gmtime( (stat 'test-file.txt')[9] )"
Sat Feb 21 06:08:00 2015

That is wrong. Before March 1st, with EST in effect, the offset was -05:00. Today, it is -04:00.

C:\...\Temp> perl -E "open my $fh, 'test-file.txt'; say scalar gmtime( (stat $fh)[9])"
Sat Feb 21 07:08:00 2015

Now, that gives the correct time. Same file, same stat, except that in one case we passed the file name, and in the other case we passed a file handle.

Now, it looks like this did not affect builds using Strawberry Perl at all.

To verify, note:

C:\...\Temp> c:\opt\strawberry\perl\bin\perl -E "say scalar gmtime((stat 'test-file.txt')[9])"
Sat Feb 21 07:08:00 2015

No problem there.

So, I am left with some questions: Is this because of 1) a problem with my system; or 2) a problem with my build process; or 3) the fact that I am building with Visual Studio?

If you have any insight, I would appreciate hearing about it on /r/perl.