Timestamp Issues

Aug 13, 2009 at 8:19 PM

Hello!

I noticed that timestamps for zimEntries in my ZipFile instance are not correct. Here is the code I am using to zip a directory:

<font size="2" color="#0000ff"><font size="2" color="#0000ff">

using

</font></font><font size="2" color="#0000ff">

 

</font>

(ZipFile zip = new ZipFile())

{ 

    zip.AddDirectory(path);

    MemoryStream memoryStream = new MemoryStream();

}

in the debugger, I can see the timestamp values for one of the Entries that look like this:

Ctime {8/13/2009 7:47:36 PM} System.DateTime

LastModified {8/13/2009 3:47:36 PM} System.DateTime

Mtime {8/13/2009 7:47:36 PM} System.DateTime

Only the LastModified field has the timestamp that is close to the actual timestamp of the file. It is not clear to me why Mtime and Ctime are shifted by 4 hrs? Also the timestamp for LastModified seems to be rounded and doesn't exactly match the timestamp of the file. So, the comparison of timestamps will not work properly.

Does anyone have any suggestion on how to work around this issue?

Thanks,

Norton.

 

Coordinator
Aug 13, 2009 at 8:57 PM

This is my favorite topic!

I kid.  It's been very tricky for me to get the timestamps to work properly.

But your problem is simple.  LastModified is expressed in LocalTime, while Ctime and Mtime are in UTC.  They are all the same point in time. 

The rounding is a side effect of the way the zip format stores timestamps.  If you want to compare LastModified to another time, you'll need to compare the delta.  In other words, subtract the time on the file from another time, and then compare that difference (which is a TimeSpan) to a fixed TimeSpan.  If you are using the LastModified time, the precision is 2 seconds, so you will need to compare to a TimeSpan of 2 seconds. 

If you use Mtime or Ctime, then the comparison is exact.  These numbers are stored differently in the zip file, stored with the full precision of the NTFS filesystem.  But if the zip file was created on a non-NTFS system, then you probably have to revert to the delta approach again.  It's safest to just use the delta approach in all cases.

Check the doc on these properties for more info.  

 

Aug 14, 2009 at 4:11 PM
Thank you very much for your response, it was very helpful!


From: Cheeso [mailto:notifications@codeplex.com]
Sent: Thursday, August 13, 2009 4:57 PM
To: Akopov, Sergei (GE EntSol, Intelligent Platforms)
Subject: Re: Timestamp Issues [DotNetZip:65509]

From: Cheeso

This is my favorite topic!

I kid. It's been very tricky for me to get the timestamps to work properly.

But your problem is simple. LastModified is expressed in LocalTime, while Ctime and Mtime are in UTC. They are all the same point in time.

The rounding is a side effect of the way the zip format stores timestamps. If you want to compare LastModified to another time, you'll need to compare the delta. In other words, subtract the time on the file from another time, and then compare that difference (which is a TimeSpan) to a fixed TimeSpan. If you are using the LastModified time, the precision is 2 seconds, so you will need to compare to a TimeSpan of 2 seconds.

If you use Mtime or Ctime, then the comparison is exact. These numbers are stored differently in the zip file, stored with the full precision of the NTFS filesystem. But if the zip file was created on a non-NTFS system, then you probably have to revert to the delta approach again. It's safest to just use the delta approach in all cases.

Check the doc on these properties for more info.