Skip to content

Commit dff3ef1

Browse files
committed
Store ZipEntry.DateTime in dedicated backing field
This allows reading values with a higher resolution than DOS time (2 second accuracy).
1 parent f36ca37 commit dff3ef1

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -721,17 +721,13 @@ public DateTime DateTime
721721
{
722722
get
723723
{
724-
uint sec = Math.Min(59, 2 * (dosTime & 0x1f));
725-
uint min = Math.Min(59, (dosTime >> 5) & 0x3f);
726-
uint hrs = Math.Min(23, (dosTime >> 11) & 0x1f);
727-
uint mon = Math.Max(1, Math.Min(12, ((dosTime >> 21) & 0xf)));
728-
uint year = ((dosTime >> 25) & 0x7f) + 1980;
729-
int day = Math.Max(1, Math.Min(DateTime.DaysInMonth((int)year, (int)mon), (int)((dosTime >> 16) & 0x1f)));
730-
return new System.DateTime((int)year, (int)mon, day, (int)hrs, (int)min, (int)sec);
724+
return dateTime;
731725
}
732726

733727
set
734728
{
729+
dateTime = value;
730+
735731
var year = (uint)value.Year;
736732
var month = (uint)value.Month;
737733
var day = (uint)value.Day;
@@ -1329,6 +1325,7 @@ public static string CleanName(string name)
13291325
private ushort versionToExtract; // Version required to extract (library handles <= 2.0)
13301326
private uint crc;
13311327
private uint dosTime;
1328+
private DateTime dateTime;
13321329

13331330
private CompressionMethod method = CompressionMethod.Deflated;
13341331
private byte[] extra;

0 commit comments

Comments
 (0)