Skip to main content

Module dates

Module dates 

Source
Expand description

Date helpers for PDF document metadata.

krilla’s Metadata::creation_date takes a DateTime built from year/month/day/hour/minute/second/utc-offset components. This module converts from the most common sources:

  • ISO date / datetime strings ("2025-11-04" or "2025-11-04T08:30:00Z") commonly found in Markdoc frontmatter.
  • The current system time, for build-time stamping.

Functions§

copyright_year_span
Format a copyright year span. A single year when the first-release year is absent or equals current, otherwise first–current joined with an en dash. Examples: "2026", "2024–2026".
current_year
The current calendar year (local time, UTC fallback).
iso_to_date_only
Re-format a YYYY-MM-DD… ISO string into a clean YYYY-MM-DD (drops any time/offset component). Returns the input unchanged when parsing fails, so the templater always has something to substitute.
now
Current system time as a krilla DateTime. Falls back to UTC if the local timezone offset can’t be determined (e.g. in containerised environments without /etc/localtime).
parse_iso
Parse a permissive ISO date / datetime string into a krilla DateTime. Accepts:
today_yyyy_mm_dd
Today as YYYY-MM-DD (UTC fallback). Used by the renderer to drive the {date} header/footer template variable when the caller hasn’t supplied an explicit date string.
year_of
Parse the four-digit year out of an ISO date string (2024-07-30…). Returns None when the leading token isn’t a plausible year.