[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.119,1.120 doc.txt,1.66,1.67 test_datetime.py,1.76,1.77

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Sun, 22 Dec 2002 12:44:02 -0800


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

Modified Files:
	datetime.py doc.txt test_datetime.py 
Log Message:
I give up:  unless I write my own strftime by hand, datetime just can't
be trusted with years before 1900, so now we raise ValueError if a date or
datetime or datetimetz .strftime() method is called with a year before
1900.


Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.119
retrieving revision 1.120
diff -C2 -d -r1.119 -r1.120
*** datetime.py	22 Dec 2002 20:32:53 -0000	1.119
--- datetime.py	22 Dec 2002 20:44:00 -0000	1.120
***************
*** 165,168 ****
--- 165,172 ----
  # Correctly substitute for %z and %Z escapes in strftime formats.
  def _wrap_strftime(object, format, timetuple):
+     year = timetuple[0]
+     if year < 1900:
+         raise ValueError("year=%d is before 1900; the datetime strftime() "
+                          "methods require year >= 1900" % year)
      # Don't call _utcoffset() or tzname() unless actually needed.
      zreplace = None # the string to use for %z

Index: doc.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/doc.txt,v
retrieving revision 1.66
retrieving revision 1.67
diff -C2 -d -r1.66 -r1.67
*** doc.txt	22 Dec 2002 20:32:53 -0000	1.66
--- doc.txt	22 Dec 2002 20:44:00 -0000	1.67
***************
*** 189,195 ****
  
  The exact range of years for which strftime() works also varies
! across platforms, and years before 1900 cannot be used on any
! platform if the environment variable PYTHON2K is set (see the
! documentation for Python's time module).
  
  
--- 189,194 ----
  
  The exact range of years for which strftime() works also varies
! across platforms.  Regardless of platform, years before 1900 cannot
! be used.
  
  

Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_datetime.py,v
retrieving revision 1.76
retrieving revision 1.77
diff -C2 -d -r1.76 -r1.77
*** test_datetime.py	22 Dec 2002 01:43:13 -0000	1.76
--- test_datetime.py	22 Dec 2002 20:44:00 -0000	1.77
***************
*** 879,882 ****
--- 879,888 ----
          self.failUnless(self.theclass.max)
  
+     def test_srftime_out_of_range(self):
+         # For nasty technical reasons, we can't handle years before 1900.
+         cls = self.theclass
+         self.assertEqual(cls(1900, 1, 1).strftime("%Y"), "1900")
+         for y in 1, 49, 51, 99, 100, 1000, 1899:
+             self.assertRaises(ValueError, cls(y, 1, 1).strftime, "%Y")
  #############################################################################
  # datetime tests