time

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 3 Imported by: 0

README

github.com/earlye/eaux/go/time

This package extends "time" by providing some helpers.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApproximateDuration added in v0.0.5

func ApproximateDuration(d ISO8601Duration) time.Duration

ApproximateDuration converts a senseyeio/duration.Duration to a time.Duration. Calendar units use fixed conversions: days and weeks are 24h and 7×24h; months and years are 30 and 365 days. No origin or timezone is used, so the result is a single Go time.Duration value suitable for timeouts, intervals, or other cases where fixed conversion is enough.

func FormatISO8601Duration added in v0.0.4

func FormatISO8601Duration(d time.Duration) string

FormatISO8601Duration converts a time.Duration to an ISO 8601 duration string using only the PT (time) prefix with H, M, and S designators. Durations >= 24h result in a large hour value (e.g. PT1000H30M) rather than using date designators. Sub-second precision is truncated. Negative durations are prefixed with "-".

func ParseISO8601Duration

func ParseISO8601Duration(s string) (time.Duration, error)

ParseISO8601Duration parses an ISO 8601 duration string (e.g. PT5M, P1D) into a time.Duration. Calendar units use fixed conversions: days and weeks are 24h and 7×24h; months and years are 30 and 365 days. No origin or timezone is used, so the result is a single Go time.Duration value suitable for timeouts, intervals, or other cases where fixed conversion is enough.

To shift a specific time by an ISO 8601 duration (e.g. "one day from now" in local time, respecting DST), use github.com/senseyeio/duration: parse with duration.ParseISO8601 and call Shift(origin). Note that Shift uses time.AddDate for months and years, so month boundaries have the usual rollover behavior (e.g. Aug 31 + P1M → Oct 1).

Types

type ISO8601Duration added in v0.0.5

type ISO8601Duration = duration.Duration

Jump to

Keyboard shortcuts

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