Documentation
¶
Overview ¶
Package timefilter is the shared parser for ?from / ?to (and named variants like ?date_from / ?date_to) query parameters across operator-facing list and export endpoints. One contract everywhere so an operator who learns one endpoint doesn't trip on the next.
Accepts two formats:
- RFC3339 instants: "2026-01-01T00:00:00Z" — what the dashboard sends, derived from tenant-TZ start/end-of-day per ADR-010.
- Bare YYYY-MM-DD dates: "2026-01-01" — convenient for curl/CLI users running ad-hoc queries.
Date-only inputs are anchored at UTC: `from` becomes 00:00:00Z (start of day), `to` becomes 23:59:59.999999Z (the last microsecond of the day) so the day named in `to` is included — matches what an operator typing "from=2026-01-01&to=2026-01-31" intuitively expects. The end is the last MICROSECOND, not the last second: Postgres timestamptz keeps microseconds, so a 23:59:59Z bound dropped every row stamped 23:59:59.000001–.999999. It is not .999999999 either: Postgres cannot hold nanoseconds, and whether such a value is truncated or rounded up to the next day's 00:00:00 depends on how it reaches the server.
Consumers do not all compare `to` the same way:
- inclusive (`<= to`): invoice list and invoices.csv, customers.csv, subscriptions.csv, usage-events.csv, the audit log and audit-log.csv (both created_at and sim_effective_at).
- exclusive (`< to`): the usage event list and aggregate (/v1/usage-events, /v1/usage-events/aggregate), all via usage.buildUsageWhere, and customer usage (/v1/customers/{id}/usage, via usage.AggregateClaims).
For a date-only `to` both read the same in practice: the exclusive consumers miss only a row stamped at exactly 23:59:59.999999.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseRange ¶
ParseRange reads two named query params from the request and returns their parsed time.Time values. Missing params return zero-value times (callers branch on IsZero to skip the filter).
Returns errs.Invalid on malformed input — the handler should pipe through respond.FromError, which answers 422 validation_error naming the param. Also rejects an inverted range (`to` before `from`); equal endpoints are allowed (see below).
fromParam and toParam are usually "from"/"to" but the audit log uses the legacy "date_from"/"date_to" naming. Pass whichever the endpoint has historically exposed; this helper doesn't normalize the param names because that would be an operator-visible URL contract change.
Types ¶
This section is empty.