[Python-checkins] python/nondist/sandbox/datetime datetime.h,1.5,1.6 obj_date.c,1.1,1.2 obj_datetime.c,1.1,1.2 obj_delta.c,1.1,1.2

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Thu, 21 Nov 2002 10:02:03 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv10672

Modified Files:
	datetime.h obj_date.c obj_datetime.c obj_delta.c 
Log Message:
Reindent with tabs.  Tim will take it from here.

Index: datetime.h
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** datetime.h	20 Aug 2002 18:53:07 -0000	1.5
--- datetime.h	21 Nov 2002 18:02:00 -0000	1.6
***************
*** 10,23 ****
  typedef struct
  {
!     PyObject_HEAD
!     long hashcode;
!     unsigned char data[_PyDateTime_DATE_DATA_SIZE];
  }  PyDateTime_Date;
  
  typedef struct
  {
!     PyObject_HEAD
!     long hashcode;
!     unsigned char data[_PyDateTime_DATETIME_DATA_SIZE];
  }  PyDateTime_DateTime;
  
--- 10,23 ----
  typedef struct
  {
! 	PyObject_HEAD
! 	long hashcode;
! 	unsigned char data[_PyDateTime_DATE_DATA_SIZE];
  }  PyDateTime_Date;
  
  typedef struct
  {
! 	PyObject_HEAD
! 	long hashcode;
! 	unsigned char data[_PyDateTime_DATETIME_DATA_SIZE];
  }  PyDateTime_DateTime;
  

Index: obj_date.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_date.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** obj_date.c	20 Aug 2002 18:53:07 -0000	1.1
--- obj_date.c	21 Nov 2002 18:02:01 -0000	1.2
***************
*** 7,68 ****
  normalize_date(long int *year, long int *month, long int *day)
  {
!     long int carry, dim;
  
!     /* This is muddy: the proper range for day can't be determined
!      * without knowing the correct month and year, but if day is,
!      * e.g., plus or minus a million, the current month and year
!      * values make no sense (and may also be out of bounds
!      * themselves).  Saying 12 months == 1 year should be
!      * non-controversial.
!      */
!     if (*month > 12) {
!         carry = (*month - 1) / 12;
!         *month -= (carry * 12);
!         *year += carry;
!         assert(*month >= 1);
!         assert(*month <= 12);
!     }
!     /* Now only day can be out of bounds (year may also be out of
!      * bounds for a datetime object, but we don't care about that
!      * here).  If day is out of bounds, what to do is arguable, but at
!      * least the method here is principled and explainable.
!      */
!     dim = days_in_month(*year, *month);
!     if (*day < 1 || *day > dim) {
!         /* Move day-1 days from the first of the month.  First try to
!          * get off cheap if we're only one day out of range
!          * (adjustments for timezone alone can't be worse than that).
!          */
!         if (*day == 0) {
!             *month -= 1;
!             if (*month > 0)
!                 *day = days_in_month(*year, *month);
!             else {
!                 *year -= 1;
!                 *month = 12;
!                 *day = 31;
!             }
!         }
!         else if (*day == dim + 1) {
!             /* move forward a day */
!             *month += 1;
!             *day = 1;
!             if (*month > 12) {
!                 *month = 1;
!                 *year += 1;
!             }
!         }
!         else {
!             long int ordinal = ymd_to_ord(*year, *month, 1) + *day - 1;
!             ord_to_ymd(ordinal, year, month, day);
!         }
!     }
!     assert(*month > 0);
!     assert(*day > 0);
!     if (*year < MINYEAR) {
!         PyErr_SetString(PyExc_OverflowError, "date value out of range");
!         return 0;
!     }
!     return 1;
  }
  
--- 7,68 ----
  normalize_date(long int *year, long int *month, long int *day)
  {
! 	long int carry, dim;
  
! 	/* This is muddy: the proper range for day can't be determined
! 	 * without knowing the correct month and year, but if day is,
! 	 * e.g., plus or minus a million, the current month and year
! 	 * values make no sense (and may also be out of bounds
! 	 * themselves).  Saying 12 months == 1 year should be
! 	 * non-controversial.
! 	 */
! 	if (*month > 12) {
! 		carry = (*month - 1) / 12;
! 		*month -= (carry * 12);
! 		*year += carry;
! 		assert(*month >= 1);
! 		assert(*month <= 12);
! 	}
! 	/* Now only day can be out of bounds (year may also be out of
! 	 * bounds for a datetime object, but we don't care about that
! 	 * here).  If day is out of bounds, what to do is arguable, but at
! 	 * least the method here is principled and explainable.
! 	 */
! 	dim = days_in_month(*year, *month);
! 	if (*day < 1 || *day > dim) {
! 		/* Move day-1 days from the first of the month.  First try to
! 		 * get off cheap if we're only one day out of range
! 		 * (adjustments for timezone alone can't be worse than that).
! 		 */
! 		if (*day == 0) {
! 			*month -= 1;
! 			if (*month > 0)
! 				*day = days_in_month(*year, *month);
! 			else {
! 				*year -= 1;
! 				*month = 12;
! 				*day = 31;
! 			}
! 		}
! 		else if (*day == dim + 1) {
! 			/* move forward a day */
! 			*month += 1;
! 			*day = 1;
! 			if (*month > 12) {
! 				*month = 1;
! 				*year += 1;
! 			}
! 		}
! 		else {
! 			long int ordinal = ymd_to_ord(*year, *month, 1) + *day - 1;
! 			ord_to_ymd(ordinal, year, month, day);
! 		}
! 	}
! 	assert(*month > 0);
! 	assert(*day > 0);
! 	if (*year < MINYEAR) {
! 		PyErr_SetString(PyExc_OverflowError, "date value out of range");
! 		return 0;
! 	}
! 	return 1;
  }
  
***************
*** 79,110 ****
  add_date_timedelta(PyDateTime_Date *date, PyDateTime_Delta *delta)
  {
!     PyObject *result;
!     /* delta + date */
!     if (GET_TD_SECONDS(delta) != 0
!         || GET_TD_MICROSECONDS(delta) != 0) {
!         /* Convert to datetime and pass it off. */
!         PyObject *dt = new_datetime(GET_YEAR(date), GET_MONTH(date),
!                                     GET_DAY(date), 0, 0, 0, 0);
!         if (dt == NULL)
!             return NULL;
!         result = datetime_add((PyObject *)delta, dt);
!         Py_DECREF(dt);
!     }
!     else if (GET_TD_DAYS(delta) != 0) {
!         /* There's actually something to do. */
!         long int year = GET_YEAR(date);
!         long int month = GET_MONTH(date);
!         long int day = GET_DAY(date) + GET_TD_DAYS(delta);
!         if (normalize_date(&year, &month, &day))
!             result = new_date(year, month, day);
!         else
!             result = NULL;
!     }
!     else {
!         /* The delta is timedelta(0), so return the original date. */
!         Py_INCREF(date);
!         result = (PyObject *) date;
!     }
!     return result;
  }
  
--- 79,110 ----
  add_date_timedelta(PyDateTime_Date *date, PyDateTime_Delta *delta)
  {
! 	PyObject *result;
! 	/* delta + date */
! 	if (GET_TD_SECONDS(delta) != 0
! 	    || GET_TD_MICROSECONDS(delta) != 0) {
! 		/* Convert to datetime and pass it off. */
! 		PyObject *dt = new_datetime(GET_YEAR(date), GET_MONTH(date),
! 					    GET_DAY(date), 0, 0, 0, 0);
! 		if (dt == NULL)
! 			return NULL;
! 		result = datetime_add((PyObject *)delta, dt);
! 		Py_DECREF(dt);
! 	}
! 	else if (GET_TD_DAYS(delta) != 0) {
! 		/* There's actually something to do. */
! 		long int year = GET_YEAR(date);
! 		long int month = GET_MONTH(date);
! 		long int day = GET_DAY(date) + GET_TD_DAYS(delta);
! 		if (normalize_date(&year, &month, &day))
! 			result = new_date(year, month, day);
! 		else
! 			result = NULL;
! 	}
! 	else {
! 		/* The delta is timedelta(0), so return the original date. */
! 		Py_INCREF(date);
! 		result = (PyObject *) date;
! 	}
! 	return result;
  }
  
***************
*** 112,138 ****
  date_add(PyObject *left, PyObject *right)
  {
!     PyTypeObject *left_type = left->ob_type;
!     PyTypeObject *right_type = right->ob_type;
  
!     if (PyType_IsSubtype(left_type, &PyDateTime_DateTimeType)
!         || PyType_IsSubtype(right_type, &PyDateTime_DateTimeType)) {
!         Py_INCREF(Py_NotImplemented);
!         return Py_NotImplemented;
!     }
!     if (PyType_IsSubtype(left_type, &PyDateTime_DateType)) {
!         /* date + ??? */
!         if (PyType_IsSubtype(right_type, &PyDateTime_DeltaType))
!             return add_date_timedelta((PyDateTime_Date *) left,
!                                       (PyDateTime_Delta *) right);
!     }
!     else {
!         /* 'right' must be one of us, or we wouldn't have been called */
!         if (PyType_IsSubtype(left_type, &PyDateTime_DeltaType))
!             return add_date_timedelta((PyDateTime_Date *) right,
!                                       (PyDateTime_Delta *) left);
!         /* else fall through; we don't support it here */
!     }
!     Py_INCREF(Py_NotImplemented);
!     return Py_NotImplemented;
  }
  
--- 112,138 ----
  date_add(PyObject *left, PyObject *right)
  {
! 	PyTypeObject *left_type = left->ob_type;
! 	PyTypeObject *right_type = right->ob_type;
  
! 	if (PyType_IsSubtype(left_type, &PyDateTime_DateTimeType)
! 	    || PyType_IsSubtype(right_type, &PyDateTime_DateTimeType)) {
! 		Py_INCREF(Py_NotImplemented);
! 		return Py_NotImplemented;
! 	}
! 	if (PyType_IsSubtype(left_type, &PyDateTime_DateType)) {
! 		/* date + ??? */
! 		if (PyType_IsSubtype(right_type, &PyDateTime_DeltaType))
! 			return add_date_timedelta((PyDateTime_Date *) left,
! 						  (PyDateTime_Delta *) right);
! 	}
! 	else {
! 		/* 'right' must be one of us, or we wouldn't have been called */
! 		if (PyType_IsSubtype(left_type, &PyDateTime_DeltaType))
! 			return add_date_timedelta((PyDateTime_Date *) right,
! 						  (PyDateTime_Delta *) left);
! 		/* else fall through; we don't support it here */
! 	}
! 	Py_INCREF(Py_NotImplemented);
! 	return Py_NotImplemented;
  }
  
