Skip to main content

Crate tztr

Crate tztr 

Source
Expand description

Timezone Translator — convert timestamps between timezones.

Rust port of the Ruby reference implementation (lib/tztr.rb). Kept functionally identical: same timestamp detection, same format preservation, same timezone aliases and resolution. See CLAUDE.md for the parity contract.

Timezone math uses jiff, which reads the system tz database — the same source Ruby’s Time uses via ENV['TZ'] — so DST behavior matches.

Structs§

Assumptions
Which assumptions a line’s timestamps force on us, for -v to disclose.
Group
The range or list a timestamp belongs to, as -j reports it.
Match
One detected timestamp and its analysis, as emitted by [matches].

Enums§

Format
Explicit output format (mirrors Ruby’s --format iso|short|time).
TzError
Why a user-supplied timezone could not be resolved.

Constants§

ZONE_ABBREVIATIONS
Timezone abbreviations tztr recognizes inside text.

Functions§

assumed_date
The date -v says it assumed for this line’s first dateless timestamp: today where it was written. Mirrors Tztr.assumed_date.
assumptions
What converting line would have to assume. See Assumptions.
detect_format
Label the detected format. Mirrors Tztr.detect_format.
detect_zone
The zone a reading ends with. It must start the text or follow a space or digit: EEST is not EST with an E in front. Mirrors Tztr.detect_zone.
ignored_zones
Zone abbreviations written right after a timestamp but not read as one because of their case (Pst), for -v to point out. Mirrors Tztr.ignored_zones.
matches
Per-match structured analysis of a line. With detect, translation is skipped and Match::translated is None. Mirrors Tztr.matches.
matches_bytes
[matches] for input that may not be valid UTF-8. Every match is ASCII, so the Match fields are text either way.
resolve_tz
Resolve a user-supplied zone (alias, numeric offset, or IANA name) to an IANA-style name the system tz database can load. Mirrors Tztr.resolve_tz.
system_zone
The zone the machine runs in, when $TZ doesn’t say: /etc/localtime’s link into the tzdb (macOS, most Linux), else Debian’s /etc/timezone. Mirrors Tztr.system_zone.
timezone_aliases
All timezone aliases as (alias, IANA name) pairs, sorted by alias.
today_in_zone
Today’s date in tz as YYYY-MM-DD.
translate
Translate every detected timestamp in line, preserving surrounding text. to/from accept aliases; from is the assumed input zone for naive timestamps; date supplies a reference date for time-only inputs.
translate_bytes
translate for input that may not be valid UTF-8 — a log line with a stray byte in it. Timestamps still convert; every other byte, valid or not, comes out exactly as it went in.
unknown_zones
Zone-shaped words a date(1) line carries that tztr doesn’t know (EEST), for -v to name as the reason the line was left alone.