temporal

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 7 Imported by: 0 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

Overview

Package temporal is the Go counterpart of lib/tasks/temporal_value.rb and lib/tasks/temporal_context.rb: a stored date with an optional wall time and zone, and the reader's own "now" that such a value is resolved against.

The split matters. A stored value is what the user wrote down — 2026-06-18 17:00 Europe/London — and never moves. The context is who is looking and when, and it is what turns that value into an instant, a local rendering, or the answer to "is this released yet?". Keeping them apart is what lets one snapshot render identically for two readers in different zones.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotADate = errors.New("could not understand that date")

ErrNotADate is what a caller gets when the expression names no date at all — distinct from an expression that names an impossible one.

Functions

func DaysIn

func DaysIn(year int, month time.Month) int

DaysIn is the length of a calendar month.

func NormalizeTime

func NormalizeTime(token string) (string, error)

NormalizeTime turns a written time into the stored HH:MM spelling. "noon" and "midnight" are spellings of 12:00 and 00:00; a meridiem folds a 12-hour reading into 24.

func ValidLocal

func ValidLocal(value string) bool

ValidLocal reports whether a stored `local` string is well formed. Check needs the predicate without building a value.

Types

type Context

type Context struct {
	Now        time.Time
	Timezone   *time.Location
	TimezoneID string
	TimeFormat int
}

Context is the reader: the instant "now", the zone dates are projected into, and the clock format renderings use.

func NewContext

func NewContext(now time.Time, timezone string, timeFormat int) (Context, error)

NewContext builds a context from a resolved zone identifier.

func (Context) LocalDate

func (c Context) LocalDate() Date

LocalDate is the reader's own calendar day — the "today" every date-sensitive read is measured against.

func (Context) LocalNow

func (c Context) LocalNow() time.Time

LocalNow is `now` in the reader's zone.

type Date

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

Date is a civil date with no zone: the shape every stored date stamp has.

func DateOf

func DateOf(instant time.Time) Date

DateOf is the civil date of an instant already projected into a zone.

func NewDate

func NewDate(year int, month time.Month, day int) (Date, bool)

NewDate reports false for a day the calendar does not have, which is what Date.valid_date? answers.

func ParseDate

func ParseDate(value string) (Date, bool)

ParseDate accepts exactly the stored spelling and only real dates.

func ParseWhen

func ParseWhen(input string, today Date, order Order) (Date, bool)

ParseWhen reads a friendly date expression relative to `today`. It reports ok=false for anything it cannot understand, including a well-formed spelling of a day the calendar does not have.

func (Date) AddDays

func (d Date) AddDays(days int) Date

AddDays is Date#+.

func (Date) AddMonths

func (d Date) AddMonths(months int) Date

AddMonths is Ruby Date#>>: a calendar step whose day of month CLAMPS to the target month's length rather than overflowing into the next month, so January 31 plus one month is February 28 (29 in a leap year). Go's time.Time.AddDate normalizes instead, which would say March 3.

func (Date) After

func (d Date) After(other Date) bool

After reports chronological order the other way round.

func (Date) Before

func (d Date) Before(other Date) bool

Before reports chronological order.

func (Date) Equal

func (d Date) Equal(other Date) bool

Equal reports identity.

func (Date) ISO

func (d Date) ISO() string

ISO is the stored spelling.

func (Date) Sub

func (d Date) Sub(other Date) int

Sub is Ruby's `(a - b).to_i` over two Dates: whole days, signed.

func (Date) Weekday

func (d Date) Weekday() time.Weekday

Weekday is the day of week, Sunday being zero, as Ruby's Date#wday reports.

func (Date) Zero

func (d Date) Zero() bool

Zero reports the never-set date.

type Order

type Order int

Order says whether the first number of an ambiguous numeric date is the month or the day.

const (
	// MDY reads 8/1 as August 1st. It is the default, as in Ruby.
	MDY Order = iota
	// DMY reads 8/1 as the 1st of August's neighbour — the 8th of January.
	DMY
)

func OrderNamed

func OrderNamed(name string) Order

OrderNamed reads a configured spelling. Anything but "mdy"/"dmy" degrades to MDY rather than failing, so a bad config value does not break date input.

func (Order) String

func (o Order) String() string

String is the config spelling of an order.

type ParseOptions