***************
*** 140,150 ****
  date_compare(PyDateTime_Date *self, PyObject *other)
  {
!     if (!PyType_IsSubtype(other->ob_type, &PyDateTime_DateType)) {
!         PyErr_SetString(PyExc_TypeError,
!                         "can't compare date to %s instance");
!         return -1;
!     }
!     return memcmp(self->data, ((PyDateTime_Date *)other)->data,
!                   _PyDateTime_DATE_DATA_SIZE);
  }
  
--- 140,150 ----
  date_compare(PyDateTime_Date *self, PyObject *other)
  {
! 	if (!PyType_IsSubtype(other->ob_type, &PyDateTime_DateType)) {
! 		PyErr_SetString(PyExc_TypeError,
! 				"can't compare date to %s instance");
! 		return -1;
! 	}
! 	return memcmp(self->data, ((PyDateTime_Date *)other)->data,
! 		      _PyDateTime_DATE_DATA_SIZE);
  }
  
***************
*** 152,156 ****
  date_ctime(PyDateTime_Date *self)
  {
!     return format_ctime(self, 0, 0, 0);
  }
  
--- 152,156 ----
  date_ctime(PyDateTime_Date *self)
  {
! 	return format_ctime(self, 0, 0, 0);
  }
  
***************
*** 158,170 ****
  date_hash(PyDateTime_Date *self)
  {
!     if (self->hashcode == -1) {
!         PyObject *temp = Py_BuildValue("lll", GET_YEAR(self),
!                                        GET_MONTH(self), GET_DAY(self));
!         if (temp != NULL) {
!             self->hashcode = PyObject_Hash(temp);
!             Py_DECREF(temp);
!         }
!     }
!     return self->hashcode;
  }
  
--- 158,170 ----
  date_hash(PyDateTime_Date *self)
  {
! 	if (self->hashcode == -1) {
! 		PyObject *temp = Py_BuildValue("lll", GET_YEAR(self),
! 					       GET_MONTH(self), GET_DAY(self));
! 		if (temp != NULL) {
! 			self->hashcode = PyObject_Hash(temp);
! 			Py_DECREF(temp);
! 		}
! 	}
! 	return self->hashcode;
  }
  
***************
*** 172,199 ****
  date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
  {
!     PyObject *self = NULL;
!     long int year, month, day;
  
!     static char *keywords[] = {
!         "year", "month", "day", NULL
!     };
  
!     if (PyArg_ParseTupleAndKeywords(args, kw, "lll", keywords,
!                                     &year, &month, &day)) {
!         if (year < MINYEAR || year > MAXYEAR) {
!             PyErr_SetString(PyExc_ValueError, "year is out of range");
!             return NULL;
!         }
!         if (month < 1 || month > 12) {
!             PyErr_SetString(PyExc_ValueError, "month must be in 1..12");
!             return NULL;
!         }
!         if (day < 1 || day > days_in_month(year, month)) {
!             PyErr_SetString(PyExc_ValueError, "day is out of range for month");
!             return NULL;
!         }
!         self = new_date(year, month, day);
!     }
!     return self;
  }
  
--- 172,199 ----
  date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
  {
! 	PyObject *self = NULL;
! 	long int year, month, day;
  
! 	static char *keywords[] = {
! 		"year", "month", "day", NULL
! 	};
  
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "lll", keywords,
! 					&year, &month, &day)) {
! 		if (year < MINYEAR || year > MAXYEAR) {
! 			PyErr_SetString(PyExc_ValueError, "year is out of range");
! 			return NULL;
! 		}
! 		if (month < 1 || month > 12) {
! 			PyErr_SetString(PyExc_ValueError, "month must be in 1..12");
! 			return NULL;
! 		}
! 		if (day < 1 || day > days_in_month(year, month)) {
! 			PyErr_SetString(PyExc_ValueError, "day is out of range for month");
! 			return NULL;
! 		}
! 		self = new_date(year, month, day);
! 	}
! 	return self;
  }
  
***************
*** 201,205 ****
  date_year(PyDateTime_Date *self, void *unused)
  {
!     return (PyInt_FromLong(GET_YEAR(self)));
  }
  
--- 201,205 ----
  date_year(PyDateTime_Date *self, void *unused)
  {
! 	return (PyInt_FromLong(GET_YEAR(self)));
  }
  
***************
*** 207,211 ****
  date_month(PyDateTime_Date *self, void *unused)
  {
!     return (PyInt_FromLong(GET_MONTH(self)));
  }
  
--- 207,211 ----
  date_month(PyDateTime_Date *self, void *unused)
  {
! 	return (PyInt_FromLong(GET_MONTH(self)));
  }
  
***************
*** 213,224 ****
  date_day(PyDateTime_Date *self, void *unused)
  {
!     return (PyInt_FromLong(GET_DAY(self)));
  }
  
  static PyGetSetDef date_getset[] = {
!     {"year",        (getter)date_year},
!     {"month",       (getter)date_month},
!     {"day",         (getter)date_day},
!     {NULL}
  };
  
--- 213,224 ----
  date_day(PyDateTime_Date *self, void *unused)
  {
! 	return (PyInt_FromLong(GET_DAY(self)));
  }
  
  static PyGetSetDef date_getset[] = {
! 	{"year",        (getter)date_year},
! 	{"month",       (getter)date_month},
! 	{"day",         (getter)date_day},
! 	{NULL}
  };
  
***************
*** 226,247 ****
  date_isocalendar(PyDateTime_Date *self)
  {
!     int  year         = GET_YEAR(self);
!     int  week1_monday = iso_week1_monday(year);
!     long today        = ymd_to_ord(year, GET_MONTH(self), GET_DAY(self));
!     int  week         = (today - week1_monday) / 7;
!     int  day          = (today - week1_monday) % 7;
  
!     if (week < 0) {
!         --year;
!         week1_monday = iso_week1_monday(year);
!         week         = (today - week1_monday) / 7;
!         day          = (today - week1_monday) % 7;
!     }
!     else if (week >= 52 &&
!              today >= iso_week1_monday(year + 1)) {
!         ++year;
!         week = 0;
!     }
!     return Py_BuildValue("iii", year, week + 1, day + 1);
  }
  
--- 226,247 ----
  date_isocalendar(PyDateTime_Date *self)
  {
! 	int  year         = GET_YEAR(self);
! 	int  week1_monday = iso_week1_monday(year);
! 	long today        = ymd_to_ord(year, GET_MONTH(self), GET_DAY(self));
! 	int  week         = (today - week1_monday) / 7;
! 	int  day          = (today - week1_monday) % 7;
  
! 	if (week < 0) {
! 		--year;
! 		week1_monday = iso_week1_monday(year);
! 		week         = (today - week1_monday) / 7;
! 		day          = (today - week1_monday) % 7;
! 	}
! 	else if (week >= 52 &&
! 		 today >= iso_week1_monday(year + 1)) {
! 		++year;
! 		week = 0;
! 	}
! 	return Py_BuildValue("iii", year, week + 1, day + 1);
  }
  
***************
*** 249,257 ****
  date_isoformat(PyDateTime_Date *self, PyObject *args, PyObject *kw)
  {
!     char buffer[128];
  
!     isoformat_date(self, buffer, sizeof(buffer));
  
!     return PyString_FromString(buffer);
  }
  
--- 249,257 ----
  date_isoformat(PyDateTime_Date *self, PyObject *args, PyObject *kw)
  {
! 	char buffer[128];
  
! 	isoformat_date(self, buffer, sizeof(buffer));
  
! 	return PyString_FromString(buffer);
  }
  
***************
*** 259,265 ****
  date_isoweekday(PyDateTime_Date *self)
  {
!     int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
  
!     return PyInt_FromLong(dow + 1);
  }
  
--- 259,265 ----
  date_isoweekday(PyDateTime_Date *self)
  {
! 	int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
  
! 	return PyInt_FromLong(dow + 1);
  }
  
***************
*** 267,273 ****
  date_nonzero(PyDateTime_Date *self)
  {
!     return (GET_YEAR(self) != 0
!             || GET_MONTH(self) != 0
!             || GET_DAY(self) != 0);
  }
  
--- 267,273 ----
  date_nonzero(PyDateTime_Date *self)
  {
! 	return (GET_YEAR(self) != 0
! 		|| GET_MONTH(self) != 0
! 		|| GET_DAY(self) != 0);
  }
  
***************
*** 275,287 ****
  date_repr(PyDateTime_Date *self)
  {
!     char buffer[1028];
!     char *typename;
  
!     typename = self->ob_type->tp_name;
!     PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d, %d)",
!                   typename,
!                   GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
  
!     return PyString_FromString(buffer);
  }
  
--- 275,287 ----
  date_repr(PyDateTime_Date *self)
  {
! 	char buffer[1028];
! 	char *typename;
  
! 	typename = self->ob_type->tp_name;
! 	PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d, %d)",
! 		      typename,
! 		      GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
  
! 	return PyString_FromString(buffer);
  }
  
***************
*** 289,297 ****
  date_str(PyDateTime_Date *self)
  {
!     char buffer[128];
  
!     isoformat_date(self, buffer, sizeof(buffer));
  
!     return PyString_FromString(buffer);
  }
  
--- 289,297 ----
  date_str(PyDateTime_Date *self)
  {
! 	char buffer[128];
  
! 	isoformat_date(self, buffer, sizeof(buffer));
  
! 	return PyString_FromString(buffer);
  }
  
