Skip to content

Commit 1a47a8e

Browse files
committed
Revert "Back ZipEntry.DateTime with a real DateTime field instead of DosTime"
This reverts commit 51605f8. The Zip file format stores date and time in a single 32 bit integer, based on the format used by MS-DOS. Adding accuracy by using a DateTime object won't necessarily result in an accurate date and time. See http://stackoverflow.com/questions/3725662/what-is-the-earliest-timestamp-value-that-is-supported-in-zip-file-format for further information. # Conflicts: # ICSharpCode.SharpZipLib/Zip/ZipEntry.cs
1 parent 6250f49 commit 1a47a8e

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

ICSharpCode.SharpZipLib/Zip/ZipEntry.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ public ZipEntry(ZipEntry entry)
212212
compressedSize = entry.compressedSize;
213213
crc = entry.crc;
214214
dosTime = entry.dosTime;
215-
dateTime = entry.dateTime;
216215
method = entry.method;
217216
comment = entry.comment;
218217
versionToExtract = entry.versionToExtract;
@@ -621,7 +620,16 @@ public long DosTime {
621620
/// </remarks>
622621
public DateTime DateTime
623622
{
624-
get { return dateTime; }
623+
get
624+
{
625+
uint sec = Math.Min(59, 2 * (dosTime & 0x1f));
626+
uint min = Math.Min(59, (dosTime >> 5) & 0x3f);
627+
uint hrs = Math.Min(23, (dosTime >> 11) & 0x1f);
628+
uint mon = Math.Max(1, Math.Min(12, ((dosTime >> 21) & 0xf)));
629+
uint year = ((dosTime >> 25) & 0x7f) + 1980;
630+
int day = Math.Max(1, Math.Min(DateTime.DaysInMonth((int)year, (int)mon), (int)((dosTime >> 16) & 0x1f)));
631+
return new System.DateTime((int)year, (int)mon, day, (int)hrs, (int)min, (int)sec);
632+
}
625633

626634
set {
627635
var year = (uint)value.Year;
@@ -930,7 +938,7 @@ internal void ProcessExtraData(bool localHeader)
930938
}
931939
}
932940

933-
dateTime = GetDateTime(extraData);
941+
DateTime = GetDateTime(extraData);
934942
if (method == CompressionMethod.WinZipAES) {
935943
ProcessAESExtraData(extraData);
936944
}
@@ -1155,7 +1163,6 @@ public static string CleanName(string name)
11551163
ushort versionToExtract; // Version required to extract (library handles <= 2.0)
11561164
uint crc;
11571165
uint dosTime;
1158-
DateTime dateTime;
11591166

11601167
CompressionMethod method = CompressionMethod.Deflated;
11611168
byte[] extra;

0 commit comments

Comments
 (0)