type ParseOptions struct {
	// Today is the calendar day relative expressions are measured from.
	Today Date
	// Order resolves ambiguous numeric dates.
	Order Order
	// Timezone pins the wall time to a zone. Mutually exclusive with Floating.
	Timezone string
	// Floating keeps the wall time zoneless, so it means the same clock
	// reading wherever it is read.
	Floating bool
	// Fold picks the second instant of a DST fall-back overlap.
	Fold int
	// FoldSpecified distinguishes an explicit earlier choice from the default
	// zero value. Clock-relative durations reject either fold modifier because
	// their computed instant already selects the side of an overlap.
	FoldSpecified bool
	// Context, when supplied, resolves a timed value immediately so an
	// impossible local time is refused at parse rather than at read.
	Context *Context
}

ParseOptions carries the flags the CLI's --timezone/--floating/--fold set.

type Projection

type Projection struct {
	Date       Date
	Local      string
	TimezoneID string
}

Projection is what a renderer needs: the date and wall time as the reader sees them, plus the zone that projection was made in.

type Value

type Value struct {
	Date      Date
	LocalTime string
	Timezone  string
	Fold      int
}

Value is a stored date with an optional local time, zone and DST fold.

Three shapes, and the difference between them is the whole point: an all-day value is a calendar day (it releases at local midnight wherever the reader is); a floating value carries a wall time but no zone (09:30 means 09:30 where you are); a fixed value carries a zone (17:00 in London is one instant for everybody).

func FromRecord

func FromRecord(date string, local, timezone string, fold int, validate bool) (Value, bool)

FromRecord reads a stored date field and its paired `<field>_time` object. A time object that does not survive validation degrades to the date alone rather than losing the record: a hand-edited time must not make a task disappear from a read, and Check is what reports it.

func NewValue

func NewValue(date Date, localTime, timezone string, fold int, validate bool) (Value, error)

NewValue validates the combination the way TemporalValue#initialize does.

func ParseExpression

func ParseExpression(expression string, options ParseOptions) (Value, error)

ParseExpression reads a date expression with an optional trailing time.

The three outcomes are distinct on purpose: a value, a refusal naming an unusable combination of flags or an impossible time (error), and "that is not a date" (ErrNotADate), which the CLI reports differently from a flag mistake.

func (Value) AllDay

func (v Value) AllDay() bool

AllDay reports a value with no wall time.

func (Value) DueBoundary

func (v Value) DueBoundary(context Context) (time.Time, error)

DueBoundary is the instant a value stops being on time. An ALL-DAY value is due at the end of its day, so its boundary is the first instant of the NEXT date — not the stored date's own midnight.

func (Value) EffectiveZone

func (v Value) EffectiveZone(context Context) *time.Location

EffectiveZone is the value's own zone when it has one, else the reader's.

func (Value) Equal

func (v Value) Equal(other Value) bool

Equal compares the four stored fields, which is what identity means for a value: two values naming the same instant through different zones are not the same stored value.

func (Value) Fixed

func (v Value) Fixed() bool

Fixed reports a value that names its own zone.

func (Value) Floating

func (v Value) Floating() bool

Floating reports a wall time with no zone.

func (Value) Instant

func (v Value) Instant(context Context) (time.Time, error)

Instant is the UTC instant this value names for this reader. An all-day value is the first instant of its date in the reader's zone; a timed value resolves its wall time in its effective zone.

func (Value) Overdue

func (v Value) Overdue(context Context) (bool, error)

Overdue reports whether this value has passed. Date-only: overdue the moment the local date passes. Timed: on time AT the exact instant, overdue strictly after it.

func (Value) Projected

func (v Value) Projected(context Context) (Projection, error)

Projected renders this value in the reader's zone. An all-day value has no wall time to project, so it reports its stored date unchanged.

func (Value) ReleaseInstant

func (v Value) ReleaseInstant(context Context) (time.Time, error)

ReleaseInstant is Instant under the name the availability rules use it by.

func (Value) Released

func (v Value) Released(context Context) (bool, error)

Released reports whether an available-from value has arrived: true at its instant, not only after it.

func (Value) Shift

func (v Value) Shift(days int) (Value, error)

Shift moves a value by whole days, keeping its wall time, zone and fold.

func (Value) TimeMetadata

func (v Value) TimeMetadata() (local, timezone string, fold int, ok bool)

TimeMetadata is the stored `<field>_time` object, or ok=false for an all-day value which has none. `fold` is written only when it is set, and `timezone` only when the value carries one, so a floating value round-trips as one.

func (Value) WithDate

func (v Value) WithDate(date Date) (Value, error)

WithDate re-dates a value, keeping everything else. It is how a recurrence roll proposes its next occurrence.

Jump to

Keyboard shortcuts

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