@@ -225,6 +225,7 @@ long ioMicroMSecs(void)
225225}
226226
227227time_t convertToSqueakTime (time_t unixTime );
228+ sqLong convertToLongSqueakTime (time_t unixTime );
228229
229230/* returns the local wall clock time */
230231sqInt ioSeconds (void )
@@ -261,6 +262,20 @@ usqLong
261262ioUTCMicrosecondsNow () { return currentUTCMicroseconds (); }
262263#endif /* STACKVM */
263264
265+
266+
267+ /*
268+ * Convert the supplied Unix (UTC) time to Squeak time.
269+ *
270+ * WARNING: On 32 bit platforms time_t is only 32 bits long.
271+ * Since Squeak has an Epoch of 1901 while Unix uses 1970 the
272+ * result is that overflow always occurs for times beyond about 1967.
273+ * The expected result ends up in the image because the value is treated
274+ * as an unsigned integer when converting to an oop.
275+ * convertToSqueakTime should be deprecated in favour of
276+ * convertToLongSqueakTime.
277+ *
278+ */
264279time_t convertToSqueakTime (time_t unixTime )
265280{
266281#ifdef HAVE_TM_GMTOFF
@@ -278,6 +293,35 @@ time_t convertToSqueakTime(time_t unixTime)
278293}
279294
280295
296+ /*
297+ * Convert the supplied Unix (UTC) time to Squeak time.
298+ *
299+ * Squeak time has an epoch of 1901 and uses local time
300+ * i.e. timezone + daylight savings
301+ *
302+ * Answer an sqLong which is guaranteed to be 64 bits on all platforms.
303+ */
304+ sqLong convertToLongSqueakTime (time_t unixTime )
305+ {
306+ sqLong result ;
307+
308+ result = unixTime ;
309+ #ifdef HAVE_TM_GMTOFF
310+ result += localtime (& unixTime )-> tm_gmtoff ;
311+ #else
312+ # ifdef HAVE_TIMEZONE
313+ result += ((daylight ) * 60 * 60 ) - timezone ;
314+ # else
315+ # error : cannot determine timezone correction
316+ # endif
317+ #endif
318+ /* Squeak epoch is Jan 1, 1901. Unix epoch is Jan 1, 1970: 17 leap years
319+ and 52 non-leap years later than Squeak. */
320+ result += ((52 * 365UL + 17 * 366UL ) * 24 * 60 * 60UL );
321+ return result ;
322+ }
323+
324+
281325/*** VM & Image File Naming ***/
282326
283327
0 commit comments