timeutil

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const RFC3339Micro = "2006-01-02T15:04:05.000000Z07:00"

Layout of RFC 3339 text with exactly six fractional digits and Z for a zero offset, fixed width so stamps of one offset sort as text in time order

Variables

This section is empty.

Functions

func Epoch

func Epoch(t time.Time) float64

Seconds since the Unix epoch of t as a float, to the nanosecond as far as a float64 holds it

func FromEpoch

func FromEpoch(ts float64) time.Time

Local instant of float seconds since the Unix epoch to the nanosecond, the zero Time for NaN, infinities and instants outside the years 1 to 9999

func Monotonic

func Monotonic() float64

Seconds on the system monotonic clock counted from boot, so a zero stamp always reads as long ago and the difference of two readings is the elapsed time

func ParseISO

func ParseISO(s string, loc *time.Location) (time.Time, error)

Instant of ISO 8601 text, a calendar, week or ordinal date alone or with a time of day, read as wall time in loc when the text carries no UTC offset and in UTC when loc is nil too; 24:00 is the next midnight and a leap second :60 the first instant of the next minute

func ParseISOZone

func ParseISOZone(s string, loc *time.Location) (time.Time, bool, error)

Instant of ISO 8601 text as ParseISO reads it, also reporting whether the text carried Z or a UTC offset

func RelativeAge

func RelativeAge(v any, sessionID string, now time.Time) string

Age of a stored timestamp cell as just now, 5m ago, 3h ago, yesterday or 4d ago, its local date when older and ? when unset, zero or corrupt

func StoredEpoch

func StoredEpoch(v any, sessionID, field string) (float64, bool)

Epoch seconds a stored timestamp cell holds, false for unset and corrupt values, a warning naming the field and session logged for corrupt ones

func Strftime

func Strftime(t time.Time, format string) string

Text of t laid out by a C strftime format in the C locale: the glibc conversions with their _ - 0 ^ # flags, widths and E or O modifiers, plus %f for microseconds and %:z for a colon offset; an unknown conversion stays as written

func StrictDate

func StrictDate(year int, month time.Month, day, hour, minute, second, nsec int, loc *time.Location) (time.Time, error)

Instant time.Date builds from the fields, or a *RangeError naming the first field time.Date would have normalized; nil loc means UTC

func YAMLTimestamp

func YAMLTimestamp(text string) (v any, ok bool, err error)

Value a YAML 1.1 timestamp scalar holds, a Date for yyyy-mm-dd and else a time.Time that is UTC without a zone and in a fixed zone, even for Z, with one; ok is false when the text is no timestamp

Types

type Date

type Date struct {
	Year  int
	Month time.Month
	Day   int
}

Calendar date with no time of day, what a bare YAML date such as 2001-12-14 loads to

func (Date) MarshalText

func (d Date) MarshalText() ([]byte, error)

Date in yyyy-mm-dd form, so JSON and other text encoders write it as a plain date string

func (Date) Midnight

func (d Date) Midnight(loc *time.Location) time.Time

Instant the date starts at in loc, UTC when loc is nil

func (Date) String

func (d Date) String() string

Date in yyyy-mm-dd form

type ParseError

type ParseError struct {
	Form string
	Text string
	Err  error
}

Text that is not a date or time of the form a parser expects, Err holding the *RangeError when a field is out of range

func (*ParseError) Error

func (e *ParseError) Error() string

Form expected, the text quoted and the out of range field when that is the reason

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

Out of range field error the text failed on, nil for a syntax error

type RangeError

type RangeError struct {
	Field    string
	Value    int
	Min, Max int
}

Calendar or clock field outside its range

func (*RangeError) Error

func (e *RangeError) Error() string

Field name, its allowed range and the value given

Jump to

Keyboard shortcuts

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