[Patches] Patch to timemodule, this time with patch:-)
Jack Jansen
Jack.Jansen@oratrix.com
Wed, 26 Apr 2000 22:39:08 +0200
This is a multi-part message in MIME format.
--------------85E38E06D9657C4E356D2881
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Here it is again (I hope:-).
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.
--------------85E38E06D9657C4E356D2881
Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="522A6368";
name="patch-timemodule"
Content-Transfer-Encoding: 7bit
Content-Description: Unknown Document
Content-Disposition: inline;
filename="patch-timemodule"
Index: timemodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/timemodule.c,v
retrieving revision 2.81
diff -c -r2.81 timemodule.c
*** timemodule.c 2000/03/24 20:35:20 2.81
--- timemodule.c 2000/04/21 22:58:16
***************
*** 41,46 ****
--- 41,54 ----
#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,276 ****
--- 279,287 ----
{
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,485 ****
--- 491,499 ----
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,522 ****
--- 531,539 ----
"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);
}
--------------85E38E06D9657C4E356D2881--