temporal

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 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

Overview

Package temporal implements the Cypher temporal types: DATE, LOCAL TIME, ZONED TIME, LOCAL DATETIME, ZONED DATETIME and DURATION. It covers construction (from strings, maps and other temporal values), component access, truncation, arithmetic, comparison, duration.between and the canonical string rendering that Cypher uses for output and storage.

The package depends only on the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b Value) (cmp int, ok bool)

Compare orders two values of the same orderable kind. ok is false for durations and for values of different kinds.

func Equal

func Equal(a, b Value) bool

Equal reports whether two temporal values are equal. Values of different kinds are never equal.

func Property

func Property(v Value, name string) (any, bool)

Property returns a component of a temporal value, e.g. d.year or t.offset. ok is false when the value has no such component.

Types

type Date

type Date struct {
	// contains filtered or unexported fields

} // midnight UTC

Date is a calendar date.

func (Date) Day

func (d Date) Day() int

func (Date) DayOfQuarter

func (d Date) DayOfQuarter() int

DayOfQuarter is the 1-based day within the quarter.

func (Date) Kind

func (Date) Kind() Kind

func (Date) Month

func (d Date) Month() int

func (Date) Ordinal

func (d Date) Ordinal() int

func (Date) Quarter

func (d Date) Quarter() int

func (Date) String

func (d Date) String() string

func (Date) Week

func (d Date) Week() int

Week is the ISO week number.

func (Date) WeekDay

func (d Date) WeekDay() int

WeekDay is the ISO day of the week, Monday = 1 … Sunday = 7.

func (Date) WeekYear

func (d Date) WeekYear() int

WeekYear is the ISO week-numbering year.

func (Date) Year

func (d Date) Year() int

type DateTime

type DateTime struct {
	// contains filtered or unexported fields
}

DateTime is a date and time with a UTC offset and optionally a region zone.

func FromEpoch

func FromEpoch(seconds, nanos int64) DateTime

FromEpoch builds a UTC datetime from seconds and nanoseconds since the Unix epoch.

func FromEpochMillis

func FromEpochMillis(ms int64) DateTime

FromEpochMillis builds a UTC datetime from milliseconds since the Unix epoch.

func (DateTime) Kind

func (DateTime) Kind() Kind

func (DateTime) Offset

func (t DateTime) Offset() int

Offset is the UTC offset in seconds.

func (DateTime) String

func (t DateTime) String() string

func (DateTime) ZoneName

func (t DateTime) ZoneName() string

ZoneName is the region name, or the offset rendering for fixed offsets.

type Duration

type Duration struct {
	Months  int64
	Days    int64
	Seconds int64
	Nanos   int64 // 0 <= Nanos < 1e9; the sign of the whole is carried by Seconds
}

Duration is an amount of time in months, days and seconds, kept separately because months and days have no fixed length.

func Between

func Between(op string, a, b Value) (Duration, error)

Between computes duration.between (op "between"), duration.inMonths, duration.inDays or duration.inSeconds of two temporal values.

func (Duration) Div

func (d Duration) Div(f float64) (Duration, error)

Div divides d by f.

func (Duration) Kind

func (Duration) Kind() Kind

func (Duration) Minus

func (d Duration) Minus(o Duration) (Duration, error)

Minus returns d - o.

func (Duration) Neg

func (d Duration) Neg() Duration

Neg returns -d.

func (Duration) Plus

func (d Duration) Plus(o Duration) (Duration, error)

Plus returns d + o.

func (Duration) Scale

func (d Duration) Scale(f float64) (Duration, error)

Scale multiplies d by f, cascading fractional months and days like the constructors do.

func (Duration) String

func (d Duration) String() string

String renders the duration in ISO 8601 form, e.g. P1Y2M3DT4H5M6.5S. The sign of each component is kept, so mixed signs render as P1M-2DT3H.

type Kind

type Kind int

Kind identifies a temporal type.

const (
	KindDate Kind = iota + 1
	KindLocalTime
	KindTime
	KindLocalDateTime
	KindDateTime
	KindDuration
)

func KindByName

func KindByName(name string) (Kind, bool)

KindByName returns the kind a constructor function name refers to.

func (Kind) Name

func (k Kind) Name() string

Name is the Cypher function name that constructs the kind.

type LocalDateTime

type LocalDateTime struct {
	// contains filtered or unexported fields

} // wall clock, labelled UTC

LocalDateTime is a date and time without a zone.

func (LocalDateTime) Kind

func (LocalDateTime) Kind() Kind

func (LocalDateTime) String

func (t LocalDateTime) String() string

type LocalTime

type LocalTime struct {
	// contains filtered or unexported fields

} // nanoseconds since midnight

LocalTime is a time of day without a zone.

func (LocalTime) Kind

func (LocalTime) Kind() Kind

func (LocalTime) String

func (t LocalTime) String() string

type Time

type Time struct {
	// contains filtered or unexported fields
}

Time is a time of day with a UTC offset.

func (Time) Kind

func (Time) Kind() Kind

func (Time) String

func (t Time) String() string

type Value

type Value interface {
	Kind() Kind
	String() string
}

Value is a temporal value. Its String method is the canonical Cypher rendering, which Parse accepts back.

func Add

func Add(a, b Value) (Value, error)

Add returns a + b for the supported combinations: temporal + duration, duration + temporal, and duration + duration.

func Construct

func Construct(kind Kind, arg any) (Value, error)

Construct builds a value of the given kind from a string, a map or another temporal value. A nil argument is the caller's responsibility (null in, null out).

func Now

func Now(kind Kind, m map[string]any, at time.Time) (Value, error)

Now returns the value of the given kind at the instant at, in the zone named by m's "timezone" entry (UTC when absent).

func Parse

func Parse(kind Kind, s string) (Value, error)

Parse parses the canonical string form of a value of the given kind.

func Sub

func Sub(a, b Value) (Value, error)

Sub returns a - b: temporal - duration or duration - duration.

func Truncate

func Truncate(kind Kind, unit string, v Value, m map[string]any) (Value, error)

Truncate implements date.truncate, localtime.truncate, time.truncate, localdatetime.truncate and datetime.truncate: the value is cut down to the start of unit and the entries of m are then applied on top (so m may carry components such as {day: 2} or {timezone: 'Europe/Stockholm'}).

Jump to

Keyboard shortcuts

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