Skip to content
Permalink
Browse files

FileAttributesPlugin v1.3.0

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 cfbd87ccd361d339df9ce3e2d7f9c6154335b71e
Showing with 403 additions and 167 deletions.
  1. +44 −0 platforms/unix/vm/sqUnixMain.c
  2. +359 −167 src/plugins/FileAttributesPlugin/FileAttributesPlugin.c
@@ -225,6 +225,7 @@ long ioMicroMSecs(void)
}

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

/* returns the local wall clock time */
sqInt ioSeconds(void)
@@ -261,6 +262,20 @@ usqLong
ioUTCMicrosecondsNow() { return currentUTCMicroseconds(); }
#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)
{
#ifdef HAVE_TM_GMTOFF
@@ -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 ***/


0 comments on commit cfbd87c

Please sign in to comment.
You can’t perform that action at this time.