SagentsLiveDebugger.Timezone (Sagents LiveDebugger v0.4.0-rc.2)

Copy Markdown

Helpers for validating IANA timezone strings received from the browser.

The debugger passes the browser's detected timezone (from Intl.DateTimeFormat().resolvedOptions().timeZone) through the LiveSocket connect_params as "time_zone". This module ensures that only valid zones known to Tzdata make it into socket state, so downstream DateTime.shift_zone/3 calls cannot crash when rendering event timestamps.

Summary

Functions

Validates a timezone string against Tzdata.TimeZoneDatabase.

Validates a timezone and falls back to "UTC" on any failure.

Functions

validate(timezone)

@spec validate(any()) :: {:ok, String.t()} | {:error, :invalid_timezone}

Validates a timezone string against Tzdata.TimeZoneDatabase.

Returns {:ok, timezone} for recognized zones, {:error, :invalid_timezone} otherwise (including for nil or non-binary input).

validate_or_utc(timezone)

@spec validate_or_utc(any()) :: String.t()

Validates a timezone and falls back to "UTC" on any failure.