• Home
  • Raw
  • Download

Lines Matching 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.
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
91 ans = Date(1,1,1) # arguments irrelevant; just getting a Date obj
120 class Date: class
151 # Python 1.1 coerces neither int+date nor date+int
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
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)
193 raise DateTestError, 'int-date should have failed'
198 raise DateTestError, 'date+date should have failed'
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
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)