summaryrefslogtreecommitdiffstats
path: root/Modules/timemodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r--Modules/timemodule.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index b01366a..7d53179 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -41,6 +41,14 @@ PERFORMANCE OF THIS SOFTWARE.
#ifdef macintosh
#include <time.h>
+#include <OSUtils.h>
+#ifdef USE_GUSI2
+/* GUSI, the I/O library which has the time() function and such uses the
+** Mac epoch of 1904. MSL, the C library which has localtime() and so uses
+** the ANSI epoch of 1900.
+*/
+#define GUSI_TO_MSL_EPOCH (4*365*24*60*60)
+#endif /* USE_GUSI2 */
#else
#include <sys/types.h>
#endif
@@ -271,6 +279,9 @@ time_convert(when, function)
{
struct tm *p;
errno = 0;
+#if defined(macintosh) && defined(USE_GUSI2)
+ when = when + GUSI_TO_MSL_EPOCH;
+#endif
p = function(&when);
if (p == NULL) {
#ifdef EINVAL
@@ -480,6 +491,9 @@ time_ctime(self, args)
if (!PyArg_Parse(args, "d", &dt))
return NULL;
tt = (time_t)dt;
+#if defined(macintosh) && defined(USE_GUSI2)
+ tt = tt + GUSI_TO_MSL_EPOCH;
+#endif
p = ctime(&tt);
if (p == NULL) {
PyErr_SetString(PyExc_ValueError, "unconvertible time");
@@ -517,6 +531,9 @@ time_mktime(self, args)
"mktime argument out of range");
return NULL;
}
+#if defined(macintosh) && defined(USE_GUSI2)
+ tt = tt - GUSI_TO_MSL_EPOCH;
+#endif
return PyFloat_FromDouble((double)tt);
}