DateTime and Period
DateTime
The newdate method answers a new DateTime instance.
If the date is None, then answer None. If date is a string, then convert to DateTime.
Check on the month and day boundaries.
The DateTime implements a full intuitive interface to the date and time information.
It allows adding an subtracting and contains many method that look like they are attributes.
- Initialize the current date if the date is equal to now
- Initialize on first day of the week if year and week are defined
- Initialize from existing datetime if "dt" is defined
- Initialize from date string (identical to the result of self.date) if defined
- Initialize from time string (identical to the result of self.time) if defined
- Initialize from (year, month, day) if all of them are defined.
- Otherwise raise an error
Python example
DateTime(date='now')
DateTime(date='2008-11-23')
DateTime(date='2008-11-23', time='23:11')
DateTime(date='2008-11-23', time='23:11:22')
DateTime(2008, 11, 23)
DateTime(2008, 11, 23, 23, 11, 22, 0)
DateTime(2008, week=23)
DateTime(date='now')
DateTime(date='2008-11-23')
DateTime(date='2008-11-23', time='23:11')
DateTime(date='2008-11-23', time='23:11:22')
DateTime(2008, 11, 23)
DateTime(2008, 11, 23, 23, 11, 22, 0)
DateTime(2008, week=23)
The DateTime class contains the following attributes and method. Note that the construction in DateTime makes the result of all methods available as attribute values.
| Method | Attributes | Docstring or default value |
|---|---|---|
| __add__ | duration |
Add the
Python example Date + Duration = Date Date + 3 = Date |
| __coerce__ | duration |
|
| __doc__ | u'\n\tnewdate method answers a new DateTime instance.\n\tIf the None, then answer None. If DateTime.\n\tCheck on the month and day boundaries.\n\t
nowFalse (default is True) then the\n\tinput values of the date are not trimmed to their minimum and maximum values. This checking is done in\n\tcontext for days in months and years.\n\t \n\tDateTime(date=\'2008-11-23\') \n\tDateTime(date=\'2008-11-23\', time=\'23:11\') \n\tDateTime(date=\'2008-11-23\', time=\'23:11:22\') \n\tDateTime(2008, 11, 23) \n\tDateTime(2008, 11, 23, 23, 11, 22, 0) \n\tDateTime(2008, week=23) \n\t |
|
| __eq__ | dt |
|
| __ge__ | dt |
|
| __getattr__ | key |
|
| __gt__ | dt |
|
| __iadd__ | item |
|
| __init__ | date day dt hour microsecond minute month second time trimvalues tz week year |
|
| __isub__ | item |
|
| __le__ | dt |
Answers True if self is in the past of or equal to date dt as in self <= dt. Note that in evaluating the condition the difference in time is taken into account as well. Use self.datenumber < dt.datenumber to test on date comparison only instead of dy <= self. |
| __lt__ | dt |
Answers True if self is in the past of date dt as in self < dt. Note that in evaluating the condition the difference in time is taken into account as well. Use self.datenumber < dt.datenumber to test on date comparison only instead of dy < self. |
| __module__ | 'xpyth.xierpa.tools.dating' | |
| __ne__ | dt |
|
| __nonzero__ |
Always answer True indicating that a DateTime instance can never be zero.
|
|
| __repr__ |
The function repr(dt) (or `dt`) answers the string representation of the date, typically identical to dt.date + ' ' + dt.time.
|
|
| __str__ |
The function str(dt) answers the string representation of the date. Typically the identical to dt.date + ' ' + dt.time.
|
|
| __sub__ | durationordate |
Python example Date - Duration = Date Date - Date = Duration Date - 3 = Date |
| _calendarmonth |
The calendarmonth method/attribute answers a list of lists containing the weeks with dates of the current month
Note that the first and lost week are filled with the days of end of the previous month and the start of the next month. Python example [ [p01, p02, p03, d01, d02, d03, d04], [d05, d06, d07, d08, d09, d10, d11], [d12, d13, d14, d15, d16, d17, d18], [d19, d20, d21, d22, d23, d24, d25], [d26, d27, d28, d29, d30, n01, n02] ] |
|
| _calendaryear |
The calendaryear method/attribute answers a list of lists of lists containing all calendarmonths of the year. Python example [ [ [p01, p02, p03, d01, d02, d03, d04], [d05, d06, d07, d08, d09, d10, d11], [d12, d13, d14, d15, d16, d17, d18], [d19, d20, d21, d22, d23, d24, d25], [d26, d27, d28, d29, d30, n01, n02] ] [ ... ] ... ] |
|
| _date |
The dt.date answers a formatted string 2008-10-23 of the date.
This is exactly what SQL needs as date-string definition.
|
|
| _datenumber |
The dt.datenumber method/attribute answers a long integer number 20080502 of the date. This
can by used to compare dates on day only and not on time. Or it can be used as ordering key.
|
|
| _datetuple |
The dt.datetuple method/attribute answers a tuple (y,m,d) of the date.
|
|
| _dayname |
The dt.dayname method/attribute answers a 3 letter abbreviation of current day name.
|
|
| _eurodate |
The dt.eurodate answers a formatted string 23-10-2008 of the date.
|
|
| _fulldayname |
The dt.fulldayname method/attribute answers the full name of the current day.
|
|
| _fullmonthname |
The dt.fullmonthname method/attribute answers the full name of the current month.
|
|
| _leapyear |
The dt.leapyear method/attribute answers a boolean if the dt is a leap year.
|
|
| _monthdays |
The dt.monthdays method/attribute answers the number of days in the current month.
|
|
| _monthend |
The dt.monthend method/attribute answers the last day of the current month.
|
|
| _monthname |
The dt.monthname method/attribute answers a 3 letter abbreviation of current month name.
|
|
| _monthstart |
The dt.monthstart method/attribute answers the first day of the current month.
|
|
| _nextmonth |
The nextmonth method/attribute answers the first day of the month after the current month.
Due to length differences between the months, it is not consistent to
answer the current day number in the next month, so it is set to 1.
|
|
| _nextworkday |
The dt.nextworkday method/attribute answers the first next date (including itself) that is a workday
|
|
| _prevmonth |
The prevmonth method/attribute answers the first day of the month previous to the current month.
Due to length differences between the months, it is not consistent to
answer the current day number in the previous month
|
|
| _studyyear |
The dt.studyyear method/attribute answers a string 0708 with
leading zero for the study year from 2007-08-01 until 2008-07-31
|
|
| _time |
The dt.datenumber method/attribute answers a formatted '12:23:45' time string.
|
|
| _timestamp | usetz |
The dt.timestamp answers a formatted string 2010-10-05 16:47:29+04 of the date.
This is exactly what SQL needs as timestamp with time zone definition. Note: use of tz does not yet work, and is ignored |
| _timetuple |
The dt.timetuple method/attribute answers a tuple (h, m, s) of the time.
|
|
| _timezone |
The dt.timezone method/attribute answers the timezone dt.tz.
|
|
| _uniquenumber |
The _uniquenumber method/attributes ansers a unique number of format '20090621200511993066',
derived from date, time and a six digit random number. This can be used e.g. in a url as parameters to make sure that browser
will not cache the content of the page.
|
|
| _week |
The dt.week method/attribute answers the weeknummer according to ISO 8601 where the first week of the year that contains a thursday.
|
|
| _weekend |
Keep integer calculation combined by brackets
|
|
| _weekstart |
The dt.weekstart method/attribute answers the “Monday” date of the current week.
|
|
| _workday |
The dt.workday method/attribute answers True if this day is one of Monday till Friday.
|
|
| _yeardays |
The dt.yeardays method/attribute answers the number of days in the current year.
|
|
| _yearend |
The dt.yearend method/attribute answers the last day of the current year.
|
|
| _yearstart |
The dt.yearstart method/attribute answers the first day of the current year.
|
|
| daynames | ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] | |
| fulldaynames | ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] | |
| fullmonthnames | ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | |
| keys | {'second': 5, 'tz': 8, 'weekday': 6, 'hour': 3, 'year': 0, 'yearday': 7, 'day': 2, 'minute': 4, 'month': 1} | |
| monthnames | ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] | |
| nextdaynamed | weekday |
Period
The Duration class contains a duration in time. It can e.g. be used to add to a DateTime
instance with a new date as result.
All common arithmetic applies to a Duration instance.
The Period class contains the following tags.Python example
Duration(3)
Duration(seconds=10)
Duration(td=timedelta)
Duration(3)
Duration(seconds=10)
Duration(td=timedelta)
All common arithmetic applies to a Duration instance.
Python example
d = Duration(3)
d * 3 is a duration of 6 days.
d = Duration(3)
d * 3 is a duration of 6 days.
| Method | Attributes | Docstring or default value |
|---|---|---|
| __add__ | value |
|
| __coerce__ | p |
|
| __div__ | n |
|
| __doc__ | u'\n\tDuration class contains a duration in time. It can e.g. be used to add to a DateTime\n\tinstance with a new date as result.\n\t \n\tDuration(seconds=10) \n\tDuration(td=timedelta) \n\t Duration instance. \n\t\n\td * 3 is a duration of 6 days. \n\t |
|
| __getattr__ | key |
|
| __iadd__ | item |
|
| __idiv__ | item |
|
| __imul__ | item |
|
| __init__ | days hours microseconds milliseconds minutes seconds td weeks |
If td is already there, then use it and ignore all other parameters.
|
| __isub__ | item |
|
| __len__ | ||
| __module__ | 'xpyth.xierpa.tools.dating' | |
| __mul__ | n |
|
| __neg__ | ||
| __nonzero__ | ||
| __repr__ | ||
| __str__ | ||
| __sub__ | dt value |
|
| max |
Most positivie timedelta object that can be represented
|
|
| min |
Most negative timedelta object that can be represented
|
|
| resolution |
Smallest resolvable difference that a timedelta object can represent
|
