LiveFilter.DateUtils (LiveFilter v0.1.8)

Copy Markdown View Source

Date utility functions for LiveFilter. Handles date range calculations for presets and custom ranges.

Summary

Functions

Generates weekly chunks for calendar display. Returns a list of weeks, where each week is a list of 7 dates.

Returns the default list of date presets in chronological order.

Formats a date for display in the filter chip. Handles both Date structs and ISO8601 strings.

Formats a date range for display. Returns "Feb 14, 2026" for same-day ranges, "Feb 1 - Feb 14, 2026" for multi-day. Handles both Date structs and ISO8601 strings.

Checks if a date is within the selected range (exclusive of endpoints).

Parses a preset atom into a date range tuple {start_date, end_date}.

Returns a human-readable label for a preset.

Checks if a date is selected (start or end of range).

Functions

calendar_weeks(month)

@spec calendar_weeks(Date.t()) :: [[Date.t()]]

Generates weekly chunks for calendar display. Returns a list of weeks, where each week is a list of 7 dates.

default_presets()

@spec default_presets() :: [atom()]

Returns the default list of date presets in chronological order.

format_date(date)

@spec format_date(Date.t() | DateTime.t() | String.t() | nil) :: String.t()

Formats a date for display in the filter chip. Handles both Date structs and ISO8601 strings.

format_range(arg)

@spec format_range({Date.t() | String.t() | nil, Date.t() | String.t() | nil}) ::
  String.t()

Formats a date range for display. Returns "Feb 14, 2026" for same-day ranges, "Feb 1 - Feb 14, 2026" for multi-day. Handles both Date structs and ISO8601 strings.

in_range?(date, start_date, end_date)

@spec in_range?(Date.t(), Date.t() | nil, Date.t() | nil) :: boolean()

Checks if a date is within the selected range (exclusive of endpoints).

parse_preset(preset)

@spec parse_preset(atom()) :: {Date.t() | nil, Date.t() | nil}

Parses a preset atom into a date range tuple {start_date, end_date}.

Special cases:

  • :overdue returns {nil, yesterday} for open-ended past range

preset_label(preset)

@spec preset_label(atom()) :: String.t()

Returns a human-readable label for a preset.

selected?(date, start_date, end_date)

@spec selected?(Date.t(), Date.t() | nil, Date.t() | nil) :: boolean()

Checks if a date is selected (start or end of range).