[Python-Dev] zipimport, round 3 (or would that be that 37?)

Just van Rossum just@letterror.com
Mon, 9 Dec 2002 15:56:03 +0100


Skip Montanaro wrote:

> Looking at the code in zipfile.py which converts a time tuple to DOS date
> and time shorts (I didn't see code that went the other way), it appears that
> dosdate is 7 bits for the year, 4 bits for the month and 5 bits for the day.
> Dostime looks like 5 bits for the hour, 6 bits for the minute and 5 bits for
> half the number of seconds.  You should be able to extract those chunks into
> a tm structure then call the C lib mktime() function to convert to a time in
> seconds since the epoch (this is just off the top of my head):
> 
>     stm = malloc(sizeof(struct tm));
>     stm->tm_sec = (dostime & 0x1f) * 2;
>     stm->tm_min = (dostime >> 5) & 0x3f;
>     stm->tm_hour = dostime >> 11);
>     stm->tm_mday = dosdate & 0x1f;
>     stm->tm_mon = (dosdate >> 5) & 0xf;
>     stm->tm_year = dosdate >> 9;
>     mtime = mktime(stm);
> 
> Here's the layout of dosdate and dostime as I understand it from reading the
> zipfile code:
> 
>     dosdate = yyyyyyymmmmddddd
>     dostime = hhhhhmmmmmmsssss
> 
> where "sssss" is actually the seconds divided by 2.  I'll let others check
> my code.  I have to dash off to a class.

Thanks! How portable is this? Which header(s) should I include?

Just