Tempo.Sigils (Tempo v2.1.1)

Copy Markdown View Source

The ~o sigil: an ISO 8601 text read at compile time.

In an expression, ~o"2026-06-15" is the %Tempo{} the text names, read once when the module compiles, so a text that cannot be read is a compile error. A duration text is a %Tempo.Duration{}.

In a pattern, the sigil is a structural match on the form the text names. A value matches every value whose units begin with the units written, so ~o"2026-06" matches ~o"2026-06-15" and ~o"2026-06-15T10", and no other field is constrained: a Gregorian-looking sigil matches a value of another calendar. An interval, a set or a recurrence matches that form exactly.

iex> import Tempo.Sigils
iex> match?(~o"2026-06", ~o"2026-06-15")
true
iex> match?(~o"2026-06", ~o"2026-07-15")
false

Summary

Functions

Reads an ISO 8601 text into an expression at compile time, or into a pattern that matches one.

Functions

sigil_o(arg1, modifiers)

(macro)

Reads an ISO 8601 text into an expression at compile time, or into a pattern that matches one.

Arguments

  • The sigil's text, an ISO 8601 text as Tempo reads it. It is a literal: a text with an interpolation is refused, since it would be read at compile time.

  • modifiers, which ~o takes none of.

Returns

  • The expression or the duration the text reads to, built when the code is compiled, or a pattern matching it where the sigil is in a pattern. A text that does not read is a compile error naming why.

Examples

iex> ~o"2026-06-15"
Tempo.from_iso8601!("2026-06-15")

iex> ~o"P1Y2M"
Tempo.Duration.new!(year: 1, month: 2)