Documentation
¶
Overview ¶
Package iso_duration parses the date-only subset of ISO-8601 durations (PnY nM nW nD) and advances a YYYY-MM-DD date by such a duration. It exists so the commit-time on_commit_fields lua hooks can recur an actionable object's `due` date: gopher-lua ships no date library, so AdvanceDate is registered as a host function in the hook VM (see tag_blobs.MakeLuaSelfApplyV1).
Index ¶
Constants ¶
const DateFormat = "2006-01-02"
DateFormat is the layout of the `due` field this package reads and writes: a date-only YYYY-MM-DD string.
Variables ¶
This section is empty.
Functions ¶
func AdvanceDate ¶
AdvanceDate advances dateStr (in DateFormat, YYYY-MM-DD) by the ISO-8601 duration in durationStr (the PnY nM nW nD subset), returning the advanced date in the same format. Month/year arithmetic uses time.AddDate, so overflowing day-of-month values normalize forward (e.g. Jan 31 + P1M lands in early March). It errors on an unparseable date or duration.
Types ¶
type Duration ¶
Duration is the parsed date-only subset of an ISO-8601 duration. Time components (hours/minutes/seconds) are intentionally unsupported.
func ParseDuration ¶
ParseDuration parses the date-only subset of an ISO-8601 duration string of the form P[nY][nM][nW][nD] (e.g. "P1D", "P2W", "P1M", "P1Y", "P1M2W"). It errors on the empty string, a string not beginning with 'P', a "P" with no components, an unrecognised designator (including the time 'T' separator and H/M/S time units), or a number with no trailing unit.