***************
*** 299,354 ****
  date_subtract(PyObject *left, PyObject *right)
  {
!     PyTypeObject *left_type = left->ob_type;
!     PyTypeObject *right_type = right->ob_type;
  
!     if (PyType_IsSubtype(left_type, &PyDateTime_DateTimeType)
!         || PyType_IsSubtype(right_type, &PyDateTime_DateTimeType)) {
!         Py_INCREF(Py_NotImplemented);
!         return Py_NotImplemented;
!     }
!     if (PyType_IsSubtype(left_type, &PyDateTime_DateType)) {
!         if (PyType_IsSubtype(right_type, &PyDateTime_DateType)) {
!             /* date - date */
!             long int left_ord = ymd_to_ord(GET_YEAR(left), GET_MONTH(left),
!                                            GET_DAY(left));
!             long int right_ord = ymd_to_ord(GET_YEAR(right), GET_MONTH(right),
!                                             GET_DAY(right));
!             return new_delta(left_ord - right_ord, 0, 0);
!         }
!         if (PyType_IsSubtype(right_type, &PyDateTime_DeltaType)) {
!             PyObject *result = NULL;
!             if (GET_TD_SECONDS(right) != 0
!                 || GET_TD_MICROSECONDS(right) != 0) {
!                 /* need to convert to datetime + delta */
!                 PyObject *dt = new_datetime(GET_YEAR(left), GET_MONTH(left),
!                                             GET_DAY(left), 0, 0, 0, 0);
!                 if (dt != NULL) {
!                     result = datetime_subtract(dt, right);
!                     Py_DECREF(dt);
!                 }
!             }
!             else if (GET_TD_DAYS(right) == 0) {
!                 /* date - timedelta(0) */
!                 Py_INCREF(left);
!                 result = left;
!             }
!             else {
!                 long int year, month, day;
!                 long int ord = ymd_to_ord(GET_YEAR(left), GET_MONTH(left),
!                                           GET_DAY(left));
!                 ord -= GET_TD_DAYS(right);
!                 if (ord < 1)
!                     PyErr_SetString(PyExc_OverflowError,
!                                     "resulting value out of range");
!                 else {
!                     ord_to_ymd(ord, &year, &month, &day);
!                     result = new_date(year, month, day);
!                 }
!             }
!             return result;
!         }
!     }
!     Py_INCREF(Py_NotImplemented);
!     return Py_NotImplemented;
  }
  
--- 299,354 ----
  date_subtract(PyObject *left, PyObject *right)
  {
! 	PyTypeObject *left_type = left->ob_type;
! 	PyTypeObject *right_type = right->ob_type;
  
! 	if (PyType_IsSubtype(left_type, &PyDateTime_DateTimeType)
! 	    || PyType_IsSubtype(right_type, &PyDateTime_DateTimeType)) {
! 		Py_INCREF(Py_NotImplemented);
! 		return Py_NotImplemented;
! 	}
! 	if (PyType_IsSubtype(left_type, &PyDateTime_DateType)) {
! 		if (PyType_IsSubtype(right_type, &PyDateTime_DateType)) {
! 			/* date - date */
! 			long int left_ord = ymd_to_ord(GET_YEAR(left), GET_MONTH(left),
! 						       GET_DAY(left));
! 			long int right_ord = ymd_to_ord(GET_YEAR(right), GET_MONTH(right),
! 							GET_DAY(right));
! 			return new_delta(left_ord - right_ord, 0, 0);
! 		}
! 		if (PyType_IsSubtype(right_type, &PyDateTime_DeltaType)) {
! 			PyObject *result = NULL;
! 			if (GET_TD_SECONDS(right) != 0
! 			    || GET_TD_MICROSECONDS(right) != 0) {
! 				/* need to convert to datetime + delta */
! 				PyObject *dt = new_datetime(GET_YEAR(left), GET_MONTH(left),
! 							    GET_DAY(left), 0, 0, 0, 0);
! 				if (dt != NULL) {
! 					result = datetime_subtract(dt, right);
! 					Py_DECREF(dt);
! 				}
! 			}
! 			else if (GET_TD_DAYS(right) == 0) {
! 				/* date - timedelta(0) */
! 				Py_INCREF(left);
! 				result = left;
! 			}
! 			else {
! 				long int year, month, day;
! 				long int ord = ymd_to_ord(GET_YEAR(left), GET_MONTH(left),
! 							  GET_DAY(left));
! 				ord -= GET_TD_DAYS(right);
! 				if (ord < 1)
! 					PyErr_SetString(PyExc_OverflowError,
! 							"resulting value out of range");
! 				else {
! 					ord_to_ymd(ord, &year, &month, &day);
! 					result = new_date(year, month, day);
! 				}
! 			}
! 			return result;
! 		}
! 	}
! 	Py_INCREF(Py_NotImplemented);
! 	return Py_NotImplemented;
  }
  
***************
*** 356,375 ****
  date_today(PyObject *self, PyObject *cls)
  {
!     /* XXX need to create the instance by calling cls(y,mon,d,h,min,s,u) */
!     struct timeval t;
!     struct tm *tm;
!     time_t timet;
  
  #ifdef GETTIMEOFDAY_NO_TZ
!     gettimeofday(&t);
  #else /* !GETTIMEOFDAY_NO_TZ */
!     gettimeofday(&t, (struct timezone *)NULL);
  #endif /* !GETTIMEOFDAY_NO_TZ */
!     timet = t.tv_sec;
!     tm = localtime(&timet);
  
!     return PyObject_CallFunction(cls, "iii",
!                                  tm->tm_year + 1900, tm->tm_mon + 1,
!                                  tm->tm_mday);
  }
  
--- 356,375 ----
  date_today(PyObject *self, PyObject *cls)
  {
! 	/* XXX need to create the instance by calling cls(y,mon,d,h,min,s,u) */
! 	struct timeval t;
! 	struct tm *tm;
! 	time_t timet;
  
  #ifdef GETTIMEOFDAY_NO_TZ
! 	gettimeofday(&t);
  #else /* !GETTIMEOFDAY_NO_TZ */
! 	gettimeofday(&t, (struct timezone *)NULL);
  #endif /* !GETTIMEOFDAY_NO_TZ */
! 	timet = t.tv_sec;
! 	tm = localtime(&timet);
  
! 	return PyObject_CallFunction(cls, "iii",
! 				     tm->tm_year + 1900, tm->tm_mon + 1,
! 				     tm->tm_mday);
  }
  
***************
*** 377,382 ****
  date_toordinal(PyDateTime_Date *self)
  {
!     return PyInt_FromLong(ymd_to_ord(GET_YEAR(self), GET_MONTH(self),
!                                      GET_DAY(self)));
  }
  
--- 377,382 ----
  date_toordinal(PyDateTime_Date *self)
  {
! 	return PyInt_FromLong(ymd_to_ord(GET_YEAR(self), GET_MONTH(self),
! 					 GET_DAY(self)));
  }
  
***************
*** 384,417 ****
  date_weekday(PyDateTime_Date *self)
  {
!     int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
  
!     return PyInt_FromLong(dow);
  }
  
  static PyMethodDef date_methods[] = {
!     /* Class methods: */
!     {"today",         (PyCFunction)date_today,       METH_O | METH_CLASS,
!      "Return a new date that represents the current date."},
  
!     /* Instance methods: */
!     {"ctime",       (PyCFunction)date_ctime,         METH_NOARGS,
!      "Return ctime() style string."},
!     {"isocalendar", (PyCFunction)date_isocalendar,   METH_NOARGS,
!      "Return a 3-tuple containing ISO year, week number, and weekday.\n\n"
!      "The first ISO week of the year is the (Mon-Sun) week containing the\n"
!      "year's first Thursday; everything rest derives from that."},
!     {"isoformat",   (PyCFunction)date_isoformat,     METH_KEYWORDS,
!      "Return the day of the week represented by the date.\n"
!      "Monday == 1 ... Sunday == 7"},
!     {"isoweekday",  (PyCFunction)date_isoweekday,    METH_NOARGS,
!      "Return the day of the week represented by the date.\n"
!      "Monday == 1 ... Sunday == 7"},
!     {"toordinal",   (PyCFunction)date_toordinal,     METH_NOARGS,
!      "Return proleptic Gregorian ordinal for the year, month and day.\n"
!      "January 1 of year 1 is day 1."},
!     {"weekday",     (PyCFunction)date_weekday,       METH_NOARGS,
!      "Return the day of the week represented by the date.\n"
!      "Monday == 0 ... Sunday == 6"},
!     {NULL}
  };
  
--- 384,417 ----
  date_weekday(PyDateTime_Date *self)
  {
! 	int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
  
! 	return PyInt_FromLong(dow);
  }
  
  static PyMethodDef date_methods[] = {
! 	/* Class methods: */
! 	{"today",         (PyCFunction)date_today,       METH_O | METH_CLASS,
! 	 "Return a new date that represents the current date."},
  
! 	/* Instance methods: */
! 	{"ctime",       (PyCFunction)date_ctime,         METH_NOARGS,
! 	 "Return ctime() style string."},
! 	{"isocalendar", (PyCFunction)date_isocalendar,   METH_NOARGS,
! 	 "Return a 3-tuple containing ISO year, week number, and weekday.\n\n"
! 	 "The first ISO week of the year is the (Mon-Sun) week containing the\n"
! 	 "year's first Thursday; everything rest derives from that."},
! 	{"isoformat",   (PyCFunction)date_isoformat,     METH_KEYWORDS,
! 	 "Return the day of the week represented by the date.\n"
! 	 "Monday == 1 ... Sunday == 7"},
! 	{"isoweekday",  (PyCFunction)date_isoweekday,    METH_NOARGS,
! 	 "Return the day of the week represented by the date.\n"
! 	 "Monday == 1 ... Sunday == 7"},
! 	{"toordinal",   (PyCFunction)date_toordinal,     METH_NOARGS,
! 	 "Return proleptic Gregorian ordinal for the year, month and day.\n"
! 	 "January 1 of year 1 is day 1."},
! 	{"weekday",     (PyCFunction)date_weekday,       METH_NOARGS,
! 	 "Return the day of the week represented by the date.\n"
! 	 "Monday == 0 ... Sunday == 6"},
! 	{NULL}
  };
  
