dates
Utilities for working with dates and times.
Attention
This module has the following additional None:
pytz>=2019.1
This can be installed as follows:
python -m pip install domdf-python-tools[dates]
Data:
Mapping of 3-character shortcodes to full month names. |
|
List of the full names for months in the Gregorian calendar. |
|
List of the short names for months in the Gregorian calendar. |
Functions:
|
Returns the date of Easter in the given year. |
|
Returns |
Returns a tzinfo object for the current timezone. |
|
|
Returns the number of the given month. |
|
Returns a localized |
|
Returns the offset between UTC and the requested timezone on the given date. |
|
Calculates whether the given day falls within British Summer Time. |
|
Converts an integer or shorthand month into the full month name. |
|
Sets the timezone / tzinfo of the given |
|
Convert UTC timestamp (seconds from UNIX epoch) to a |
-
check_date
(month, day, leap_year=True)[source] Returns
True
if the day number is valid for the given month.
-
get_month_number
(month)[source] Returns the number of the given month. If
month
is already a number between 1 and 12 it will be returned immediately.
-
get_timezone
(tz, date=None)[source] Returns a localized
pytz.timezone
object for the given date.If
date
isNone
then the current date is used.
-
get_utc_offset
(tz, date=None)[source] Returns the offset between UTC and the requested timezone on the given date. If
date
isNone
then the current date is used.
-
is_bst
(the_date)[source] Calculates whether the given day falls within British Summer Time.
This function should also be applicable to other timezones which change to summer time on the same date (e.g. Central European Summer Time).
Note
This function does not consider the time of day, and therefore does not handle the fact that the time changes at 1 AM GMT. It also does not account for historic deviations from the current norm.
New in version 3.5.0.
- Parameters
the_date (
Union
[struct_time
,date
]) – Atime.struct_time
,datetime.date
ordatetime.datetime
representing the target date.- Return type
- Returns
True
if the date falls within British Summer Time,False
otherwise.
-
set_timezone
(obj, tzinfo)[source] Sets the timezone / tzinfo of the given
datetime.datetime
object. This will not convert the time (i.e. the hours will stay the same). Usedatetime.datetime.astimezone()
to accomplish that.
-
utc_timestamp_to_datetime
(utc_timestamp, output_tz=None)[source] Convert UTC timestamp (seconds from UNIX epoch) to a
datetime.datetime
object.If
output_tz
isNone
the timestamp is converted to the platform’s local date and time, and the local timezone is inferred and set for the object.If
output_tz
is notNone
, it must be an instance of adatetime.tzinfo
subclass, and the timestamp is converted tooutput_tz
’s time zone.- Parameters
- Return type
- Returns
The timestamp as a datetime object.
- Raises
OverflowError – if the timestamp is out of the range of values supported by the platform C localtime() or gmtime() functions, and OSError on localtime() or gmtime() failure. It’s common for this to be restricted to years in 1970 through 2038.
-
months
Type:
OrderedDict
[str
,str
]Mapping of 3-character shortcodes to full month names.
Essentially:
months = { Jan="January", Feb="February", Mar="March", Apr="April", May="May", ..., Dec="December", }