Documentation
¶
Overview ¶
Package dates provides canonical date/datetime parsing and validation helpers.
This package exists to avoid duplicating date parsing logic across: - schema validation - vault/CLI date args - check validation - index/query date filters - reference resolution (date shorthand)
Index ¶
- Constants
- func IsRelativeDateKeyword(value string) bool
- func IsValidDate(s string) bool
- func IsValidDatetime(s string) bool
- func NormalizeRelativeDateKeyword(value string) (string, bool)
- func ParseDate(s string) (time.Time, error)
- func ParseDateArg(arg string, now time.Time) (time.Time, error)
- func ParseDatetime(s string) (time.Time, error)
- type RelativeDateKind
- type RelativeDateResolution
Constants ¶
const ( // DateLayout is the Go time layout for YYYY-MM-DD dates. DateLayout = "2006-01-02" // DatetimeLayout is the Go time layout for YYYY-MM-DDTHH:MM datetimes. DatetimeLayout = "2006-01-02T15:04" // DatetimeSecondsLayout is the Go time layout for YYYY-MM-DDTHH:MM:SS datetimes. DatetimeSecondsLayout = "2006-01-02T15:04:05" )
Date format constants - use these instead of string literals.
Variables ¶
This section is empty.
Functions ¶
func IsRelativeDateKeyword ¶ added in v0.0.3
IsRelativeDateKeyword reports whether value is a supported relative date keyword.
func IsValidDate ¶
IsValidDate checks if a string is a valid YYYY-MM-DD date.
func IsValidDatetime ¶
IsValidDatetime checks if a string is a valid datetime.
Accepted formats (preserving current behavior): - RFC3339 (e.g. 2025-01-01T10:30:00Z, 2025-06-15T14:00:00+05:00) - YYYY-MM-DDTHH:MM - YYYY-MM-DDTHH:MM:SS
func NormalizeRelativeDateKeyword ¶ added in v0.0.3
NormalizeRelativeDateKeyword normalizes and validates a relative date keyword. Returns the canonical keyword and true when valid.
func ParseDateArg ¶
ParseDateArg parses a CLI date argument which can be: - "today", "yesterday", "tomorrow" (relative dates) - "YYYY-MM-DD" format (absolute date) - Empty string defaults to today
Types ¶
type RelativeDateKind ¶ added in v0.0.3
type RelativeDateKind int
RelativeDateKind describes whether a relative date keyword resolves to a single date.
const ( RelativeDateUnknown RelativeDateKind = iota RelativeDateInstant )
type RelativeDateResolution ¶ added in v0.0.3
type RelativeDateResolution struct {
Keyword string
Kind RelativeDateKind
Date time.Time
}
RelativeDateResolution is the resolved representation of a relative date keyword.
func ResolveRelativeDateKeyword ¶ added in v0.0.3
func ResolveRelativeDateKeyword(value string, now time.Time, _ time.Weekday) (RelativeDateResolution, bool)
ResolveRelativeDateKeyword resolves a relative date keyword using the provided "now".