[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.62,1.63 test_datetime.py,1.43,1.44
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Tue, 19 Nov 2002 19:23:36 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv10409
Modified Files:
datetime.py test_datetime.py
Log Message:
Implemented the Julian day-of-year method (_yday), + a simple test.
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.62
retrieving revision 1.63
diff -C2 -d -r1.62 -r1.63
*** datetime.py 19 Nov 2002 17:41:40 -0000 1.62
--- datetime.py 20 Nov 2002 03:23:34 -0000 1.63
***************
*** 559,567 ****
def _yday(self):
! """Return tm_yday: day within the current year, where Jan 1 == 1.
!
! XXX This is not correct for now. Who cares.
! """
! return 0
def timetuple(self):
--- 559,564 ----
def _yday(self):
! "Return tm_yday: day within the current year, where Jan 1 == 1."
! return _days_before_month(self.__month, self.__year) + self.__day
def timetuple(self):
Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_datetime.py,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** test_datetime.py 2 Apr 2002 13:41:09 -0000 1.43
--- test_datetime.py 20 Nov 2002 03:23:34 -0000 1.44
***************
*** 311,314 ****
--- 311,329 ----
self.assertEqual(self.theclass.max - big, self.theclass.min)
+ def test_timetuple(self):
+ for i in range(7):
+ # January 2, 1956 is a Monday (0)
+ d = self.theclass(1956, 1, 2+i)
+ t = d.timetuple()
+ self.assertEqual(t, (1956, 1, 2+i, 0, 0, 0, i, 2+i, -1))
+ # February 1, 1956 is a Wednesday (2)
+ d = self.theclass(1956, 2, 1+i)
+ t = d.timetuple()
+ self.assertEqual(t, (1956, 2, 1+i, 0, 0, 0, (2+i)%7, 32+i, -1))
+ # March 1, 1956 is a Thurday (3), and is the 31+29+1 = 61st day
+ # of the year.
+ d = self.theclass(1956, 3, 1+i)
+ t = d.timetuple()
+ self.assertEqual(t, (1956, 3, 1+i, 0, 0, 0, (3+i)%7, 61+i, -1))
class TestDateTime(TestDate):