iso_duration

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 3 Imported by: 0

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

View Source
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

func AdvanceDate(dateStr, durationStr string) (advanced string, err error)

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

type Duration struct {
	Years  int
	Months int
	Weeks  int
	Days   int
}

Duration is the parsed date-only subset of an ISO-8601 duration. Time components (hours/minutes/seconds) are intentionally unsupported.

func ParseDuration

func ParseDuration(s string) (duration Duration, err error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL