Kathikon.Timezone (Kathikon v0.2.1)

Copy Markdown View Source

Timezone helpers for Kathikon scheduling.

Configure the application timezone with:

config :kathikon, timezone: "America/New_York"

Requires a time zone database (tzdata is included as a dependency):

config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase

Behaviour

  • :schedule_at and scheduler :at accept DateTime (any zone) or NaiveDateTime (interpreted as wall clock in the configured timezone)
  • Cron expressions and presets (@daily, etc.) match against local time
  • :schedule_in stays relative to UTC instants (duration-based)
  • All persisted timestamps remain UTC

Summary

Functions

Returns the configured IANA timezone name.

Returns the current time in the configured timezone.

Normalizes insert/schedule options, converting :schedule_at to UTC.

Normalizes a schedule target to UTC for storage and comparison.

Converts a UTC DateTime to the configured timezone.

Converts a wall-clock time in the configured timezone to UTC.

Returns the current UTC instant.

Functions

configured()

@spec configured() :: String.t()

Returns the configured IANA timezone name.

local_now()

@spec local_now() :: DateTime.t()

Returns the current time in the configured timezone.

normalize_opts(opts)

@spec normalize_opts(keyword()) :: {:ok, keyword()} | {:error, term()}

Normalizes insert/schedule options, converting :schedule_at to UTC.

normalize_schedule_at(naive)

@spec normalize_schedule_at(NaiveDateTime.t() | DateTime.t()) ::
  {:ok, DateTime.t()} | {:error, term()}

Normalizes a schedule target to UTC for storage and comparison.

to_local(utc)

@spec to_local(DateTime.t()) :: DateTime.t()

Converts a UTC DateTime to the configured timezone.

to_utc(naive)

@spec to_utc(NaiveDateTime.t() | DateTime.t()) ::
  {:ok, DateTime.t()} | {:error, term()}

Converts a wall-clock time in the configured timezone to UTC.

Accepts NaiveDateTime or DateTime (shifted to UTC).

utc_now()

@spec utc_now() :: DateTime.t()

Returns the current UTC instant.