Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileAttributesPlugin 1.3.0 #268

Merged
merged 8 commits into from
Jun 17, 2018
43 changes: 43 additions & 0 deletions platforms/Mac OS/vm/sqMacTime.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ unsigned volatile long long
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
Expand All @@ -165,3 +178,33 @@ time_t convertToSqueakTime(time_t unixTime)
and 52 non-leap years later than Squeak. */
return unixTime + ((52*365UL + 17*366UL) * 24*60*60UL);
}


/*
* 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;
}

2 changes: 1 addition & 1 deletion platforms/Mac OS/vm/sqMacTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

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