***************
*** 420,477 ****
  
  static PyNumberMethods date_as_number = {
!     date_add,					/* nb_add */
!     date_subtract,				/* nb_subtract */
!     0,						/* nb_multiply */
!     0,						/* nb_divide */
!     0,						/* nb_remainder */
!     0,						/* nb_divmod */
!     0,						/* nb_power */
!     0,						/* nb_negative */
!     0,						/* nb_positive */
!     0,						/* nb_absolute */
!     (inquiry)date_nonzero,			/* nb_nonzero */
  };
  
  static PyTypeObject PyDateTime_DateType = {
!     PyObject_HEAD_INIT(NULL)
!     0,						/* ob_size */
!     "date",					/* tp_name */
!     sizeof(PyDateTime_Date),			/* tp_basicsize */
!     0,						/* tp_itemsize */
!     (destructor)PyObject_Del,			/* tp_dealloc */
!     0,						/* tp_print */
!     0,						/* tp_getattr */
!     0,						/* tp_setattr */
!     (cmpfunc)date_compare,			/* tp_compare */
!     (reprfunc)date_repr,			/* tp_repr */
!     &date_as_number,				/* tp_as_number */
!     0,						/* tp_as_sequence */
!     0,						/* tp_as_mapping */
!     (hashfunc)date_hash,			/* tp_hash */
!     0,              				/* tp_call */
!     (reprfunc)date_str,				/* tp_str */
!     PyObject_GenericGetAttr,			/* tp_getattro */
!     0,						/* tp_setattro */
!     0,						/* tp_as_buffer */
!     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
          Py_TPFLAGS_BASETYPE,			/* tp_flags */
!     date_doc,					/* tp_doc */
!     0,						/* tp_traverse */
!     0,						/* tp_clear */
!     0,						/* tp_richcompare */
!     0,						/* tp_weaklistoffset */
!     0,						/* tp_iter */
!     0,						/* tp_iternext */
!     date_methods,				/* tp_methods */
!     0,						/* tp_members */
!     date_getset,				/* tp_getset */
!     0,						/* tp_base */
!     0,						/* tp_dict */
!     0,						/* tp_descr_get */
!     0,						/* tp_descr_set */
!     0,						/* tp_dictoffset */
!     0,						/* tp_init */
!     0,						/* tp_alloc */
!     date_new,					/* tp_new */
!     _PyObject_Del,				/* tp_free */
  };
--- 420,477 ----
  
  static PyNumberMethods date_as_number = {
! 	date_add,					/* nb_add */
! 	date_subtract,				/* nb_subtract */
! 	0,						/* nb_multiply */
! 	0,						/* nb_divide */
! 	0,						/* nb_remainder */
! 	0,						/* nb_divmod */
! 	0,						/* nb_power */
! 	0,						/* nb_negative */
! 	0,						/* nb_positive */
! 	0,						/* nb_absolute */
! 	(inquiry)date_nonzero,			/* nb_nonzero */
  };
  
  static PyTypeObject PyDateTime_DateType = {
! 	PyObject_HEAD_INIT(NULL)
! 	0,						/* ob_size */
! 	"date",					/* tp_name */
! 	sizeof(PyDateTime_Date),			/* tp_basicsize */
! 	0,						/* tp_itemsize */
! 	(destructor)PyObject_Del,			/* tp_dealloc */
! 	0,						/* tp_print */
! 	0,						/* tp_getattr */
! 	0,						/* tp_setattr */
! 	(cmpfunc)date_compare,			/* tp_compare */
! 	(reprfunc)date_repr,			/* tp_repr */
! 	&date_as_number,				/* tp_as_number */
! 	0,						/* tp_as_sequence */
! 	0,						/* tp_as_mapping */
! 	(hashfunc)date_hash,			/* tp_hash */
! 	0,              				/* tp_call */
! 	(reprfunc)date_str,				/* tp_str */
! 	PyObject_GenericGetAttr,			/* tp_getattro */
! 	0,						/* tp_setattro */
! 	0,						/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
          Py_TPFLAGS_BASETYPE,			/* tp_flags */
! 	date_doc,					/* tp_doc */
! 	0,						/* tp_traverse */
! 	0,						/* tp_clear */
! 	0,						/* tp_richcompare */
! 	0,						/* tp_weaklistoffset */
! 	0,						/* tp_iter */
! 	0,						/* tp_iternext */
! 	date_methods,				/* tp_methods */
! 	0,						/* tp_members */
! 	date_getset,				/* tp_getset */
! 	0,						/* tp_base */
! 	0,						/* tp_dict */
! 	0,						/* tp_descr_get */
! 	0,						/* tp_descr_set */
! 	0,						/* tp_dictoffset */
! 	0,						/* tp_init */
! 	0,						/* tp_alloc */
! 	date_new,					/* tp_new */
! 	_PyObject_Del,				/* tp_free */
  };

Index: obj_datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetime.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** obj_datetime.c	20 Aug 2002 18:53:07 -0000	1.1
--- obj_datetime.c	21 Nov 2002 18:02:01 -0000	1.2
***************
*** 7,20 ****
  normalize_pair(long int *parent, long int *child, int size)
  {
!     if (*child < 0) {
!         long int borrow = (*child / size) + 1;
!         *parent -= borrow;
!         *child += (borrow * size);
!     }
!     else if (*child >= size) {
!         long int carry = *child / size;
!         *parent += carry;
!         *child -= (carry * size);
!     }
  }
  
--- 7,20 ----
  normalize_pair(long int *parent, long int *child, int size)
  {
! 	if (*child < 0) {
! 		long int borrow = (*child / size) + 1;
! 		*parent -= borrow;
! 		*child += (borrow * size);
! 	}
! 	else if (*child >= size) {
! 		long int carry = *child / size;
! 		*parent += carry;
! 		*child -= (carry * size);
! 	}
  }
  
***************
*** 24,33 ****
                     long int *microsecond)
  {
!     normalize_pair(second, microsecond, 1000000);
!     normalize_pair(minute, second, 60);
!     normalize_pair(hour, minute, 60);
!     normalize_pair(day, hour, 24);
  
!     return normalize_date(year, month, day);
  }
  
--- 24,33 ----
                     long int *microsecond)
  {
! 	normalize_pair(second, microsecond, 1000000);
! 	normalize_pair(minute, second, 60);
! 	normalize_pair(hour, minute, 60);
! 	normalize_pair(day, hour, 24);
  
! 	return normalize_date(year, month, day);
  }
  
***************
*** 35,52 ****
  add_datetime_timedelta(PyDateTime_DateTime *date, PyDateTime_Delta *delta)
  {
!     long int year = GET_YEAR(date);
!     long int month = GET_MONTH(date);
!     long int day = GET_DAY(date) + GET_TD_DAYS(delta);
!     long int hour = GET_HOUR(date);
!     long int minute = GET_MINUTE(date);
!     long int second = GET_SECOND(date) + GET_TD_SECONDS(delta);
!     long int microsecond = GET_MICROSECOND(date) + GET_TD_MICROSECONDS(delta);
  
!     if (normalize_datetime(&year, &month, &day,
!                            &hour, &minute, &second, &microsecond))
!         return new_datetime(year, month, day,
!                             hour, minute, second, microsecond);
!     else
!         return NULL;
  }
  
--- 35,52 ----
  add_datetime_timedelta(PyDateTime_DateTime *date, PyDateTime_Delta *delta)
  {
! 	long int year = GET_YEAR(date);
! 	long int month = GET_MONTH(date);
! 	long int day = GET_DAY(date) + GET_TD_DAYS(delta);
! 	long int hour = GET_HOUR(date);
! 	long int minute = GET_MINUTE(date);
! 	long int second = GET_SECOND(date) + GET_TD_SECONDS(delta);
! 	long int microsecond = GET_MICROSECOND(date) + GET_TD_MICROSECONDS(delta);
  
! 	if (normalize_datetime(&year, &month, &day,
! 			       &hour, &minute, &second, &microsecond))
! 		return new_datetime(year, month, day,
! 				    hour, minute, second, microsecond);
! 	else
! 		return NULL;
  }
  
***************
*** 54,73 ****
  datetime_add(PyObject *left, PyObject *right)
  {
!     PyTypeObject *left_type = left->ob_type;
!     PyTypeObject *right_type = right->ob_type;
  
!     if (PyType_IsSubtype(left_type, &PyDateTime_DateTimeType)) {
!         /* datetime + ??? */
!         if (PyType_IsSubtype(right_type, &PyDateTime_DeltaType))
!             return add_datetime_timedelta((PyDateTime_DateTime *) left,
!                                           (PyDateTime_Delta *) right);
!     }
!     else if (PyType_IsSubtype(left_type, &PyDateTime_DeltaType)) {
!         /* delta + datetime */
!         return add_datetime_timedelta((PyDateTime_DateTime *) right,
!                                       (PyDateTime_Delta *) left);
!     }
!     Py_INCREF(Py_NotImplemented);
!     return Py_NotImplemented;
  }
  
--- 54,73 ----
  datetime_add(PyObject *left, PyObject *right)
  {
! 	PyTypeObject *left_type = left->ob_type;
! 	PyTypeObject *right_type = right->ob_type;
  
! 	if (PyType_IsSubtype(left_type, &PyDateTime_DateTimeType)) {
! 		/* datetime + ??? */
! 		if (PyType_IsSubtype(right_type, &PyDateTime_DeltaType))
! 			return add_datetime_timedelta((PyDateTime_DateTime *) left,
! 						      (PyDateTime_Delta *) right);
! 	}
! 	else if (PyType_IsSubtype(left_type, &PyDateTime_DeltaType)) {
! 		/* delta + datetime */
! 		return add_datetime_timedelta((PyDateTime_DateTime *) right,
! 					      (PyDateTime_Delta *) left);
! 	}
! 	Py_INCREF(Py_NotImplemented);
! 	return Py_NotImplemented;
  }
  
***************
*** 75,85 ****
  datetime_compare(PyDateTime_DateTime *self, PyObject *other)
  {
!     if (!PyType_IsSubtype(other->ob_type, &PyDateTime_DateTimeType)) {
!         PyErr_SetString(PyExc_TypeError,
!                         "can't compare date to %s instance");
!         return -1;
!     }
!     return memcmp(self->data, ((PyDateTime_DateTime *)other)->data,
!                   _PyDateTime_DATETIME_DATA_SIZE);
  }
  
--- 75,85 ----
  datetime_compare(PyDateTime_DateTime *self, PyObject *other)
  {
! 	if (!PyType_IsSubtype(other->ob_type, &PyDateTime_DateTimeType)) {
! 		PyErr_SetString(PyExc_TypeError,
! 				"can't compare date to %s instance");
! 		return -1;
! 	}
! 	return memcmp(self->data, ((PyDateTime_DateTime *)other)->data,
! 		      _PyDateTime_DATETIME_DATA_SIZE);
  }
  
***************
*** 87,92 ****
  datetime_ctime(PyDateTime_DateTime *self)
  {
!     return format_ctime((PyDateTime_Date *)self,
!                         GET_HOUR(self), GET_MINUTE(self), GET_SECOND(self));
  }
  
--- 87,92 ----
  datetime_ctime(PyDateTime_DateTime *self)
  {
! 	return format_ctime((PyDateTime_Date *)self,
! 			    GET_HOUR(self), GET_MINUTE(self), GET_SECOND(self));
  }
  
