mattconnolly / ZipArchive

zip archive processing for Cocoa - iPhone and OS X
http://code.google.com/p/ziparchive/
MIT License
840 stars 260 forks source link

file modification timestamps not generated correctly #30

Closed danielmatzke closed 10 years ago

danielmatzke commented 10 years ago

In ZipArchive.m, lines 354 to 356, the library creates an NSDate from the fileInfo.dosDate value.

                NSDate* orgDate = [[NSDate alloc]
                                   initWithTimeInterval:(NSTimeInterval)fileInfo.dosDate
                                   sinceDate:[self Date1980] ];

The value is not a time interval since 1980, it is a bitfield that contains the date components individually:

               http://proger.i-forge.net/MS-DOS_date_and_time_format/OFz

It would be better to use the fileInfo.tmu_date property as follows:

                NSDateComponents* components = [[NSDateComponents alloc] init];
                components.second = fileInfo.tmu_date.tm_sec;
                components.minute = fileInfo.tmu_date.tm_min;
                components.hour = fileInfo.tmu_date.tm_hour;
                components.day = fileInfo.tmu_date.tm_mday;
                components.month = fileInfo.tmu_date.tm_mon;
                components.year = fileInfo.tmu_date.tm_year;

                NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
                NSDate* orgDate = [[gregorianCalendar dateFromComponents:components] retain];
                [components release];
                [gregorianCalendar release];
mattconnolly commented 10 years ago

Hi Daniel,

Thanks for finding this. Can you send a pull request through please?

Also, I assume that the date should be interpreted in the machine/device's local time zone??

Cheers, Matt.

danielmatzke commented 10 years ago

Hi Matt, sorry for letting you wait - will send you a pull request (soon) -Daniel

mattconnolly commented 10 years ago

Fixed by pull request #31.