gws.lib.datetimex
¶
Date and time utilities.
These utilities are wrappers around the datetime
module,
some functions also use pendulum
(https://pendulum.eustace.io/),
however all functions here return strictly stock datetime.datetime
objects.
date
objects are silently promoted to datetime
with time set to midnight UTC.
time
objects are silently promoted to datetime
in the local timezone with the today’s date.
This module always returns timezone-aware objects.
When constructing an object (e.g. from a string), the default time zone should be passed
as a zoneinfo string (like Europe/Berlin
). An empty zoneinfo string (default) means the local time zone.
Alias names like CEST
are not supported.
Naive datetime arguments are assumed to be in the local time zone.
When running in a docker container, there are several ways to set up the local time zone:
by setting the config variable
server.timeZone
(seegws.config.parser
)by setting the
TZ
environment variablemounting a host zone info file to
/etc/localtime
Source code: gws.lib.datetimex
Package Contents¶
- gws.lib.datetimex.add(d: datetime.date | None = None, years=0, months=0, days=0, weeks=0, hours=0, minutes=0, seconds=0, microseconds=0) datetime.datetime ¶
- gws.lib.datetimex.day_of_week(d: datetime.date | None = None) int ¶
- gws.lib.datetimex.day_of_year(d: datetime.date | None = None) int ¶
- gws.lib.datetimex.days_in_month(d: datetime.date | None = None) int ¶
- class gws.lib.datetimex.Diff¶
- days: int¶
- hours: int¶
- microseconds: int¶
- minutes: int¶
- months: int¶
- seconds: int¶
- weeks: int¶
- years: int¶
- gws.lib.datetimex.end_of_day(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.end_of_hour(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.end_of_minute(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.end_of_month(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.end_of_second(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.end_of_week(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.end_of_year(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.from_iso_string(s: str, tz: str = '') datetime.datetime ¶
- gws.lib.datetimex.from_iso_time_string(s: str, tz: str = '') datetime.datetime ¶
- gws.lib.datetimex.from_string(s: str, tz: str = '') datetime.datetime ¶
- gws.lib.datetimex.from_timestamp(n: float, tz: str = '') datetime.datetime ¶
- gws.lib.datetimex.is_date(x) bool ¶
- gws.lib.datetimex.is_datetime(x) bool ¶
- gws.lib.datetimex.is_local(d: datetime.datetime) bool ¶
- gws.lib.datetimex.is_utc(d: datetime.datetime) bool ¶
- gws.lib.datetimex.mock_now(d)¶
- gws.lib.datetimex.new(year, month, day, hour=0, minute=0, second=0, microsecond=0, fold=0, tz: str = '') datetime.datetime ¶
- gws.lib.datetimex.next(day: int | str, d: datetime.date | None = None, keep_time=False) datetime.datetime ¶
- gws.lib.datetimex.now(tz: str = '') datetime.datetime ¶
- gws.lib.datetimex.now_utc() datetime.datetime ¶
- gws.lib.datetimex.parse(s: str | datetime.datetime | datetime.date | None, tz: str = '') datetime.datetime | None ¶
- gws.lib.datetimex.parse_duration(s: str) int ¶
Converts weeks, days, hours or minutes to seconds.
- Parameters:
s – Time of duration.
- Returns:
Input as seconds.
- Raises:
ValueError – if the duration is invalid.
- gws.lib.datetimex.parse_time(s: str | datetime.time | None, tz: str = '') datetime.datetime | None ¶
- gws.lib.datetimex.prev(day: int | str, d: datetime.date | None = None, keep_time=False) datetime.datetime ¶
- gws.lib.datetimex.set_local_time_zone(tz: str)¶
- gws.lib.datetimex.start_of_day(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.start_of_hour(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.start_of_minute(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.start_of_month(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.start_of_second(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.start_of_week(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.start_of_year(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.time_zone(tz: str = '') zoneinfo.ZoneInfo ¶
- gws.lib.datetimex.to_basic_string(d: datetime.date | None = None) str ¶
- gws.lib.datetimex.to_iso_date_string(d: datetime.date | None = None) str ¶
- gws.lib.datetimex.to_iso_string(d: datetime.date | None = None, with_tz='+', sep='T') str ¶
- gws.lib.datetimex.to_iso_time_string(d: datetime.date | None = None, with_tz='+') str ¶
- gws.lib.datetimex.to_local(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.to_millis(d: datetime.date | None = None) int ¶
- gws.lib.datetimex.to_string(fmt: str, d: datetime.date | None = None) str ¶
- gws.lib.datetimex.to_time_zone(tz: str, d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.to_timestamp(d: datetime.date | None = None) int ¶
- gws.lib.datetimex.to_utc(d: datetime.date | None = None) datetime.datetime ¶
- gws.lib.datetimex.today(tz: str = '') datetime.datetime ¶
- gws.lib.datetimex.today_utc() datetime.datetime ¶
- gws.lib.datetimex.UTC¶
- gws.lib.datetimex.week_of_month(d: datetime.date | None = None) int ¶
- gws.lib.datetimex.week_of_year(d: datetime.date | None = None) int ¶