[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.120,1.121 doc.txt,1.67,1.68 test_datetime.py,1.77,1.78
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Mon, 23 Dec 2002 15:39:08 -0800
- Previous message: [Python-checkins] python/dist/src/Mac/Modules/menu _Menumodule.c,1.16,1.17 menusupport.py,1.19,1.20
- Next message: [Python-checkins] python/nondist/sandbox/datetime datetime.py,1.121,1.122 doc.txt,1.68,1.69 test_datetime.py,1.78,1.79
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv6369
Modified Files:
datetime.py doc.txt test_datetime.py
Log Message:
Implemented date.replace().
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.120
retrieving revision 1.121
diff -C2 -d -r1.120 -r1.121
*** datetime.py 22 Dec 2002 20:44:00 -0000 1.120
--- datetime.py 23 Dec 2002 23:39:05 -0000 1.121
***************
*** 722,725 ****
--- 722,743 ----
return _ymd2ord(self.__year, self.__month, self.__day)
+ def replace(self, year=None, month=None, day=None):
+ """Return a new date with new values for the specified fields."""
+ if year is None:
+ year = self.__year
+ if month is None:
+ month = self.__month
+ if day is None:
+ day = self.__day
+ if not MINYEAR <= year <= MAXYEAR:
+ raise ValueError('year must be in %d..%d' % (MINYEAR, MAXYEAR),
+ year)
+ if not 1 <= month <= 12:
+ raise ValueError('month must be in 1..12', month)
+ dim = _days_in_month(year, month)
+ if not 1 <= day <= dim:
+ raise ValueError('day must be in 1..%d' % dim, day)
+ return date(year, month, day)
+
def __cmp__(self, other):
"Three-way comparison."
Index: doc.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/doc.txt,v
retrieving revision 1.67
retrieving revision 1.68
diff -C2 -d -r1.67 -r1.68
*** doc.txt 22 Dec 2002 20:44:00 -0000 1.67
--- doc.txt 23 Dec 2002 23:39:05 -0000 1.68
***************
*** 408,411 ****
--- 408,416 ----
Instance methods:
+ - replace(year=None, month=None, day=None)
+ Return a date with the same fields as self, except for those members
+ given in the argument list. For example,
+ date(1, 1, 1).replace(year=2000) == date(2000, 1, 1).
+
- timetuple()
Return a 9-element tuple of the form returned by time.localtime().
Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_datetime.py,v
retrieving revision 1.77
retrieving revision 1.78
diff -C2 -d -r1.77 -r1.78
*** test_datetime.py 22 Dec 2002 20:44:00 -0000 1.77
--- test_datetime.py 23 Dec 2002 23:39:05 -0000 1.78
***************
*** 885,888 ****
--- 885,910 ----
for y in 1, 49, 51, 99, 100, 1000, 1899:
self.assertRaises(ValueError, cls(y, 1, 1).strftime, "%Y")
+
+ def test_replace(self):
+ cls = self.theclass
+ args = [1, 2, 3]
+ base = cls(*args)
+ self.assertEqual(base, base.replace())
+
+ i = 0
+ for name, newval in (("year", 2),
+ ("month", 3),
+ ("day", 4)):
+ newargs = args[:]
+ newargs[i] = newval
+ expected = cls(*newargs)
+ got = base.replace(**{name: newval})
+ self.assertEqual(expected, got)
+ i += 1
+
+ # Out of bounds.
+ base = date(2000, 2, 29)
+ self.assertRaises(ValueError, base.replace, year=2001)
+
#############################################################################
# datetime tests
***************
*** 1258,1261 ****
--- 1280,1287 ----
self.assertRaises(TypeError, combine, d, t, 1) # too many args
self.assertRaises(TypeError, combine, "date", "time") # wrong types
+
+ def test_replace(self):
+ return
+
class TestTime(unittest.TestCase):
- Previous message: [Python-checkins] python/dist/src/Mac/Modules/menu _Menumodule.c,1.16,1.17 menusupport.py,1.19,1.20
- Next message: [Python-checkins] python/nondist/sandbox/datetime datetime.py,1.121,1.122 doc.txt,1.68,1.69 test_datetime.py,1.78,1.79
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]