[Python-checkins] r66426 - python/trunk/Demo/classes/Dates.py

andrew.kuchling python-checkins at python.org
Sat Sep 13 03:34:46 CEST 2008


Author: andrew.kuchling
Date: Sat Sep 13 03:34:41 2008
New Revision: 66426
Log:
#687648 from Robert Schuppenies: use classic division. From me: don't use string exception; add __main__ section
Modified:
 python/trunk/Demo/classes/Dates.py
Modified: python/trunk/Demo/classes/Dates.py
==============================================================================
--- python/trunk/Demo/classes/Dates.py	(original)
+++ python/trunk/Demo/classes/Dates.py	Sat Sep 13 03:34:41 2008
@@ -68,7 +68,7 @@
 return 365 + _is_leap(year)
 
 def _days_before_year(year): # number of days before year
- return year*365L + (year+3)/4 - (year+99)/100 + (year+399)/400
+ return year*365L + (year+3)//4 - (year+99)//100 + (year+399)//400
 
 def _days_in_month(month, year): # number of days in month of year
 if month == 2 and _is_leap(year): return 29
@@ -92,9 +92,9 @@
 del ans.ord, ans.month, ans.day, ans.year # un-initialize it
 ans.ord = n
 
- n400 = (n-1)/_DI400Y # # of 400-year blocks preceding
+ n400 = (n-1)//_DI400Y # # of 400-year blocks preceding
 year, n = 400 * n400, n - _DI400Y * n400
- more = n / 365
+ more = n // 365
 dby = _days_before_year(more)
 if dby >= n:
 more = more - 1
@@ -104,7 +104,7 @@
 try: year = int(year) # chop to int, if it fits
 except (ValueError, OverflowError): pass
 
- month = min(n/29 + 1, 12)
+ month = min(n//29 + 1, 12)
 dbm = _days_before_month(month, year)
 if dbm >= n:
 month = month - 1
@@ -174,7 +174,9 @@
 local = time.localtime(time.time())
 return Date(local[1], local[2], local[0])
 
-DateTestError = 'DateTestError'
+class DateTestError(Exception):
+ pass
+
 def test(firstyear, lastyear):
 a = Date(9,30,1913)
 b = Date(9,30,1914)
@@ -220,3 +222,6 @@
 (fd.month,fd.day,fd.year,ld.month,ld.day,ld.year):
 raise DateTestError, ('num->date failed', y)
 y = y + 1
+
+if __name__ == '__main__':
+ test(1850, 2150)


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /