Skip to main content

Module time

Module time 

Source
Expand description

Project-wide locale + timezone helpers. Every fetcher / renderer that emits a human-readable timestamp goes through here so the same [general] defaults (and per-widget overrides) drive every clock-shaped output instead of each site reaching for Local::now() / Utc::now() independently.

  • now_in(tz) resolves an IANA name ("Asia/Tokyo") to a fixed-offset DateTime. Falls back to Local for unknown names — never panics.
  • today_in(tz) is the date-only counterpart for “today” math.
  • parse_locale(name) resolves a chrono::Locale from "en_US" / "ja_JP". Falls back to POSIX (chrono’s hard-coded English).
  • format_local(dt, fmt, locale) is chrono::format_localized with a directive-error fallback so a typo’d %Q doesn’t crash the splash.
  • format_relative_compact(seconds, locale) is the 3h / 2d / 1w rounding used by list_timeline and friends. Locale only flips the suffix glyphs; the math is locale-independent.

Behaviour with tz = None and locale = None matches the pre-migration Local::now() + format(...) output bit-for-bit (POSIX is what chrono’s unlocalised format already emits), so call sites can migrate without having to compare snapshots.

Constants§

DEFAULT_LOCALE

Functions§

format_local
format_relative_compact
3h / 2d / 1w style label for seconds_ago. Future deltas grow an in prefix; sub-minute deltas collapse to now. Returns None when the delta exceeds ~4 weeks so callers can fall back to an absolute date.
now_in
parse_locale
parse_tz
today_in