***************
*** 94,126 ****
  datetime_hash(PyDateTime_DateTime *self)
  {
!     if (self->hashcode == -1) {
!         PyObject *temp;
!         if (GET_MICROSECOND(self) != 0)
!             temp = Py_BuildValue("lllllll", GET_YEAR(self),
!                                  GET_MONTH(self), GET_DAY(self),
!                                  GET_HOUR(self), GET_MINUTE(self),
!                                  GET_SECOND(self), GET_MICROSECOND(self));
!         else if (GET_SECOND(self) != 0)
!             temp = Py_BuildValue("llllll", GET_YEAR(self),
!                                  GET_MONTH(self), GET_DAY(self),
!                                  GET_HOUR(self), GET_MINUTE(self),
!                                  GET_SECOND(self));
!         else if (GET_MINUTE(self) != 0)
!             temp = Py_BuildValue("lllll", GET_YEAR(self),
!                                  GET_MONTH(self), GET_DAY(self),
!                                  GET_HOUR(self), GET_MINUTE(self));
!         else if (GET_HOUR(self) != 0)
!             temp = Py_BuildValue("llll", GET_YEAR(self),
!                                  GET_MONTH(self), GET_DAY(self),
!                                  GET_HOUR(self));
!         else
!             temp = Py_BuildValue("lll", GET_YEAR(self),
!                                  GET_MONTH(self), GET_DAY(self));
!         if (temp != NULL) {
!             self->hashcode = PyObject_Hash(temp);
!             Py_DECREF(temp);
!         }
!     }
!     return self->hashcode;
  }
  
--- 94,126 ----
  datetime_hash(PyDateTime_DateTime *self)
  {
! 	if (self->hashcode == -1) {
! 		PyObject *temp;
! 		if (GET_MICROSECOND(self) != 0)
! 			temp = Py_BuildValue("lllllll", GET_YEAR(self),
! 					     GET_MONTH(self), GET_DAY(self),
! 					     GET_HOUR(self), GET_MINUTE(self),
! 					     GET_SECOND(self), GET_MICROSECOND(self));
! 		else if (GET_SECOND(self) != 0)
! 			temp = Py_BuildValue("llllll", GET_YEAR(self),
! 					     GET_MONTH(self), GET_DAY(self),
! 					     GET_HOUR(self), GET_MINUTE(self),
! 					     GET_SECOND(self));
! 		else if (GET_MINUTE(self) != 0)
! 			temp = Py_BuildValue("lllll", GET_YEAR(self),
! 					     GET_MONTH(self), GET_DAY(self),
! 					     GET_HOUR(self), GET_MINUTE(self));
! 		else if (GET_HOUR(self) != 0)
! 			temp = Py_BuildValue("llll", GET_YEAR(self),
! 					     GET_MONTH(self), GET_DAY(self),
! 					     GET_HOUR(self));
! 		else
! 			temp = Py_BuildValue("lll", GET_YEAR(self),
! 					     GET_MONTH(self), GET_DAY(self));
! 		if (temp != NULL) {
! 			self->hashcode = PyObject_Hash(temp);
! 			Py_DECREF(temp);
! 		}
! 	}
! 	return self->hashcode;
  }
  
***************
*** 128,173 ****
  datetime_new(PyTypeObject *type, PyObject *args, PyObject *kw)
  {
!     PyObject *self = NULL;
!     long int year, month, day, hour = 0, minute = 0, second = 0, usecond = 0;
  
!     static char *keywords[] = {
!         "year", "month", "day", "hour", "minute", "second", "microsecond", NULL
!     };
  
!     if (PyArg_ParseTupleAndKeywords(args, kw, "lll|llll", keywords,
!                                     &year, &month, &day, &hour, &minute,
!                                     &second, &usecond)) {
!         if (year < MINYEAR || year > MAXYEAR) {
!             PyErr_SetString(PyExc_ValueError, "year is out of range");
!             return NULL;
!         }
!         if (month < 1 || month > 12) {
!             PyErr_SetString(PyExc_ValueError, "month must be in 1..12");
!             return NULL;
!         }
!         if (day < 1 || day > days_in_month(year, month)) {
!             PyErr_SetString(PyExc_ValueError, "day is out of range for month");
!             return NULL;
!         }
!         if (hour < 0 || hour > 23) {
!             PyErr_SetString(PyExc_ValueError, "hour must be in 0..23");
!             return NULL;
!         }
!         if (minute < 0 || minute > 59) {
!             PyErr_SetString(PyExc_ValueError, "minute must be in 0..59");
!             return NULL;
!         }
!         if (second < 0 || second > 59) {
!             PyErr_SetString(PyExc_ValueError, "second must be in 0..59");
!             return NULL;
!         }
!         if (usecond < 0 || usecond > 999999) {
!             PyErr_SetString(PyExc_ValueError,
!                             "microsecond must be in 0..999999");
!             return NULL;
!         }
!         self = new_datetime(year, month, day, hour, minute, second, usecond);
!     }
!     return self;
  }
  
--- 128,173 ----
  datetime_new(PyTypeObject *type, PyObject *args, PyObject *kw)
  {
! 	PyObject *self = NULL;
! 	long int year, month, day, hour = 0, minute = 0, second = 0, usecond = 0;
  
! 	static char *keywords[] = {
! 		"year", "month", "day", "hour", "minute", "second", "microsecond", NULL
! 	};
  
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "lll|llll", keywords,
! 					&year, &month, &day, &hour, &minute,
! 					&second, &usecond)) {
! 		if (year < MINYEAR || year > MAXYEAR) {
! 			PyErr_SetString(PyExc_ValueError, "year is out of range");
! 			return NULL;
! 		}
! 		if (month < 1 || month > 12) {
! 			PyErr_SetString(PyExc_ValueError, "month must be in 1..12");
! 			return NULL;
! 		}
! 		if (day < 1 || day > days_in_month(year, month)) {
! 			PyErr_SetString(PyExc_ValueError, "day is out of range for month");
! 			return NULL;
! 		}
! 		if (hour < 0 || hour > 23) {
! 			PyErr_SetString(PyExc_ValueError, "hour must be in 0..23");
! 			return NULL;
! 		}
! 		if (minute < 0 || minute > 59) {
! 			PyErr_SetString(PyExc_ValueError, "minute must be in 0..59");
! 			return NULL;
! 		}
! 		if (second < 0 || second > 59) {
! 			PyErr_SetString(PyExc_ValueError, "second must be in 0..59");
! 			return NULL;
! 		}
! 		if (usecond < 0 || usecond > 999999) {
! 			PyErr_SetString(PyExc_ValueError,
! 					"microsecond must be in 0..999999");
! 			return NULL;
! 		}
! 		self = new_datetime(year, month, day, hour, minute, second, usecond);
! 	}
! 	return self;
  }
  
***************
*** 175,202 ****
  datetime_repr(PyDateTime_DateTime *self)
  {
!     char buffer[1028];
!     char *typename;
  
!     typename = self->ob_type->tp_name;
!     if (GET_MICROSECOND(self)) {
!         PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d, %d, %d, %d, %d, %d)",
!                       typename,
!                       GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
!                       GET_HOUR(self), GET_MINUTE(self), GET_SECOND(self),
!                       GET_MICROSECOND(self));
!     }
!     else if (GET_SECOND(self)) {
!         PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d, %d, %d, %d, %d)",
!                       typename,
!                       GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
!                       GET_HOUR(self), GET_MINUTE(self), GET_SECOND(self));
!     }
!     else {
!         PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d, %d, %d, %d)",
!                       typename,
!                       GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
!                       GET_HOUR(self), GET_MINUTE(self));
!     }
!     return PyString_FromString(buffer);
  }
  
--- 175,202 ----
  datetime_repr(PyDateTime_DateTime *self)
  {
! 	char buffer[1028];
! 	char *typename;
  
! 	typename = self->ob_type->tp_name;
! 	if (GET_MICROSECOND(self)) {
! 		PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d, %d, %d, %d, %d, %d)",
! 			      typename,
! 			      GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
! 			      GET_HOUR(self), GET_MINUTE(self), GET_SECOND(self),
! 			      GET_MICROSECOND(self));
! 	}
! 	else if (GET_SECOND(self)) {
! 		PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d, %d, %d, %d, %d)",
! 			      typename,
! 			      GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
! 			      GET_HOUR(self), GET_MINUTE(self), GET_SECOND(self));
! 	}
! 	else {
! 		PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d, %d, %d, %d)",
! 			      typename,
! 			      GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
! 			      GET_HOUR(self), GET_MINUTE(self));
! 	}
! 	return PyString_FromString(buffer);
  }
  
***************
*** 204,215 ****
  datetime_str(PyDateTime_DateTime *self)
  {
!     char buffer[128];
!     char *cp;
  
!     cp = isoformat_date((PyDateTime_Date *)self, buffer, sizeof(buffer));
!     *cp++ = ' ';
!     isoformat_time(self, cp, sizeof(buffer) - (cp - buffer));
  
!     return PyString_FromString(buffer);
  }
  
--- 204,215 ----
  datetime_str(PyDateTime_DateTime *self)
  {
! 	char buffer[128];
! 	char *cp;
  
! 	cp = isoformat_date((PyDateTime_Date *)self, buffer, sizeof(buffer));
! 	*cp++ = ' ';
! 	isoformat_time(self, cp, sizeof(buffer) - (cp - buffer));
  
! 	return PyString_FromString(buffer);
  }
  
***************
*** 217,222 ****
  datetime_subtract(PyObject *left, PyObject *right)
  {
!     Py_INCREF(Py_NotImplemented);
!     return Py_NotImplemented;
  }
  
--- 217,222 ----
  datetime_subtract(PyObject *left, PyObject *right)
  {
! 	Py_INCREF(Py_NotImplemented);
! 	return Py_NotImplemented;
  }
  
***************
*** 225,229 ****
  datetime_hour(PyDateTime_DateTime *self, void *unused)
  {
!     return (PyInt_FromLong(GET_HOUR(self)));
  }
  
--- 225,229 ----
  datetime_hour(PyDateTime_DateTime *self, void *unused)
  {
! 	return (PyInt_FromLong(GET_HOUR(self)));
  }
  
***************
*** 231,235 ****
  datetime_minute(PyDateTime_DateTime *self, void *unused)
  {
!     return (PyInt_FromLong(GET_MINUTE(self)));
  }
  
--- 231,235 ----
  datetime_minute(PyDateTime_DateTime *self, void *unused)
  {
! 	return (PyInt_FromLong(GET_MINUTE(self)));
  }
  
