dates

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 4 Imported by: 0

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

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

func IsRelativeDateKeyword(value string) bool

IsRelativeDateKeyword reports whether value is a supported relative date keyword.

func IsValidDate

func IsValidDate(s string) bool

IsValidDate checks if a string is a valid YYYY-MM-DD date.

func IsValidDatetime

func IsValidDatetime(s string) bool

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

func NormalizeRelativeDateKeyword(value string) (string, bool)

NormalizeRelativeDateKeyword normalizes and validates a relative date keyword. Returns the canonical keyword and true when valid.

func ParseDate

func ParseDate(s string) (time.Time, error)

ParseDate parses a YYYY-MM-DD date.

func ParseDateArg

func ParseDateArg(arg string, now time.Time) (time.Time, error)

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

func ParseDatetime

func ParseDatetime(s string) (time.Time, error)

ParseDatetime parses a datetime in one of the accepted formats.

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".

Jump to

Keyboard shortcuts

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