Skip to main content

tablo_core/values/
zone.rs

1//! The time zone a request shows and reads wall-clock times in.
2
3use jiff::tz::TimeZone;
4use topcoat::context::{Cx, try_context};
5
6/// The time zone the request reads and shows wall-clock times in: the signed-in user's
7/// [`time_zone`](crate::PanelUser::time_zone), else the request panel's
8/// [`time_zone`](crate::Panel::time_zone), else UTC.
9///
10/// A timestamp's control shows its stored instant in this zone and reads the wall-clock time it
11/// posts back in it, and a [`DateColumn`](crate::DateColumn) and a
12/// [`DateFilter`](crate::DateFilter) read a timestamp's calendar day in it.
13///
14/// - `14:00` entered in Paris on 20 October stores `12:00:00Z`. A time the zone skips moves forward
15///   by the gap, and a time it repeats takes the earlier instant; a value posted back untouched
16///   keeps its stored instant, in a repeater's rows too. A value posted with an offset, such as
17///   `2026-10-20T14:00:00-05:00`, names that instant and stores it in UTC. A `min` or `max` refusal
18///   spells the bound as the control shows it.
19/// - A civil date or date-time names its day whatever the zone, but a timestamp's day is the
20///   viewer's: two users in different zones who open the same `?f.starts_at=2026-10-20` see
21///   different rows.
22/// - The stored value is the instant: an export and a [`TextColumn`](crate::TextColumn) spell it in
23///   RFC 3339, in UTC.
24/// - A custom control receives the stored RFC 3339 value and posts a value the panel does not
25///   convert, so it posts an instant with an offset: a wall-clock time is refused.
26/// - [`Schema::read`](crate::Schema::read) reads a timestamp's wall-clock time in this zone too;
27///   [`TypedValue::parse_input`](crate::extend::TypedValue::parse_input) alone refuses one, since
28///   it names no instant.
29pub fn time_zone(cx: &Cx) -> TimeZone {
30    try_context::<ZoneSource>(cx)
31        .and_then(|ZoneSource(session)| session(cx))
32        .unwrap_or(TimeZone::UTC)
33}
34
35/// Finds the zone of the request's user or panel; the first panel mounted on a
36/// router installs it.
37pub(crate) struct ZoneSource(pub(crate) fn(&Cx) -> Option<TimeZone>);