[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.113,1.114
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
2002年12月20日 21:43:36 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv16377
Modified Files:
datetime.py
Log Message:
Switched the signatures of some internal helper function, for sanity and
to match the C implementation's versions.
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.113
retrieving revision 1.114
diff -C2 -d -r1.113 -r1.114
*** datetime.py 21 Dec 2002 05:03:13 -0000 1.113
--- datetime.py 21 Dec 2002 05:43:34 -0000 1.114
***************
*** 43,48 ****
return y*365 + y//4 - y//100 + y//400
! def _days_in_month(month, year):
! "month, year -> number of days in that month in that year."
assert 1 <= month <= 12, month
if month == 2 and _is_leap(year):
--- 43,48 ----
return y*365 + y//4 - y//100 + y//400
! def _days_in_month(year, month):
! "year, month -> number of days in that month in that year."
assert 1 <= month <= 12, month
if month == 2 and _is_leap(year):
***************
*** 50,55 ****
return _DAYS_IN_MONTH[month]
! def _days_before_month(month, year):
! "month, year -> number of days in year preceeding first day of month."
if not 1 <= month <= 12:
raise ValueError('month must be in 1..12', month)
--- 50,55 ----
return _DAYS_IN_MONTH[month]
! def _days_before_month(year, month):
! "year, month -> number of days in year preceeding first day of month."
if not 1 <= month <= 12:
raise ValueError('month must be in 1..12', month)
***************
*** 60,68 ****
if not 1 <= month <= 12:
raise ValueError('month must be in 1..12', month)
! dim = _days_in_month(month, year)
if not 1 <= day <= dim:
raise ValueError('day must be in 1..%d' % dim, day)
return (_days_before_year(year) +
! _days_before_month(month, year) +
day)
--- 60,68 ----
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 (_days_before_year(year) +
! _days_before_month(year, month) +
day)
***************
*** 139,143 ****
preceding -= _DAYS_IN_MONTH[month] + (month == 2 and leapyear)
n -= preceding
! assert 0 <= n < _days_in_month(month, year)
# Now the year and month are correct, and n is the offset from the
--- 139,143 ----
preceding -= _DAYS_IN_MONTH[month] + (month == 2 and leapyear)
n -= preceding
! assert 0 <= n < _days_in_month(year, month)
# Now the year and month are correct, and n is the offset from the
***************
*** 153,157 ****
def _build_struct_time(y, m, d, hh, mm, ss, dstflag):
wday = (_ymd2ord(y, m, d) + 6) % 7
! dnum = _days_before_month(m, y) + d
return _time.struct_time((y, m, d, hh, mm, ss, wday, dnum, dstflag))
--- 153,157 ----
def _build_struct_time(y, m, d, hh, mm, ss, dstflag):
wday = (_ymd2ord(y, m, d) + 6) % 7
! dnum = _days_before_month(y, m) + d
return _time.struct_time((y, m, d, hh, mm, ss, wday, dnum, dstflag))
***************
*** 270,274 ****
# 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(month, year)
if not 1 <= day <= dim:
# Move day-1 days from the first of the month. First try to
--- 270,274 ----
# 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 not 1 <= day <= dim:
# Move day-1 days from the first of the month. First try to
***************
*** 278,282 ****
month -= 1
if month > 0:
! day = _days_in_month(month, year)
else:
year, month, day = year-1, 12, 31
--- 278,282 ----
month -= 1
if month > 0:
! day = _days_in_month(year, month)
else:
year, month, day = year-1, 12, 31
***************
*** 602,606 ****
if not 1 <= month <= 12:
raise ValueError('month must be in 1..12', month)
! dim = _days_in_month(month, year)
if not 1 <= day <= dim:
raise ValueError('day must be in 1..%d' % dim, day)
--- 602,606 ----
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)