Dayoff.Data (Dayoff v0.2.0)

Copy Markdown View Source

Access to the holiday dataset in priv/data/holidays.json.

The file is decoded once into :persistent_term on first use. Rules for a country, state and region are merged the way the reference implementation merges them and cached per selection, so repeated calls are cheap.

Codes are what the dataset uses: uppercase ISO 3166-1 country codes and the upstream state and region codes ("CA", "BY", "07", "KATH"). All of them are strings, and a lowercase country code is accepted.

Summary

Types

Country, state and region selection.

Functions

The country entry, or the state or region entry when selected.

A field looked up from the region, then the state, then the country, the first one that has it. The reference implementation never reaches the region level here because of a typo; dayoff does.

The decoded dataset: holidays by country code and the shared names.

The rules for a selection: country rules, then the state's, then the region's, each level overriding by exact rule string, false deleting a rule, and _name references resolved from the shared names. Cached.

Normalizes a country, state and region into a selection, raising ArgumentError with the known codes when something doesn't exist.

What mix dayoff.sync recorded about the upstream commits.

Types

selection()

@type selection() :: %{
  country: String.t(),
  state: String.t() | nil,
  region: String.t() | nil
}

Country, state and region selection.

Functions

entry(map)

@spec entry(selection()) :: map()

The country entry, or the state or region entry when selected.

inherited(selection, key)

@spec inherited(selection(), String.t()) :: term()

A field looked up from the region, then the state, then the country, the first one that has it. The reference implementation never reaches the region level here because of a typo; dayoff does.

raw()

@spec raw() :: map()

The decoded dataset: holidays by country code and the shared names.

rules(selection)

@spec rules(selection()) :: %{required(String.t()) => map()}

The rules for a selection: country rules, then the state's, then the region's, each level overriding by exact rule string, false deleting a rule, and _name references resolved from the shared names. Cached.

selection!(country, opts \\ [])

@spec selection!(String.t(), keyword()) :: selection()

Normalizes a country, state and region into a selection, raising ArgumentError with the known codes when something doesn't exist.

country may carry the state and region separated by dashes ("US-CA", "DE-BY-A"), as the reference implementation allows.

version()

@spec version() :: map()

What mix dayoff.sync recorded about the upstream commits.