Lines Matching +full:not +full:- +full:date
1 # Class Date supplies date objects that support date arithmetic.
3 # Date(month,day,year) returns a Date object. An instance prints as,
7 # all work as expected for date objects: int+date or date+int returns
8 # the date `int' days from `date'; date+date raises an exception;
9 # date-int returns the date `int' days before `date'; date2-date1 returns
10 # an integer, the number of days from date1 to date2; int-date raises an
13 # the two dates and max(date1,date2) the later; and date objects can be
16 # Date objects support one visible method, date.weekday(). This returns
17 # the day of the week the date falls on, as a string.
19 # Date objects also have 4 read-only data attributes:
23 # .ord the ordinal of the date relative to an arbitrary staring point
26 # current date as a date object.
34 # not speaking for Kendall Square Research Corp
71 return year*365L + (year+3)//4 - (year+99)//100 + (year+399)//400
75 return _DAYS_IN_MONTH[month-1]
78 return _DAYS_BEFORE_MONTH[month-1] + (month > 2 and _is_leap(year))
80 def _date2num(date): # compute ordinal of date.month,day,year argument
81 return _days_before_year(date.year) + \
82 _days_before_month(date.month, date.year) + \
83 date.day
87 def _num2date(n): # return date with ordinal n
88 if type(n) not in _INT_TYPES:
91 ans = Date(1,1,1) # arguments irrelevant; just getting a Date obj
92 del ans.ord, ans.month, ans.day, ans.year # un-initialize it
95 n400 = (n-1)//_DI400Y # # of 400-year blocks preceding
96 year, n = 400 * n400, n - _DI400Y * n400
100 more = more - 1
101 dby = dby - _days_in_year(more)
102 year, n = year + more, int(n - dby)
110 month = month - 1
111 dbm = dbm - _days_in_month(month, year)
113 ans.month, ans.day, ans.year = month, n-dbm, year
120 class Date: class
122 if not 1 <= month <= 12:
125 if not 1 <= day <= dim:
133 raise AttributeError, 'read-only attribute ' + name
148 _MONTH_NAMES[self.month-1],
151 # Python 1.1 coerces neither int+date nor date+int
153 if type(n) not in _INT_TYPES:
154 raise TypeError, 'can\'t add %r to date' % type(n)
156 __radd__ = __add__ # handle int+date
158 # Python 1.1 coerces neither date-int nor date-date
160 if type(other) in _INT_TYPES: # date-int
161 return _num2date(self.ord - other)
163 return self.ord - other.ord # date-date
165 # complain about int-date
167 raise TypeError, 'Can\'t subtract date from integer'
175 return Date(local[1], local[2], local[0])
181 a = Date(9,30,1913)
182 b = Date(9,30,1914)
185 if (not a < b) or a == b or a > b or b != b:
189 if b-a != 365 or b-365 != a:
192 x = 1 - a
193 raise DateTestError, 'int-date should have failed'
198 raise DateTestError, 'date+date should have failed'
203 if max(a,b) is not b or min(a,b) is not a:
205 d = {a-1:b, b:a+1}
206 if d[b-366] != b or d[a+(b-a)] != Date(10,1,1913):
209 # verify date<->number conversions for first and last days for
216 lord = ford + _days_in_year(y) - 1
217 fd, ld = Date(1,1,y), Date(12,31,y)
219 raise DateTestError, ('date->num failed', y)
223 raise DateTestError, ('num->date failed', y)