zabgrab.adapters.dates

Parsing of user-supplied times, such as 2026-10-14 09:00 or 24 hours ago.

zabgrab.adapters.dates.EXAMPLES

Examples of times zabgrab understands, for messages.

Type:

str

Functions

parse_time(text, *, now, tz)

Parse a time typed by the user, returning an aware UTC datetime.

timezone_for(name)

Get the time zone for a timezone setting.

zabgrab.adapters.dates.timezone_for(name)[source]

Get the time zone for a timezone setting.

Parameters:

name (str) – "local" or an IANA name such as "Europe/London".

Returns:

tzinfo or None – The time zone, or None for local time.

Return type:

tzinfo | None

zabgrab.adapters.dates.parse_time(text, *, now, tz)[source]

Parse a time typed by the user, returning an aware UTC datetime.

ISO 8601 (2026-10-14, 2026-10-14 09:00, 2026-10-14T09:00:00Z) is parsed exactly. Anything else goes to dateparser, which understands relative times and natural language, with day-first numeric dates (14/10/2026). Times without an explicit offset are in tz (None for local time), and relative times are relative to now.

Parameters:
  • text (str) – The time as typed.

  • now (datetime) – The current time, for relative times.

  • tz (tzinfo or None) – The time zone for times without an offset (None for local time).

Returns:

datetime – The time, as an aware UTC datetime.

Raises:

ValueError – With a message suitable for showing to the user.

Return type:

datetime