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

Skip to content

Commit e6a4b7b

Browse files
committed
timezone support for macintosh (Jack)
1 parent 5bd919b commit e6a4b7b

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Modules/timemodule.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,37 @@ extern int ftime();
8989
static int floatsleep Py_PROTO((double));
9090
static double floattime Py_PROTO(());
9191

92+
#ifdef macintosh
93+
/* Our own timezone. We have enough information to deduce whether
94+
** DST is on currently, but unfortunately we cannot put it to good
95+
** use because we don't know the rules (and that is needed to have
96+
** localtime() return correct tm_isdst values for times other than
97+
** the current time. So, we cop out and only tell the user the current
98+
** timezone.
99+
*/
100+
static long timezone;
101+
102+
static void
103+
initmactimezone()
104+
{
105+
MachineLocation loc;
106+
long delta;
107+
108+
ReadLocation(&loc);
109+
110+
if (loc.latitude == 0 && loc.longitude == 0 && loc.u.gmtDelta == 0)
111+
return;
112+
113+
delta = loc.u.gmtDelta & 0x00FFFFFF;
114+
115+
if (delta & 0x00800000)
116+
delta |= 0xFF000000;
117+
118+
timezone = -delta;
119+
}
120+
#endif /* macintosh */
121+
122+
92123
static PyObject *
93124
time_time(self, args)
94125
PyObject *self;
@@ -430,6 +461,11 @@ inittime()
430461
ins(d, "tzname",
431462
Py_BuildValue("(zz)", wintername, summername));
432463
}
464+
#else
465+
#ifdef macintosh
466+
initmactimezone();
467+
ins(d, "timezone", PyInt_FromLong(timezone));
468+
#endif /* macintosh */
433469
#endif /* HAVE_TM_ZONE */
434470
#endif /* !HAVE_TZNAME */
435471
if (PyErr_Occurred())

0 commit comments

Comments
 (0)