***************
*** 237,241 ****
  datetime_second(PyDateTime_DateTime *self, void *unused)
  {
!     return (PyInt_FromLong(GET_SECOND(self)));
  }
  
--- 237,241 ----
  datetime_second(PyDateTime_DateTime *self, void *unused)
  {
! 	return (PyInt_FromLong(GET_SECOND(self)));
  }
  
***************
*** 243,255 ****
  datetime_microsecond(PyDateTime_DateTime *self, void *unused)
  {
!     return (PyInt_FromLong(GET_MICROSECOND(self)));
  }
  
  static PyGetSetDef datetime_getset[] = {
!     {"hour",        (getter)datetime_hour},
!     {"minute",      (getter)datetime_minute},
!     {"second",      (getter)datetime_second},
!     {"microsecond", (getter)datetime_microsecond},
!     {NULL}
  };
  
--- 243,255 ----
  datetime_microsecond(PyDateTime_DateTime *self, void *unused)
  {
! 	return (PyInt_FromLong(GET_MICROSECOND(self)));
  }
  
  static PyGetSetDef datetime_getset[] = {
! 	{"hour",        (getter)datetime_hour},
! 	{"minute",      (getter)datetime_minute},
! 	{"second",      (getter)datetime_second},
! 	{"microsecond", (getter)datetime_microsecond},
! 	{NULL}
  };
  
***************
*** 258,276 ****
                     PyObject *args, PyObject *kw)
  {
!     char buffer[128];
!     char sep = 'T';
!     char *cp;
  
!     static char *keywords[] = {"sep", NULL};
  
!     if (!PyArg_ParseTupleAndKeywords(args, kw, "|c:isoformat", keywords, &sep))
!         return NULL;
  
!     cp = isoformat_date((PyDateTime_Date *)self, buffer, sizeof(buffer));
!     assert(cp != NULL);
!     *cp++ = sep;
!     isoformat_time(self, cp, sizeof(buffer) - (cp - buffer));
  
!     return PyString_FromString(buffer);
  }
  
--- 258,276 ----
                     PyObject *args, PyObject *kw)
  {
! 	char buffer[128];
! 	char sep = 'T';
! 	char *cp;
  
! 	static char *keywords[] = {"sep", NULL};
  
! 	if (!PyArg_ParseTupleAndKeywords(args, kw, "|c:isoformat", keywords, &sep))
! 		return NULL;
  
! 	cp = isoformat_date((PyDateTime_Date *)self, buffer, sizeof(buffer));
! 	assert(cp != NULL);
! 	*cp++ = sep;
! 	isoformat_time(self, cp, sizeof(buffer) - (cp - buffer));
  
! 	return PyString_FromString(buffer);
  }
  
***************
*** 278,286 ****
  datetime_nonzero(PyDateTime_DateTime *self)
  {
!     return (GET_MICROSECOND(self) != 0
!             || GET_SECOND(self) != 0
!             || GET_MINUTE(self) != 0
!             || GET_HOUR(self) != 0
!             || date_nonzero((PyDateTime_Date *) self) != 0);
  }
  
--- 278,286 ----
  datetime_nonzero(PyDateTime_DateTime *self)
  {
! 	return (GET_MICROSECOND(self) != 0
! 		|| GET_SECOND(self) != 0
! 		|| GET_MINUTE(self) != 0
! 		|| GET_HOUR(self) != 0
! 		|| date_nonzero((PyDateTime_Date *) self) != 0);
  }
  
***************
*** 288,308 ****
  datetime_now(PyObject *self, PyObject *cls)
  {
!     /* XXX need to create the instance by calling cls(y,mon,d,h,min,s,u) */
!     struct timeval t;
!     struct tm *tm;
!     time_t timet;
  
  #ifdef GETTIMEOFDAY_NO_TZ
!     gettimeofday(&t);
  #else /* !GETTIMEOFDAY_NO_TZ */
!     gettimeofday(&t, (struct timezone *)NULL);
  #endif /* !GETTIMEOFDAY_NO_TZ */
!     timet = t.tv_sec;
!     tm = localtime(&timet);
  
!     return PyObject_CallFunction(cls, "iiiiiil",
!                                  tm->tm_year + 1900, tm->tm_mon + 1,
!                                  tm->tm_mday, tm->tm_hour, tm->tm_min,
!                                  tm->tm_sec, t.tv_usec);
  }
  
--- 288,308 ----
  datetime_now(PyObject *self, PyObject *cls)
  {
! 	/* XXX need to create the instance by calling cls(y,mon,d,h,min,s,u) */
! 	struct timeval t;
! 	struct tm *tm;
! 	time_t timet;
  
  #ifdef GETTIMEOFDAY_NO_TZ
! 	gettimeofday(&t);
  #else /* !GETTIMEOFDAY_NO_TZ */
! 	gettimeofday(&t, (struct timezone *)NULL);
  #endif /* !GETTIMEOFDAY_NO_TZ */
! 	timet = t.tv_sec;
! 	tm = localtime(&timet);
  
! 	return PyObject_CallFunction(cls, "iiiiiil",
! 				     tm->tm_year + 1900, tm->tm_mon + 1,
! 				     tm->tm_mday, tm->tm_hour, tm->tm_min,
! 				     tm->tm_sec, t.tv_usec);
  }
  
***************
*** 310,345 ****
  datetime_today(PyObject *self, PyObject *cls)
  {
!     /* XXX need to create the instance by calling cls(y,mon,d,h,min,s,u) */
!     struct timeval t;
!     struct tm *tm;
!     time_t timet;
  
  #ifdef GETTIMEOFDAY_NO_TZ
!     gettimeofday(&t);
  #else /* !GETTIMEOFDAY_NO_TZ */
!     gettimeofday(&t, (struct timezone *)NULL);
  #endif /* !GETTIMEOFDAY_NO_TZ */
!     timet = t.tv_sec;
!     tm = localtime(&timet);
  
!     return PyObject_CallFunction(cls, "iiiiiil",
!                                  tm->tm_year + 1900, tm->tm_mon + 1,
!                                  tm->tm_mday, 0, 0, 0, 0);
  }
  
  static PyMethodDef datetime_methods[] = {
!     /* Class methods: */
!     {"now",         (PyCFunction)datetime_now,           METH_O | METH_CLASS,
!      "Return a new datetime that represents the current time."},
!     {"today",         (PyCFunction)datetime_today,       METH_O | METH_CLASS,
!      "Return a new datetime that represents the current date."},
  
!     /* Instance methods: */
!     {"ctime",       (PyCFunction)datetime_ctime,         METH_NOARGS,
!      "Return ctime() style string."},
!     {"isoformat",   (PyCFunction)datetime_isoformat,     METH_KEYWORDS,
!      "Return the day of the week represented by the datetime.\n"
!      "Monday == 1 ... Sunday == 7"},
!     {NULL}
  };
  
--- 310,345 ----
  datetime_today(PyObject *self, PyObject *cls)
  {
! 	/* XXX need to create the instance by calling cls(y,mon,d,h,min,s,u) */
! 	struct timeval t;
! 	struct tm *tm;
! 	time_t timet;
  
  #ifdef GETTIMEOFDAY_NO_TZ
! 	gettimeofday(&t);
  #else /* !GETTIMEOFDAY_NO_TZ */
! 	gettimeofday(&t, (struct timezone *)NULL);
  #endif /* !GETTIMEOFDAY_NO_TZ */
! 	timet = t.tv_sec;
! 	tm = localtime(&timet);
  
! 	return PyObject_CallFunction(cls, "iiiiiil",
! 				     tm->tm_year + 1900, tm->tm_mon + 1,
! 				     tm->tm_mday, 0, 0, 0, 0);
  }
  
  static PyMethodDef datetime_methods[] = {
! 	/* Class methods: */
! 	{"now",         (PyCFunction)datetime_now,           METH_O | METH_CLASS,
! 	 "Return a new datetime that represents the current time."},
! 	{"today",         (PyCFunction)datetime_today,       METH_O | METH_CLASS,
! 	 "Return a new datetime that represents the current date."},
  
! 	/* Instance methods: */
! 	{"ctime",       (PyCFunction)datetime_ctime,         METH_NOARGS,
! 	 "Return ctime() style string."},
! 	{"isoformat",   (PyCFunction)datetime_isoformat,     METH_KEYWORDS,
! 	 "Return the day of the week represented by the datetime.\n"
! 	 "Monday == 1 ... Sunday == 7"},
! 	{NULL}
  };
  
***************
*** 348,405 ****
  
  static PyNumberMethods datetime_as_number = {
!     datetime_add,				/* nb_add */
!     datetime_subtract,				/* nb_subtract */
!     0,						/* nb_multiply */
!     0,						/* nb_divide */
!     0,						/* nb_remainder */
!     0,						/* nb_divmod */
!     0,						/* nb_power */
!     0,						/* nb_negative */
!     0,						/* nb_positive */
!     0,						/* nb_absolute */
!     (inquiry)datetime_nonzero,			/* nb_nonzero */
  };
  
  statichere PyTypeObject PyDateTime_DateTimeType = {
!     PyObject_HEAD_INIT(NULL)
!     0,						/* ob_size */
!     "datetime",					/* tp_name */
!     sizeof(PyDateTime_DateTime),		/* tp_basicsize */
!     0,						/* tp_itemsize */
!     (destructor)PyObject_Del,			/* tp_dealloc */
!     0,						/* tp_print */
!     0,						/* tp_getattr */
!     0,						/* tp_setattr */
!     (cmpfunc)datetime_compare,			/* tp_compare */
!     (reprfunc)datetime_repr,			/* tp_repr */
!     &datetime_as_number,			/* tp_as_number */
!     0,						/* tp_as_sequence */
!     0,						/* tp_as_mapping */
!     (hashfunc)datetime_hash,			/* tp_hash */
!     0,              				/* tp_call */
!     (reprfunc)datetime_str,			/* tp_str */
!     PyObject_GenericGetAttr,			/* tp_getattro */
!     0,						/* tp_setattro */
!     0,						/* tp_as_buffer */
!     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
          Py_TPFLAGS_BASETYPE,			/* tp_flags */
!     datetime_doc,				/* tp_doc */
!     0,						/* tp_traverse */
!     0,						/* tp_clear */
!     0,						/* tp_richcompare */
!     0,						/* tp_weaklistoffset */
!     0,						/* tp_iter */
!     0,						/* tp_iternext */
!     datetime_methods,				/* tp_methods */
!     0,						/* tp_members */
!     datetime_getset,				/* tp_getset */
!     &PyDateTime_DateType,			/* tp_base */
!     0,						/* tp_dict */
!     0,						/* tp_descr_get */
!     0,						/* tp_descr_set */
!     0,						/* tp_dictoffset */
!     0,						/* tp_init */
!     0,						/* tp_alloc */
!     datetime_new,				/* tp_new */
!     _PyObject_Del,				/* tp_free */
  };
