Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c410e92

Browse files
committed
Jack Jansen:
This patch is a workaround for Macintosh, where the GUSI I/O library (time, stat, etc) use the MacOS epoch of 1-Jan-1904 and the MSL C library (ctime, localtime, etc) uses the (apparently ANSI standard) epoch of 1-Jan-1900. Python programs see the MacOS epoch and we convert values when needed.
1 parent 9e392e2 commit c410e92

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Modules/timemodule.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ PERFORMANCE OF THIS SOFTWARE.
4141

4242
#ifdef macintosh
4343
#include <time.h>
44+
#include <OSUtils.h>
45+
#ifdef USE_GUSI2
46+
/* GUSI, the I/O library which has the time() function and such uses the
47+
** Mac epoch of 1904. MSL, the C library which has localtime() and so uses
48+
** the ANSI epoch of 1900.
49+
*/
50+
#define GUSI_TO_MSL_EPOCH (4*365*24*60*60)
51+
#endif /* USE_GUSI2 */
4452
#else
4553
#include <sys/types.h>
4654
#endif
@@ -271,6 +279,9 @@ time_convert(when, function)
271279
{
272280
struct tm *p;
273281
errno = 0;
282+
#if defined(macintosh) && defined(USE_GUSI2)
283+
when = when + GUSI_TO_MSL_EPOCH;
284+
#endif
274285
p = function(&when);
275286
if (p == NULL) {
276287
#ifdef EINVAL
@@ -480,6 +491,9 @@ time_ctime(self, args)
480491
if (!PyArg_Parse(args, "d", &dt))
481492
return NULL;
482493
tt = (time_t)dt;
494+
#if defined(macintosh) && defined(USE_GUSI2)
495+
tt = tt + GUSI_TO_MSL_EPOCH;
496+
#endif
483497
p = ctime(&tt);
484498
if (p == NULL) {
485499
PyErr_SetString(PyExc_ValueError, "unconvertible time");
@@ -517,6 +531,9 @@ time_mktime(self, args)
517531
"mktime argument out of range");
518532
return NULL;
519533
}
534+
#if defined(macintosh) && defined(USE_GUSI2)
535+
tt = tt - GUSI_TO_MSL_EPOCH;
536+
#endif
520537
return PyFloat_FromDouble((double)tt);
521538
}
522539

0 commit comments

Comments
 (0)