Chronix.Range (Chronix v0.2.0)

Copy Markdown View Source

Resolves a Chronix expression into the inclusive {start, finish} interval it denotes. Prefer the top-level Chronix.parse_range/2.

Accepts exactly the expressions Chronix.parse/2 accepts and classifies each parsed AST into one of three interval shapes:

  • Calendar periodslast/this/next week|month|year expand to the full calendar bounds of that period relative to the reference date (ISO weeks run Monday through Sunday). Note that this differs from Chronix.parse/2, where "this week" resolves to the bare reference date: as a range it means the current week's calendar bounds.
  • Whole days — expressions that denote a day without a time-of-day: today, yesterday, tomorrow, day-offset aliases, explicit dates (7/1/2026, 2026-07-01), word dates (January 1, 2025), weekday expressions (next monday), and relative shifts in day-or-coarser integer units (3 days ago, in 2 weeks). These expand from 00:00:00.000000 to 23:59:59.999999 of the day the expression resolves to.
  • Instants — everything carrying a time-of-day or resolving to a point in time: now, noon, 3 hours ago, tomorrow at 3pm, ISO-8601 timestamps, beginning of/end of boundaries, and fractional day-unit shifts (1.5 days ago). These become zero-width ranges {instant, instant}.

The end of every non-instant range is the last representable microsecond of the period, matching the "end of ..." boundary semantics.

All arithmetic happens in whatever time zone the reference date carries; callers are responsible for normalizing zones beforehand.

Summary

Functions

Parses date_string and resolves it to an inclusive {start, finish} interval. See the module docs for the classification rules and Chronix.parse_range/2 for examples.

Types

result()

@type result() :: {:ok, t()} | {:error, String.t()}

t()

@type t() :: {DateTime.t(), DateTime.t()}

Functions

parse(date_string, opts \\ [])

@spec parse(
  String.t(),
  keyword()
) :: result()

Parses date_string and resolves it to an inclusive {start, finish} interval. See the module docs for the classification rules and Chronix.parse_range/2 for examples.