mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									9e392e2412
								
							
						
					
					
						commit
						c410e92974
					
				
					 1 changed files with 17 additions and 0 deletions
				
			
		| 
						 | 
					@ -41,6 +41,14 @@ PERFORMANCE OF THIS SOFTWARE.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef macintosh
 | 
					#ifdef macintosh
 | 
				
			||||||
#include <time.h>
 | 
					#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
 | 
					#else
 | 
				
			||||||
#include <sys/types.h>
 | 
					#include <sys/types.h>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -271,6 +279,9 @@ time_convert(when, function)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct tm *p;
 | 
						struct tm *p;
 | 
				
			||||||
	errno = 0;
 | 
						errno = 0;
 | 
				
			||||||
 | 
					#if defined(macintosh) && defined(USE_GUSI2)
 | 
				
			||||||
 | 
						when = when + GUSI_TO_MSL_EPOCH;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
	p = function(&when);
 | 
						p = function(&when);
 | 
				
			||||||
	if (p == NULL) {
 | 
						if (p == NULL) {
 | 
				
			||||||
#ifdef EINVAL
 | 
					#ifdef EINVAL
 | 
				
			||||||
| 
						 | 
					@ -480,6 +491,9 @@ time_ctime(self, args)
 | 
				
			||||||
	if (!PyArg_Parse(args, "d", &dt))
 | 
						if (!PyArg_Parse(args, "d", &dt))
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	tt = (time_t)dt;
 | 
						tt = (time_t)dt;
 | 
				
			||||||
 | 
					#if defined(macintosh) && defined(USE_GUSI2)
 | 
				
			||||||
 | 
						tt = tt + GUSI_TO_MSL_EPOCH;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
	p = ctime(&tt);
 | 
						p = ctime(&tt);
 | 
				
			||||||
	if (p == NULL) {
 | 
						if (p == NULL) {
 | 
				
			||||||
		PyErr_SetString(PyExc_ValueError, "unconvertible time");
 | 
							PyErr_SetString(PyExc_ValueError, "unconvertible time");
 | 
				
			||||||
| 
						 | 
					@ -517,6 +531,9 @@ time_mktime(self, args)
 | 
				
			||||||
                                "mktime argument out of range");
 | 
					                                "mktime argument out of range");
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					#if defined(macintosh) && defined(USE_GUSI2)
 | 
				
			||||||
 | 
						tt = tt - GUSI_TO_MSL_EPOCH;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
	return PyFloat_FromDouble((double)tt);
 | 
						return PyFloat_FromDouble((double)tt);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue