Documentation
¶
Overview ¶
Package temporal defines shared bounds, Allen relations, typed errors, and resource limits for bounded temporal algebra packages.
Example (DailyInterval) ¶
package main
import (
"fmt"
"time"
calendar "github.com/faustbrian/go-calendar"
calendartz "github.com/faustbrian/go-calendar/timezone"
temporal "github.com/faustbrian/go-temporal"
"github.com/faustbrian/go-temporal/timeofday"
)
func main() {
start, _ := timeofday.Parse("22:00", temporal.Limits{})
end, _ := timeofday.Parse("02:00", temporal.Limits{})
night, _ := timeofday.Between(start, end, temporal.ClosedOpen)
set, _ := timeofday.NewIntervalSet(temporal.Limits{}, night)
offHours, _ := set.Complement()
date := calendar.MustDate(2026, time.July, 16)
instants, _ := night.ToInstant(date, time.UTC, calendartz.Reject)
duration, _ := instants.Duration()
fmt.Println(night.Kind(), night.Duration(), offHours.Len(), duration)
}
Output: Circular 4h0m0s 1 4h0m0s
Example (DatePeriod) ¶
package main
import (
"fmt"
"time"
calendartz "github.com/faustbrian/go-calendar/timezone"
temporal "github.com/faustbrian/go-temporal"
"github.com/faustbrian/go-temporal/dateperiod"
)
func main() {
month, _ := dateperiod.Month(2026, time.July)
weeks, _ := month.SplitDays(7, temporal.Limits{Steps: 10})
location, _ := time.LoadLocation("Europe/Helsinki")
instants, _ := month.ToInstant(location, calendartz.Reject)
duration, _ := instants.Duration()
fmt.Println(month.Start(), month.End(), len(weeks), duration.Hours())
}
Output: 2026-07-01 2026-07-31 5 744
Example (InstantPeriod) ¶
package main
import (
"fmt"
"time"
temporal "github.com/faustbrian/go-temporal"
"github.com/faustbrian/go-temporal/instant"
)
func main() {
start := time.Date(2026, time.July, 16, 9, 0, 0, 0, time.UTC)
period, _ := instant.Range(start, start.Add(90*time.Minute))
parts, _ := period.SplitForward(30*time.Minute, temporal.Limits{Steps: 10})
set, _ := instant.NewSet(temporal.Limits{}, parts...)
fmt.Println(period.Bounds(), set.Includes(start), set.Len())
}
Output: [) true 1
Index ¶
- Constants
- Variables
- type Bounds
- func (b Bounds) ExcludeEnd() Bounds
- func (b Bounds) ExcludeStart() Bounds
- func (b Bounds) IncludeEnd() Bounds
- func (b Bounds) IncludeStart() Bounds
- func (b Bounds) Includes(side Side) (bool, error)
- func (b Bounds) IncludesEnd() bool
- func (b Bounds) IncludesStart() bool
- func (b Bounds) MarshalText() ([]byte, error)
- func (b Bounds) String() string
- func (b *Bounds) UnmarshalText(text []byte) error
- func (b Bounds) Valid() bool
- func (b Bounds) WithSide(side Side, included bool) (Bounds, error)
- type LimitError
- type Limits
- type Relation
- type Side
Examples ¶
Constants ¶
const ( // HardMaxPeriods bounds the input and output of any set operation. HardMaxPeriods = 100_000 // HardMaxSteps bounds iteration and splitting. HardMaxSteps = 1_000_000 )
Variables ¶
var ( // ErrBounds identifies an unknown or malformed bounds value. ErrBounds = errors.New("temporal: invalid bounds") // ErrLimit identifies a configured or operational resource limit violation. ErrLimit = errors.New("temporal: resource limit exceeded") // ErrReversed identifies an interval whose end precedes its start. ErrReversed = errors.New("temporal: reversed interval") // ErrEmpty identifies an operation that requires a non-empty interval. ErrEmpty = errors.New("temporal: empty interval") // ErrStep identifies a zero or negative iteration step. ErrStep = errors.New("temporal: invalid step") // ErrOverflow identifies arithmetic outside the supported representation. ErrOverflow = errors.New("temporal: arithmetic overflow") // ErrParse identifies malformed or unsupported notation. ErrParse = errors.New("temporal: parse error") // ErrPrecision identifies input whose fractional precision is unsupported. ErrPrecision = errors.New("temporal: precision exceeded") // ErrInvalidTime identifies an invalid local time-of-day value. ErrInvalidTime = errors.New("temporal: invalid local time") // ErrUnsupported identifies a conversion that cannot preserve semantics. ErrUnsupported = errors.New("temporal: unsupported operation") )
Functions ¶
This section is empty.
Types ¶
type Bounds ¶
type Bounds uint8
Bounds describes endpoint inclusion for a bounded interval.
func AllBounds ¶
func AllBounds() []Bounds
AllBounds returns the four supported modes in canonical order.
func (Bounds) ExcludeEnd ¶
ExcludeEnd returns a bounds value with an excluded end.
func (Bounds) ExcludeStart ¶
ExcludeStart returns a bounds value with an excluded start.
func (Bounds) IncludeEnd ¶
IncludeEnd returns a bounds value with an included end.
func (Bounds) IncludeStart ¶
IncludeStart returns a bounds value with an included start.
func (Bounds) IncludesEnd ¶
IncludesEnd reports whether the end endpoint is a member.
func (Bounds) IncludesStart ¶
IncludesStart reports whether the start endpoint is a member.
func (Bounds) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Bounds) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type LimitError ¶
LimitError describes which resource limit was invalid or exceeded.
func (*LimitError) Unwrap ¶
func (e *LimitError) Unwrap() error
Unwrap makes LimitError discoverable with errors.Is.
type Limits ¶
type Limits struct {
ParseBytes int
Precision int
ErrorBytes int
FormatBytes int
InputPeriods int
OutputPeriods int
Steps int
ParserDepth int
}
Limits controls allocation and work performed by variable-size operations. A zero field selects its safe default. Values cannot exceed hard limits.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits returns the package's bounded operational defaults.
type Relation ¶
type Relation uint8
Relation is one of Allen's thirteen relations for two non-empty intervals.
const ( // RelationInvalid is the safe zero value and is not an Allen relation. RelationInvalid Relation = iota // Before ends strictly before the other interval starts. Before // Meets ends exactly where the other interval starts. Meets // Overlaps starts first and ends inside the other interval. Overlaps // Starts shares the start and ends first. Starts // During starts after and ends before the other interval. During // Finishes starts later and shares the end. Finishes // Equal shares both endpoints with the other interval. Equal // FinishedBy starts first and shares the end. FinishedBy // Contains starts before and ends after the other interval. Contains // StartedBy shares the start and ends after the other interval. StartedBy // OverlappedBy starts inside the other interval and ends later. OverlappedBy // MetBy starts exactly where the other interval ends. MetBy // After starts strictly after the other interval ends. After )
func AllRelations ¶
func AllRelations() []Relation
AllRelations returns all Allen relations in canonical order.
Directories
¶
| Path | Synopsis |
|---|---|
|
adapters
|
|
|
config
Package temporalconfig provides atomic text wrappers for config and other configuration decoders that honor encoding.TextUnmarshaler.
|
Package temporalconfig provides atomic text wrappers for config and other configuration decoders that honor encoding.TextUnmarshaler. |
|
postgres
Package temporalpostgres provides loss-checked PostgreSQL range and multirange mappings for temporal values.
|
Package temporalpostgres provides loss-checked PostgreSQL range and multirange mappings for temporal values. |
|
validation
Package temporalvalidation adapts temporal values to validation's deterministic immutable validator contract.
|
Package temporalvalidation adapts temporal values to validation's deterministic immutable validator contract. |
|
wire
Package temporalwire provides versioned, format-neutral documents for encoding temporal values through wire or the standard JSON package.
|
Package temporalwire provides versioned, format-neutral documents for encoding temporal values through wire or the standard JSON package. |
|
Package dateperiod provides immutable bounded intervals over civil calendar dates.
|
Package dateperiod provides immutable bounded intervals over civil calendar dates. |
|
Package instant provides immutable bounded intervals over time.Time instants.
|
Package instant provides immutable bounded intervals over time.Time instants. |
|
internal
|
|
|
diagnostic
Package diagnostic provides bounded errors for hostile input boundaries.
|
Package diagnostic provides bounded errors for hostile input boundaries. |
|
Package notation provides strict codecs for temporal interval notation.
|
Package notation provides strict codecs for temporal interval notation. |
|
Package postgres provides retained PostgreSQL adapters.
|
Package postgres provides retained PostgreSQL adapters. |
|
Package temporalconfig provides retained configuration adapters.
|
Package temporalconfig provides retained configuration adapters. |
|
Package temporaltest provides canonical algebra fixtures and assertions for temporal package consumers.
|
Package temporaltest provides canonical algebra fixtures and assertions for temporal package consumers. |
|
Package temporalvalidation provides retained validation adapters.
|
Package temporalvalidation provides retained validation adapters. |
|
Package temporalwire provides retained wire adapters.
|
Package temporalwire provides retained wire adapters. |
|
Package timeofday provides immutable date-independent local time values and circular daily interval algebra.
|
Package timeofday provides immutable date-independent local time values and circular daily interval algebra. |