Skip to main content

Module dates

Module dates 

Source
Expand description

Calendar values for templates: run.date, run.now, date(), datetime() and the periods built from them. Everything is worked out at render time, so compiled SQL holds literals and a rerun with the same DRE_RUN_DATE renders the same text.

Three types:

  • Date: a calendar day. Renders YYYY-MM-DD.
  • DateTime: an instant, shown in a timezone. Renders YYYY-MM-DD HH:MM:SS[.ffffff].
  • Period: a run of whole days (a week, a month, …). start and end are its first and last instants; start.date and end.date its first and last days.

A Calendar (the run’s timezone, first day of the week and week numbering) travels with every value, so navigation and conversions agree with the project’s settings.

Structs§

Calendar
The settings every date value carries.
Date
DateTime
Period

Enums§

WeekNumbering
How weeks are numbered: iso (week 1 holds the year’s first Thursday) or us (week 1 holds 1 January).
WeekStart
The first day of a week.

Constants§

DATE_ATTRS
Every attribute of a Date, for dre validate’s check of run.date.<name>.
PERIOD_PRESETS
The named periods period() knows.

Functions§

parse_tz
Parse an IANA timezone name (Australia/Sydney, UTC).
register
Add date(), datetime(), period(), date_range(), month_of(), quarter_of(), year_of(), week_of() and the as_date / as_datetime filters. run_date is what period() counts from by default.