--- 348,405 ----
  
  static PyNumberMethods datetime_as_number = {
! 	datetime_add,				/* nb_add */
! 	datetime_subtract,				/* nb_subtract */
! 	0,						/* nb_multiply */
! 	0,						/* nb_divide */
! 	0,						/* nb_remainder */
! 	0,						/* nb_divmod */
! 	0,						/* nb_power */
! 	0,						/* nb_negative */
! 	0,						/* nb_positive */
! 	0,						/* nb_absolute */
! 	(inquiry)datetime_nonzero,			/* nb_nonzero */
  };
  
  statichere PyTypeObject PyDateTime_DateTimeType = {
! 	PyObject_HEAD_INIT(NULL)
! 	0,						/* ob_size */
! 	"datetime",					/* tp_name */
! 	sizeof(PyDateTime_DateTime),		/* tp_basicsize */
! 	0,						/* tp_itemsize */
! 	(destructor)PyObject_Del,			/* tp_dealloc */
! 	0,						/* tp_print */
! 	0,						/* tp_getattr */
! 	0,						/* tp_setattr */
! 	(cmpfunc)datetime_compare,			/* tp_compare */
! 	(reprfunc)datetime_repr,			/* tp_repr */
! 	&datetime_as_number,			/* tp_as_number */
! 	0,						/* tp_as_sequence */
! 	0,						/* tp_as_mapping */
! 	(hashfunc)datetime_hash,			/* tp_hash */
! 	0,              				/* tp_call */
! 	(reprfunc)datetime_str,			/* tp_str */
! 	PyObject_GenericGetAttr,			/* tp_getattro */
! 	0,						/* tp_setattro */
! 	0,						/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
          Py_TPFLAGS_BASETYPE,			/* tp_flags */
! 	datetime_doc,				/* tp_doc */
! 	0,						/* tp_traverse */
! 	0,						/* tp_clear */
! 	0,						/* tp_richcompare */
! 	0,						/* tp_weaklistoffset */
! 	0,						/* tp_iter */
! 	0,						/* tp_iternext */
! 	datetime_methods,				/* tp_methods */
! 	0,						/* tp_members */
! 	datetime_getset,				/* tp_getset */
! 	&PyDateTime_DateType,			/* tp_base */
! 	0,						/* tp_dict */
! 	0,						/* tp_descr_get */
! 	0,						/* tp_descr_set */
! 	0,						/* tp_dictoffset */
! 	0,						/* tp_init */
! 	0,						/* tp_alloc */
! 	datetime_new,				/* tp_new */
! 	_PyObject_Del,				/* tp_free */
  };

Index: obj_delta.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_delta.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** obj_delta.c	20 Aug 2002 18:53:07 -0000	1.1
--- obj_delta.c	21 Nov 2002 18:02:01 -0000	1.2
***************
*** 8,39 ****
  delta_add(PyObject *left, PyObject *right)
  {
!     PyTypeObject *left_type = left->ob_type;
!     PyTypeObject *right_type = right->ob_type;
!     PyDateTime_Delta *delta;
!     PyObject *other;
!     PyTypeObject *other_type;
  
!     if (PyType_IsSubtype(left_type, &PyDateTime_DeltaType)) {
!         /* delta + ??? */
!         delta = (PyDateTime_Delta *) left;
!         if (PyType_IsSubtype(right_type, &PyDateTime_DeltaType)) {
!             /* delta + delta */
!             long int days = GET_TD_DAYS(delta) + GET_TD_DAYS(right);
!             long int seconds = GET_TD_SECONDS(delta) + GET_TD_SECONDS(right);
!             long int microseconds = (GET_TD_MICROSECONDS(delta)
!                                      + GET_TD_MICROSECONDS(right));
!             return new_delta(days, seconds, microseconds);
!         }
!         other = right;
!         other_type = right_type;
!     }
!     else {
!         /* !delta + delta */
!         delta = (PyDateTime_Delta *) right;
!         other = left;
!         other_type = left_type;
!     }
!     Py_INCREF(Py_NotImplemented);
!     return Py_NotImplemented;
  }
  
--- 8,39 ----
  delta_add(PyObject *left, PyObject *right)
  {
! 	PyTypeObject *left_type = left->ob_type;
! 	PyTypeObject *right_type = right->ob_type;
! 	PyDateTime_Delta *delta;
! 	PyObject *other;
! 	PyTypeObject *other_type;
  
! 	if (PyType_IsSubtype(left_type, &PyDateTime_DeltaType)) {
! 		/* delta + ??? */
! 		delta = (PyDateTime_Delta *) left;
! 		if (PyType_IsSubtype(right_type, &PyDateTime_DeltaType)) {
! 			/* delta + delta */
! 			long int days = GET_TD_DAYS(delta) + GET_TD_DAYS(right);
! 			long int seconds = GET_TD_SECONDS(delta) + GET_TD_SECONDS(right);
! 			long int microseconds = (GET_TD_MICROSECONDS(delta)
! 						 + GET_TD_MICROSECONDS(right));
! 			return new_delta(days, seconds, microseconds);
! 		}
! 		other = right;
! 		other_type = right_type;
! 	}
! 	else {
! 		/* !delta + delta */
! 		delta = (PyDateTime_Delta *) right;
! 		other = left;
! 		other_type = left_type;
! 	}
! 	Py_INCREF(Py_NotImplemented);
! 	return Py_NotImplemented;
  }
  
***************
*** 41,62 ****
  delta_compare(PyDateTime_Delta *self, PyObject *other)
  {
!     int result = -1;
!     if (!PyObject_TypeCheck(other, &PyDateTime_DeltaType))
!         PyErr_Format(PyExc_TypeError,
!                      "can't compare %s to %s instance",
!                      self->ob_type->tp_name, other->ob_type->tp_name);
!     else {
!         long diff = GET_TD_DAYS(self) - GET_TD_DAYS(other);
!         if (diff == 0) {
!             diff = GET_TD_SECONDS(self) - GET_TD_SECONDS(other);
!             if (diff == 0)
!                 diff = GET_TD_MICROSECONDS(self) - GET_TD_MICROSECONDS(other);
!         }
!         if (diff == 0)
!             result = 0;
!         else if (diff > 0)
!             result = 1;
!     }
!     return result;
  }
  
--- 41,62 ----
  delta_compare(PyDateTime_Delta *self, PyObject *other)
  {
! 	int result = -1;
! 	if (!PyObject_TypeCheck(other, &PyDateTime_DeltaType))
! 		PyErr_Format(PyExc_TypeError,
! 			     "can't compare %s to %s instance",
! 			     self->ob_type->tp_name, other->ob_type->tp_name);
! 	else {
! 		long diff = GET_TD_DAYS(self) - GET_TD_DAYS(other);
! 		if (diff == 0) {
! 			diff = GET_TD_SECONDS(self) - GET_TD_SECONDS(other);
! 			if (diff == 0)
! 				diff = GET_TD_MICROSECONDS(self) - GET_TD_MICROSECONDS(other);
! 		}
! 		if (diff == 0)
! 			result = 0;
! 		else if (diff > 0)
! 			result = 1;
! 	}
! 	return result;
  }
  
***************
*** 64,68 ****
  delta_hash(PyDateTime_Delta *self)
  {
!     return -2;
  }
  
--- 64,68 ----
  delta_hash(PyDateTime_Delta *self)
  {
! 	return -2;
  }
  
***************
*** 70,77 ****
  multiply_int_timedelta(PyObject *intobj, PyDateTime_Delta *delta)
  {
!     long i = PyInt_AS_LONG(intobj);
!     return new_delta(GET_TD_DAYS(delta) * i,
!                      GET_TD_SECONDS(delta) * i,
!                      GET_TD_MICROSECONDS(delta) * i);
  }
  
--- 70,77 ----
  multiply_int_timedelta(PyObject *intobj, PyDateTime_Delta *delta)
  {
! 	long i = PyInt_AS_LONG(intobj);
! 	return new_delta(GET_TD_DAYS(delta) * i,
! 			 GET_TD_SECONDS(delta) * i,
! 			 GET_TD_MICROSECONDS(delta) * i);
  }
  
***************
*** 79,100 ****
  delta_multiply(PyObject *left, PyObject *right)
  {
!     PyObject *result = NULL;
!     if (PyType_IsSubtype(left->ob_type, &PyDateTime_DeltaType)) {
!         /* delta * ??? */
!         if (PyInt_Check(right))
!             result = multiply_int_timedelta(right, (PyDateTime_Delta *) left);
!         else {
!             Py_INCREF(Py_NotImplemented);
!             return Py_NotImplemented;
!         }
!     }
!     else if (PyInt_Check(left))
!         result = multiply_int_timedelta(left, (PyDateTime_Delta *) right);
!     else {
!         /* !(delta | int) * delta */
!         Py_INCREF(Py_NotImplemented);
!         return Py_NotImplemented;
!     }
!     return result;
  }
  
--- 79,100 ----
  delta_multiply(PyObject *left, PyObject *right)
  {
! 	PyObject *result = NULL;
! 	if (PyType_IsSubtype(left->ob_type, &PyDateTime_DeltaType)) {
! 		/* delta * ??? */
! 		if (PyInt_Check(right))
! 			result = multiply_int_timedelta(right, (PyDateTime_Delta *) left);
! 		else {
! 			Py_INCREF(Py_NotImplemented);
! 			return Py_NotImplemented;
! 		}
! 	}
! 	else if (PyInt_Check(left))
! 		result = multiply_int_timedelta(left, (PyDateTime_Delta *) right);
! 	else {
! 		/* !(delta | int) * delta */
! 		Py_INCREF(Py_NotImplemented);
! 		return Py_NotImplemented;
! 	}
! 	return result;
  }
  
***************
*** 102,108 ****
  delta_negative(PyDateTime_Delta *self)
  {
!     return new_delta(-GET_TD_DAYS(self),
!                      -GET_TD_SECONDS(self),
!                      -GET_TD_MICROSECONDS(self));
  }
  
