Skip to content

Commit

Permalink
FileAttributesPlugin v1.3.0
Browse files Browse the repository at this point in the history
Convert file timestamps from Unix (UTC) to Squeak.

This should finally get the timestamps on Windows correct (in all the
timezone and DST combinations).
  • Loading branch information
akgrant committed Jun 15, 2018
1 parent 0fe68bc commit cfbd87c
Show file tree
Hide file tree
Showing 2 changed files with 403 additions and 167 deletions.
44 changes: 44 additions & 0 deletions platforms/unix/vm/sqUnixMain.c
Expand Up @@ -225,6 +225,7 @@ long ioMicroMSecs(void)
} }


time_t convertToSqueakTime(time_t unixTime); time_t convertToSqueakTime(time_t unixTime);
sqLong convertToLongSqueakTime(time_t unixTime);


/* returns the local wall clock time */ /* returns the local wall clock time */
sqInt ioSeconds(void) sqInt ioSeconds(void)
Expand Down Expand Up @@ -261,6 +262,20 @@ usqLong
ioUTCMicrosecondsNow() { return currentUTCMicroseconds(); } ioUTCMicrosecondsNow() { return currentUTCMicroseconds(); }
#endif /* STACKVM */ #endif /* STACKVM */




/*
* Convert the supplied Unix (UTC) time to Squeak time.
*
* WARNING: On 32 bit platforms time_t is only 32 bits long.
* Since Squeak has an Epoch of 1901 while Unix uses 1970 the
* result is that overflow always occurs for times beyond about 1967.
* The expected result ends up in the image because the value is treated
* as an unsigned integer when converting to an oop.
* convertToSqueakTime should be deprecated in favour of
* convertToLongSqueakTime.
*
*/
time_t convertToSqueakTime(time_t unixTime) time_t convertToSqueakTime(time_t unixTime)
{ {
#ifdef HAVE_TM_GMTOFF #ifdef HAVE_TM_GMTOFF
Expand All @@ -278,6 +293,35 @@ time_t convertToSqueakTime(time_t unixTime)
} }




/*
* Convert the supplied Unix (UTC) time to Squeak time.
*
* Squeak time has an epoch of 1901 and uses local time
* i.e. timezone + daylight savings
*
* Answer an sqLong which is guaranteed to be 64 bits on all platforms.
*/
sqLong convertToLongSqueakTime(time_t unixTime)
{
sqLong result;

result = unixTime;
#ifdef HAVE_TM_GMTOFF
result += localtime(&unixTime)->tm_gmtoff;
#else
# ifdef HAVE_TIMEZONE
result += ((daylight) * 60*60) - timezone;
# else
# error: cannot determine timezone correction
# endif
#endif
/* Squeak epoch is Jan 1, 1901. Unix epoch is Jan 1, 1970: 17 leap years
and 52 non-leap years later than Squeak. */
result += ((52*365UL + 17*366UL) * 24*60*60UL);
return result;
}


/*** VM & Image File Naming ***/ /*** VM & Image File Naming ***/




Expand Down

0 comments on commit cfbd87c

Please sign in to comment.