~pythonregexp2.7/python/issue2636-01+09-02

« back to all changes in this revision

Viewing changes to Demo/classes/Dates.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-22 00:16:16 UTC
  • mfrom: (39022.1.34 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080922001616-p1wdip9lfp0zl5cu
Merged in changes from the Atomic Grouping / Possessive Qualifiers branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
    return 365 + _is_leap(year)
69
69
 
70
70
def _days_before_year(year):  # number of days before year
71
 
    return year*365L + (year+3)/4 - (year+99)/100 + (year+399)/400
 
71
    return year*365L + (year+3)//4 - (year+99)//100 + (year+399)//400
72
72
 
73
73
def _days_in_month(month, year):      # number of days in month of year
74
74
    if month == 2 and _is_leap(year): return 29
92
92
    del ans.ord, ans.month, ans.day, ans.year # un-initialize it
93
93
    ans.ord = n
94
94
 
95
 
    n400 = (n-1)/_DI400Y                # # of 400-year blocks preceding
 
95
    n400 = (n-1)//_DI400Y                # # of 400-year blocks preceding
96
96
    year, n = 400 * n400, n - _DI400Y * n400
97
 
    more = n / 365
 
97
    more = n // 365
98
98
    dby = _days_before_year(more)
99
99
    if dby >= n:
100
100
        more = more - 1
104
104
    try: year = int(year)               # chop to int, if it fits
105
105
    except (ValueError, OverflowError): pass
106
106
 
107
 
    month = min(n/29 + 1, 12)
 
107
    month = min(n//29 + 1, 12)
108
108
    dbm = _days_before_month(month, year)
109
109
    if dbm >= n:
110
110
        month = month - 1
174
174
    local = time.localtime(time.time())
175
175
    return Date(local[1], local[2], local[0])
176
176
 
177
 
DateTestError = 'DateTestError'
 
177
class DateTestError(Exception):
 
178
    pass
 
179
 
178
180
def test(firstyear, lastyear):
179
181
    a = Date(9,30,1913)
180
182
    b = Date(9,30,1914)
220
222
           (fd.month,fd.day,fd.year,ld.month,ld.day,ld.year):
221
223
            raise DateTestError, ('num->date failed', y)
222
224
        y = y + 1
 
225
 
 
226
if __name__ == '__main__':
 
227
    test(1850, 2150)