| |
- Date
class Date |
|
Store and manipulate dates.
It is possible to construct invalid dates (eg 123/-5/12.4).
Behavior in this case is undefined.
Y2K note: Years are interpreted exactly as you enter them,
so you should use all four digits of the year. |
|
Methods defined here:
- __add__(self, num)
- This returns the Date corresponding to 'num' days after the
current day.
- __cmp__(self, other)
- Compare two Date objects.
__cmp__(self,other) < 0 if self < other
__cmp__(self,other) > 0 if self > other
__cmp__(self,other) == 0 if self == other
etc.
- __init__(self, month=1, day=1, year=1, str='', sep='/')
- Create a new Date object.
If 'str' is given, it will be used instead of month, day, and year.
'str' should be in the format 'M [sep] D [sep] Y'.
M, D, and Y can be any number of digits long.
Whitespace anywhere will be ignored, as long as it doesn't occur in
the middle of a number.
Valid Examples:
sep='/', str='12/02/1982'
sep=' ', str=' 12 2 1982 '
sep='.', str=' 12 . 2 . 2000000 '
sep='foo', str='12 foo 02 foo 1982'
Invalid Examples:
sep='/', str='1 2/02/1982'
sep='/', str='12/2/1982/9999'
- __repr__(self)
- Convert this Date to a string in the format 'Date(%m,%d,%y)'
- __str__(self)
- Convert this Date to a string in the format '%M %0d, %0y'
- __sub__(self, num)
- This returns the Date corresponding to 'num' days before
the current Date.
- convertDayToDate(self, num, year)
- This takes a number between 1 and 366 if year is a leap year
or 1-365 otherwise and returns the Date corresponding to the
'num' day of the year 'year'.
- dayOfYear(self)
- Return the day of the year for this Date instance, between
1 and 365 for a non-leap year and 1-366 for a leap year.
- isLeapYear(self, year=None)
- If no year is given, this returns whether the current year
is a leap year, otherwise it returns whether the given year
is a leap year.
- next(self)
- Return the day just after the current day.
- prev(self)
- Return the day just before the current day.
- tostring(self, format='%0m/%0d/%0y')
- Convert this Date object to a string with arbitrary format.
The following replacements will be made to the format string:
'%d' -> day
'%0d' -> day, two digits. Leading zero added if neccesary.
'%M' -> month (name)
'%m' -> month (number)
'%0m' -> month (number), two digits. Leading zero added if neccesary.
'%y' -> year
'%0y' -> year, four digits. Leading zeros added if neccesary.
- verifydate(self)
- Raise an exception if this date is not valid.
Data and non-method functions defined here:
- __doc__ = 'Store and manipulate dates.\n\n It is possib...ou should use all four digits of the year.\n '
- __module__ = 'david'
- day = 1
- leap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- month = 1
- monthnames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
- normal = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- year = 1
| |