--- 102,108 ----
  delta_negative(PyDateTime_Delta *self)
  {
! 	return new_delta(-GET_TD_DAYS(self),
! 			 -GET_TD_SECONDS(self),
! 			 -GET_TD_MICROSECONDS(self));
  }
  
***************
*** 110,135 ****
  delta_new(PyTypeObject *type, PyObject *args, PyObject *kw)
  {
!     PyObject *self = NULL;
!     long int days, seconds = 0, microseconds = 0;
  
!     static char *keywords[] = {
!         "days", "seconds", "microseconds", NULL
!     };
  
!     if (PyArg_ParseTupleAndKeywords(args, kw, "l|ll:__new__", keywords,
!                                     &days, &seconds, &microseconds)) {
!         if (seconds < 0 || seconds >= (24 * 3600)) {
!             PyErr_SetString(PyExc_ValueError,
!                             "seconds must be in 0..86399");
!             return NULL;
!         }
!         if (microseconds < 0 || microseconds >= 1000000) {
!             PyErr_SetString(PyExc_ValueError,
!                             "microseconds must be in 0..999999");
!             return NULL;
!         }
!         self = new_delta(days, seconds, microseconds);
!     }
!     return self;
  }
  
--- 110,135 ----
  delta_new(PyTypeObject *type, PyObject *args, PyObject *kw)
  {
! 	PyObject *self = NULL;
! 	long int days, seconds = 0, microseconds = 0;
  
! 	static char *keywords[] = {
! 		"days", "seconds", "microseconds", NULL
! 	};
  
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "l|ll:__new__", keywords,
! 					&days, &seconds, &microseconds)) {
! 		if (seconds < 0 || seconds >= (24 * 3600)) {
! 			PyErr_SetString(PyExc_ValueError,
! 					"seconds must be in 0..86399");
! 			return NULL;
! 		}
! 		if (microseconds < 0 || microseconds >= 1000000) {
! 			PyErr_SetString(PyExc_ValueError,
! 					"microseconds must be in 0..999999");
! 			return NULL;
! 		}
! 		self = new_delta(days, seconds, microseconds);
! 	}
! 	return self;
  }
  
***************
*** 137,142 ****
  delta_subtract(PyObject *left, PyObject *right)
  {
!     Py_INCREF(Py_NotImplemented);
!     return Py_NotImplemented;
  }
  
--- 137,142 ----
  delta_subtract(PyObject *left, PyObject *right)
  {
! 	Py_INCREF(Py_NotImplemented);
! 	return Py_NotImplemented;
  }
  
***************
*** 144,150 ****
  delta_nonzero(PyDateTime_Delta *self)
  {
!     return (GET_TD_DAYS(self) != 0
!             || GET_TD_SECONDS(self) != 0
!             || GET_TD_MICROSECONDS(self) != 0);
  }
  
--- 144,150 ----
  delta_nonzero(PyDateTime_Delta *self)
  {
! 	return (GET_TD_DAYS(self) != 0
! 		|| GET_TD_SECONDS(self) != 0
! 		|| GET_TD_MICROSECONDS(self) != 0);
  }
  
***************
*** 152,170 ****
  delta_repr(PyDateTime_Delta *self)
  {
!     if (GET_TD_MICROSECONDS(self) != 0)
!         return PyString_FromFormat("%s(%ld, %ld, %ld)",
!                                    self->ob_type->tp_name,
!                                    GET_TD_DAYS(self),
!                                    GET_TD_SECONDS(self),
!                                    GET_TD_MICROSECONDS(self));
!     if (GET_TD_SECONDS(self) != 0)
!         return PyString_FromFormat("%s(%ld, %ld)",
!                                    self->ob_type->tp_name,
!                                    GET_TD_DAYS(self),
!                                    GET_TD_SECONDS(self));
  
!     return PyString_FromFormat("%s(%ld)",
!                                self->ob_type->tp_name,
!                                GET_TD_DAYS(self));
  }
  
--- 152,170 ----
  delta_repr(PyDateTime_Delta *self)
  {
! 	if (GET_TD_MICROSECONDS(self) != 0)
! 		return PyString_FromFormat("%s(%ld, %ld, %ld)",
! 					   self->ob_type->tp_name,
! 					   GET_TD_DAYS(self),
! 					   GET_TD_SECONDS(self),
! 					   GET_TD_MICROSECONDS(self));
! 	if (GET_TD_SECONDS(self) != 0)
! 		return PyString_FromFormat("%s(%ld, %ld)",
! 					   self->ob_type->tp_name,
! 					   GET_TD_DAYS(self),
! 					   GET_TD_SECONDS(self));
  
! 	return PyString_FromFormat("%s(%ld)",
! 				   self->ob_type->tp_name,
! 				   GET_TD_DAYS(self));
  }
  
***************
*** 172,182 ****
  
  static PyMemberDef delta_members[] = {
!     {"days",         T_LONG, OFFSET(days),         READONLY,
!      "Number os days."},
!     {"seconds",      T_LONG, OFFSET(seconds),      READONLY,
!      "Number of seconds (less than 1 day)."},
!     {"microseconds", T_LONG, OFFSET(microseconds), READONLY,
!      "Number of microseconds (less than 1 second)."},
!     {NULL}
  };
  
--- 172,182 ----
  
  static PyMemberDef delta_members[] = {
! 	{"days",         T_LONG, OFFSET(days),         READONLY,
! 	 "Number os days."},
! 	{"seconds",      T_LONG, OFFSET(seconds),      READONLY,
! 	 "Number of seconds (less than 1 day)."},
! 	{"microseconds", T_LONG, OFFSET(microseconds), READONLY,
! 	 "Number of microseconds (less than 1 second)."},
! 	{NULL}
  };
  
***************
*** 185,241 ****
  
  static PyNumberMethods delta_as_number = {
!     delta_add,					/* nb_add */
!     delta_subtract,				/* nb_subtract */
!     delta_multiply,				/* nb_multiply */
!     0,						/* nb_divide */
!     0,						/* nb_remainder */
!     0,						/* nb_divmod */
!     0,						/* nb_power */
!     (unaryfunc)delta_negative,			/* nb_negative */
!     0,						/* nb_positive */
!     0,						/* nb_absolute */
!     (inquiry)delta_nonzero,			/* nb_nonzero */
  };
  
  static PyTypeObject PyDateTime_DeltaType = {
!     PyObject_HEAD_INIT(NULL)
!     0,						/* ob_size */
!     "timedelta",				/* tp_name */
!     sizeof(PyDateTime_Delta),			/* tp_basicsize */
!     0,						/* tp_itemsize */
!     0,						/* tp_dealloc */
!     0,						/* tp_print */
!     0,						/* tp_getattr */
!     0,						/* tp_setattr */
!     (cmpfunc)delta_compare,			/* tp_compare */
!     (reprfunc)delta_repr,			/* tp_repr */
!     &delta_as_number,				/* tp_as_number */
!     0,						/* tp_as_sequence */
!     0,						/* tp_as_mapping */
!     (hashfunc)delta_hash,			/* tp_hash */
!     0,              				/* tp_call */
!     0,						/* tp_str */
!     PyObject_GenericGetAttr,			/* tp_getattro */
!     0,						/* tp_setattro */
!     0,						/* tp_as_buffer */
!     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES,	/* tp_flags */
!     delta_doc,					/* tp_doc */
!     0,						/* tp_traverse */
!     0,						/* tp_clear */
!     0,						/* tp_richcompare */
!     0,						/* tp_weaklistoffset */
!     0,						/* tp_iter */
!     0,						/* tp_iternext */
!     0,						/* tp_methods */
!     delta_members,				/* tp_members */
!     0,						/* tp_getset */
!     0,						/* tp_base */
!     0,						/* tp_dict */
!     0,						/* tp_descr_get */
!     0,						/* tp_descr_set */
!     0,						/* tp_dictoffset */
!     0,						/* tp_init */
!     0,						/* tp_alloc */
!     delta_new,					/* tp_new */
!     _PyObject_Del,				/* tp_free */
  };
--- 185,241 ----
  
  static PyNumberMethods delta_as_number = {
! 	delta_add,					/* nb_add */
! 	delta_subtract,				/* nb_subtract */
! 	delta_multiply,				/* nb_multiply */
! 	0,						/* nb_divide */
! 	0,						/* nb_remainder */
! 	0,						/* nb_divmod */
! 	0,						/* nb_power */
! 	(unaryfunc)delta_negative,			/* nb_negative */
! 	0,						/* nb_positive */
! 	0,						/* nb_absolute */
! 	(inquiry)delta_nonzero,			/* nb_nonzero */
  };
  
  static PyTypeObject PyDateTime_DeltaType = {
! 	PyObject_HEAD_INIT(NULL)
! 	0,						/* ob_size */
! 	"timedelta",				/* tp_name */
! 	sizeof(PyDateTime_Delta),			/* tp_basicsize */
! 	0,						/* tp_itemsize */
! 	0,						/* tp_dealloc */
! 	0,						/* tp_print */
! 	0,						/* tp_getattr */
! 	0,						/* tp_setattr */
! 	(cmpfunc)delta_compare,			/* tp_compare */
! 	(reprfunc)delta_repr,			/* tp_repr */
! 	&delta_as_number,				/* tp_as_number */
! 	0,						/* tp_as_sequence */
! 	0,						/* tp_as_mapping */
! 	(hashfunc)delta_hash,			/* tp_hash */
! 	0,              				/* tp_call */
! 	0,						/* tp_str */
! 	PyObject_GenericGetAttr,			/* tp_getattro */
! 	0,						/* tp_setattro */
! 	0,						/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES,	/* tp_flags */
! 	delta_doc,					/* tp_doc */
! 	0,						/* tp_traverse */
! 	0,						/* tp_clear */
! 	0,						/* tp_richcompare */
! 	0,						/* tp_weaklistoffset */
! 	0,						/* tp_iter */
! 	0,						/* tp_iternext */
! 	0,						/* tp_methods */
! 	delta_members,				/* tp_members */
! 	0,						/* tp_getset */
! 	0,						/* tp_base */
! 	0,						/* tp_dict */
! 	0,						/* tp_descr_get */
! 	0,						/* tp_descr_set */
! 	0,						/* tp_dictoffset */
! 	0,						/* tp_init */
! 	0,						/* tp_alloc */
! 	delta_new,					/* tp_new */
! 	_PyObject_Del,				/* tp_free */
  };