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 ¶
- Variables
- func DaysIn(year int, month time.Month) int
- func NormalizeTime(token string) (string, error)
- func ValidLocal(value string) bool
- type Context
- type Date
- func (d Date) AddDays(days int) Date
- func (d Date) AddMonths(months int) Date
- func (d Date) After(other Date) bool
- func (d Date) Before(other Date) bool
- func (d Date) Equal(other Date) bool
- func (d Date) ISO() string
- func (d Date) Sub(other Date) int
- func (d Date) Weekday() time.Weekday
- func (d Date) Zero() bool
- type Order
- type ParseOptions
- type Projection
- type Value
- func (v Value) AllDay() bool
- func (v Value) DueBoundary(context Context) (time.Time, error)
- func (v Value) EffectiveZone(context Context) *time.Location
- func (v Value) Equal(other Value) bool
- func (v Value) Fixed() bool
- func (v Value) Floating() bool
- func (v Value) Instant(context Context) (time.Time, error)
- func (v Value) Overdue(context Context) (bool, error)
- func (v Value) Projected(context Context) (Projection, error)
- func (v Value) ReleaseInstant(context Context) (time.Time, error)
- func (v Value) Released(context Context) (bool, error)
- func (v Value) Shift(days int) (Value, error)
- func (v Value) TimeMetadata() (local, timezone string, fold int, ok bool)
- func (v Value) WithDate(date Date) (Value, error)
Constants ¶
This section is empty.
Variables ¶
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 NormalizeTime ¶
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 ¶
ValidLocal reports whether a stored `local` string is well formed. Check needs the predicate without building a value.
Types ¶
type Context ¶
Context is the reader: the instant "now", the zone dates are projected into, and the clock format renderings use.
func NewContext ¶
NewContext builds a context from a resolved zone identifier.
type Date ¶
Date is a civil date with no zone: the shape every stored date stamp has.
func NewDate ¶
NewDate reports false for a day the calendar does not have, which is what Date.valid_date? answers.
func ParseWhen ¶
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) AddMonths ¶
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.
type Order ¶
type Order int
Order says whether the first number of an ambiguous numeric date is the month or the day.
func OrderNamed ¶
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.
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
// 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 ¶
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 ¶
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 ¶
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 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) DueBoundary ¶
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 ¶
EffectiveZone is the value's own zone when it has one, else the reader's.
func (Value) Equal ¶
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) Instant ¶
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 ¶
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 ¶
ReleaseInstant is Instant under the name the availability rules use it by.
func (Value) Released ¶
Released reports whether an available-from value has arrived: true at its instant, not only after it.
func (Value) TimeMetadata ¶
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.