[Mono.Posix] Fix time_t conversions.
authorJonathan Pryor <jonpryor@vt.edu>
Fri, 14 Jun 2013 20:11:53 +0000 (16:11 -0400)
committerJonathan Pryor <jonpryor@vt.edu>
Fri, 14 Jun 2013 20:18:47 +0000 (16:18 -0400)
commit8c7397406e3f4bd1be57eb5aadd8f924dd3c0710
tree85e377ab0a98bec3857ca408bd136ba50960a5c0
parent0418ecd93033138cbf1316a5372b511ffdbc3c8c
[Mono.Posix] Fix time_t conversions.

Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=12686

Mono.Unix.UnixFileSystemInfo.LastWriteTime & co. were hilariously
wrong. Just...hilariously wrong.

$ ls -l bxc12686.exe
-rwxr-xr-x  1 jon  staff  4096 Jun 14 15:43 bxc12686.exe

$ csharp -r:Mono.Posix
csharp> new Mono.Unix.UnixFileInfo("bxc12686.exe").LastWriteTime;
6/14/2013 7:43:12 PM

Note: I'm currently in EDT (US Eastern Daylight Time). LastWriteTime
is supposed to be in the local time; it's 4 hours off (which also
happens to be the EDT UTF offset: -4:00).

The fundamental problem was that NativeConvert.FromTimeT() was written
for pre-.NET 2.0 environments, which precluded use (or knowledge of!)
DateTimeKind. Now that .NET 1.1 is no longer supported, and 2.0 is on
the its deathbead (bring on 4.5!), we can be smarter and let DateTime
sanely handle the conversion logic for us.

After the fix:

$ csharp -r:Mono.Posix
csharp> new Mono.Unix.UnixFileInfo("bxc12686.exe").LastWriteTime;
6/14/2013 3:43:12 PM
mcs/class/Mono.Posix/Mono.Unix.Native/NativeConvert.cs