diff options
author | Alexander Köplinger <alex.koeplinger@outlook.com> | 2016-05-31 12:59:49 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2016-05-31 14:55:05 +0300 |
commit | 07baa1cce4d5ec969d9dff304cc2f19ba3101cc9 (patch) | |
tree | c9b573854ef15b0800a1853bb8f7cf36336a17dd /mcs/class/WindowsBase | |
parent | 059d656a9b851e90585e3a9f70a7c02e4cc0354e (diff) |
[WindowsBase] Fix off-by-one error in ZipTime
The date/time struct in zip.h defines the month value as
uInt tm_mon; /* months since January - [0,11] */
.NET's DateTime object in turn stores months from 1-12. We didn't
take this into account when passing the values from managed->native
so the month ended up being off by one.
We didn't use this codepath before https://github.com/mono/mono/pull/3036
that's why it didn't show up until now.
Diffstat (limited to 'mcs/class/WindowsBase')
-rw-r--r-- | mcs/class/WindowsBase/Test/System.IO.Packaging/PackageTest.cs | 4 | ||||
-rw-r--r-- | mcs/class/WindowsBase/ZipSharp/ZipTime.cs | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/mcs/class/WindowsBase/Test/System.IO.Packaging/PackageTest.cs b/mcs/class/WindowsBase/Test/System.IO.Packaging/PackageTest.cs index d4867c936b1..9a1aa2ea4fb 100644 --- a/mcs/class/WindowsBase/Test/System.IO.Packaging/PackageTest.cs +++ b/mcs/class/WindowsBase/Test/System.IO.Packaging/PackageTest.cs @@ -432,7 +432,11 @@ namespace MonoTests.System.IO.Packaging { using (var archive = new ZipArchive(stream))
{
foreach (var entry in archive.Entries)
+ {
Assert.AreEqual (DateTime.Now.Year, entry.LastWriteTime.Year);
+ Assert.AreEqual (DateTime.Now.Month, entry.LastWriteTime.Month);
+ Assert.AreEqual (DateTime.Now.Day, entry.LastWriteTime.Day);
+ }
}
}
}
diff --git a/mcs/class/WindowsBase/ZipSharp/ZipTime.cs b/mcs/class/WindowsBase/ZipSharp/ZipTime.cs index 2736df9410d..e2c3abb66ca 100644 --- a/mcs/class/WindowsBase/ZipSharp/ZipTime.cs +++ b/mcs/class/WindowsBase/ZipSharp/ZipTime.cs @@ -25,13 +25,13 @@ namespace zipsharp minute = (uint) time.Minute; hour = (uint) time.Hour; day = (uint) time.Day; - month = (uint) time.Month; + month = (uint) time.Month - 1; year = (uint) time.Year; } public DateTime Date { - get { return new DateTime ((int) year, (int) month, (int) day, (int) hour, (int) minute, (int) second); } + get { return new DateTime ((int) year, (int) month + 1, (int) day, (int) hour, (int) minute, (int) second); } } } } |