Documentation
¶
Overview ¶
Package openinghours provides immutable recurring opening-hours schedules, dated exceptions, explicit timezone evaluation, bounded search, and stable canonical persistence.
Index ¶
- Constants
- func IsCode(err error, code Code) bool
- type Availability
- type Clock
- type Code
- type Config
- type ConflictPolicy
- type DailyRange
- type Date
- type DayResult
- type DayRule
- type DayState
- type ElapsedClock
- type Error
- type Exception
- type ExceptionConfig
- type ExceptionOperation
- type ExceptionRangeConfig
- type ExceptionSet
- type Explanation
- type InstantRange
- type LocalKind
- type LocalResolutionPolicy
- type LocalTime
- type Metadata
- type Observation
- type Observer
- type Operation
- type Outcome
- type OutsideEffectivePolicy
- type OverlapPolicy
- type Range
- type ResolvedLocal
- type RuleKind
- type Schedule
- func (s Schedule) CanonicalJSON() ([]byte, error)
- func (s Schedule) Compare(other Schedule) (int, error)
- func (s Schedule) EffectiveInstantRanges(start, end time.Time) ([]InstantRange, error)
- func (s Schedule) EffectiveRanges(date Date) ([]DailyRange, error)
- func (s Schedule) Equal(other Schedule) bool
- func (s Schedule) Hash() [sha256.Size]byte
- func (s Schedule) HumanSummary() (string, error)
- func (s Schedule) Intersection(other Schedule) (Schedule, error)
- func (s Schedule) IsOpen(instant time.Time) (Availability, error)
- func (s Schedule) IsOpenLocal(date Date, localTime LocalTime, policy LocalResolutionPolicy) (Availability, error)
- func (s Schedule) IsOpenNow(clock Clock) (Availability, error)
- func (s Schedule) MarshalJSON() ([]byte, error)
- func (s Schedule) MarshalText() ([]byte, error)
- func (s Schedule) Metadata() Metadata
- func (s Schedule) NextClosing(instant time.Time, horizon time.Duration) (Transition, error)
- func (s Schedule) NextOpening(instant time.Time, horizon time.Duration) (Transition, error)
- func (s Schedule) NextTransition(instant time.Time, horizon time.Duration) (Transition, error)
- func (s Schedule) ObserveIsOpen(instant time.Time, elapsedClock ElapsedClock, observer Observer) (Availability, error)
- func (s Schedule) ObserveNextTransition(instant time.Time, horizon time.Duration, elapsedClock ElapsedClock, ...) (Transition, error)
- func (s Schedule) OpenDuration(start, end time.Time) (time.Duration, error)
- func (s Schedule) Overlay(other Schedule) (Schedule, error)
- func (s Schedule) PreviousTransition(instant time.Time, horizon time.Duration) (Transition, error)
- func (s Schedule) Ranges(date Date) (DayResult, error)
- func (s Schedule) ResolveLocal(date Date, localTime LocalTime, policy LocalResolutionPolicy) (ResolvedLocal, error)
- func (s Schedule) Revision() string
- func (s *Schedule) Scan(source any) error
- func (s Schedule) SemanticallyEqual(other Schedule) bool
- func (s Schedule) String() string
- func (s Schedule) Subtract(other Schedule) (Schedule, error)
- func (s Schedule) Timezone() string
- func (s Schedule) Union(other Schedule) (Schedule, error)
- func (s *Schedule) UnmarshalJSON(data []byte) error
- func (s *Schedule) UnmarshalText(data []byte) error
- func (s Schedule) Value() (driver.Value, error)
- type Transition
- type TransitionKind
Constants ¶
const (
// MaxCompositionDepth bounds immutable algebra expression nesting.
MaxCompositionDepth = 16
)
const (
// MaxHumanSummaryBytes bounds presentation-oriented schedule summaries.
MaxHumanSummaryBytes = 64 << 10
)
const (
// MaxJSONBytes bounds canonical and parsed schedule documents.
MaxJSONBytes = 1 << 20
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Availability ¶
type Availability struct {
Open bool
Explanation Explanation
}
Availability is the explained result of a point query.
type Clock ¶
Clock is the clock current-time capability. Core schedule queries never read a process-global clock.
type Code ¶
type Code string
Code identifies a stable, safe-to-expose failure category.
const ( // CodeInvalidTime reports a wall-clock value outside its valid domain. CodeInvalidTime Code = "invalid_time" // CodeInvalidDate reports a civil date outside its valid domain. CodeInvalidDate Code = "invalid_date" // CodeInvalidRange reports a malformed or zero-length time range. CodeInvalidRange Code = "invalid_range" // CodeInvalidTimezone reports an absent or unknown IANA timezone. CodeInvalidTimezone Code = "invalid_timezone" // CodeInvalidWeekday reports a weekday outside Sunday through Saturday. CodeInvalidWeekday Code = "invalid_weekday" // CodeInvalidState reports an unsupported enum or state combination. CodeInvalidState Code = "invalid_state" // CodeOverlap reports overlapping ranges under a rejecting policy. CodeOverlap Code = "overlap" // CodeLimitExceeded reports a configured resource bound was exceeded. CodeLimitExceeded Code = "limit_exceeded" // CodeAmbiguousException reports equal-priority exception ambiguity. CodeAmbiguousException Code = "ambiguous_exception" // CodeDuplicateRevision reports duplicate source revision identity. CodeDuplicateRevision Code = "duplicate_revision" // CodeAmbiguousLocalTime reports a local time in a timezone fold. CodeAmbiguousLocalTime Code = "ambiguous_local_time" // CodeNonexistentLocalTime reports a local time in a timezone gap. CodeNonexistentLocalTime Code = "nonexistent_local_time" // CodeInvalidHorizon reports an unbounded or excessive search horizon. CodeInvalidHorizon Code = "invalid_horizon" // CodeSearchExhausted reports no transition in the bounded horizon. CodeSearchExhausted Code = "search_exhausted" // CodeTimezoneMismatch reports composition across different timezones. CodeTimezoneMismatch Code = "timezone_mismatch" // CodeInvalidEncoding reports malformed or noncanonical input structure. CodeInvalidEncoding Code = "invalid_encoding" // CodeUnsupportedVersion reports an unknown canonical wire version. CodeUnsupportedVersion Code = "unsupported_version" // CodeInvalidInterval reports a reversed, empty, or excessive interval. CodeInvalidInterval Code = "invalid_interval" // CodeOutsideEffectiveRange reports a query outside configured dates. CodeOutsideEffectiveRange Code = "outside_effective_range" // CodeInvalidClock reports a missing injected clock capability. CodeInvalidClock Code = "invalid_clock" // CodeAdjacent reports adjacent ranges under a rejecting policy. CodeAdjacent Code = "adjacent" // CodeDayBoundaryOverflow reports normalized ownership beyond one day. CodeDayBoundaryOverflow Code = "day_boundary_overflow" )
type Config ¶
type Config struct {
Timezone string
Weekly map[time.Weekday]DayRule
Exceptions []Exception
ExceptionSets []ExceptionSet
ConflictPolicy ConflictPolicy
Metadata Metadata
EffectiveStart *Date
EffectiveEnd *Date
OutsideEffective OutsideEffectivePolicy
}
Config is copied by NewSchedule.
type ConflictPolicy ¶
type ConflictPolicy uint8
ConflictPolicy controls equal-priority exception handling.
const ( // RejectAmbiguous rejects equal-priority rules without unique precedence. RejectAmbiguous ConflictPolicy = iota // ResolveCanonical resolves equal priorities by stable provenance order. ResolveCanonical )
type DailyRange ¶
DailyRange is a start-inclusive, end-exclusive interval within one civil date. EndAtDayBoundary distinguishes midnight at the end from midnight at the start of the date.
type Date ¶
Date is the calendar immutable Gregorian civil date value.
type DayRule ¶
type DayRule struct {
// contains filtered or unexported fields
}
DayRule is an immutable weekly or dated availability rule.
func Inherited ¶
func Inherited() DayRule
Inherited returns a rule that delegates to the lower-precedence source.
func OpenRanges ¶
func OpenRanges(input []Range, policy OverlapPolicy) (DayRule, error)
OpenRanges constructs a canonical ranged rule using the selected policy.
type DayState ¶
type DayState uint8
DayState distinguishes absence, ranged opening, full-day opening, and closure.
const ( // DayInherited delegates to a lower-precedence rule source. DayInherited DayState = iota // DayOpenRanges opens only the rule's explicit local-time ranges. DayOpenRanges // DayOpenAllDay opens the complete owned civil day. DayOpenAllDay // DayClosed explicitly closes the owned civil day. DayClosed )
type ElapsedClock ¶
type ElapsedClock = clock.ElapsedClock
ElapsedClock is the clock monotonic elapsed-time capability. Observation helpers accept it separately so measuring a query never reads wall time.
type Exception ¶
type Exception struct {
// contains filtered or unexported fields
}
Exception is an immutable exact-date availability operation.
func NewException ¶
func NewException(config ExceptionConfig) (Exception, error)
NewException validates an exact-date exception and its bounded provenance.
func (Exception) Operation ¶
func (e Exception) Operation() ExceptionOperation
Operation returns the exception operation.
type ExceptionConfig ¶
type ExceptionConfig struct {
Date Date
Operation ExceptionOperation
Rule DayRule
Priority int
Source string
Revision string
}
ExceptionConfig is copied by NewException.
type ExceptionOperation ¶
type ExceptionOperation uint8
ExceptionOperation defines how a dated rule changes inherited availability.
const ( // ExceptionReplace replaces availability for its civil date. ExceptionReplace ExceptionOperation = iota // ExceptionAdd unions availability into its civil date. ExceptionAdd // ExceptionSubtract removes availability from its civil date. ExceptionSubtract // ExceptionClose closes its civil date completely. ExceptionClose )
type ExceptionRangeConfig ¶
type ExceptionRangeConfig struct {
Name string
Start Date
End Date
MaximumDates int
Operation ExceptionOperation
Rule DayRule
Priority int
Source string
Revision string
}
ExceptionRangeConfig expands a bounded inclusive civil-date range.
type ExceptionSet ¶
type ExceptionSet struct {
// contains filtered or unexported fields
}
ExceptionSet is an immutable named group flattened before evaluation.
func ExpandExceptionRange ¶
func ExpandExceptionRange(config ExceptionRangeConfig) (ExceptionSet, error)
ExpandExceptionRange resolves a multi-day rule to deterministic exact dates.
func NewExceptionSet ¶
func NewExceptionSet(name string, input []Exception) (ExceptionSet, error)
NewExceptionSet validates, names, and copies a non-empty exception group.
func (ExceptionSet) Exceptions ¶
func (set ExceptionSet) Exceptions() []Exception
Exceptions returns detached exception values and range slices.
type Explanation ¶
Explanation reports bounded, non-sensitive rule provenance.
type InstantRange ¶
InstantRange is a start-inclusive, end-exclusive absolute interval.
type LocalResolutionPolicy ¶
type LocalResolutionPolicy uint8
LocalResolutionPolicy explicitly resolves DST gaps and folds.
const ( // RejectDST rejects both nonexistent and ambiguous local times. RejectDST LocalResolutionPolicy = iota // PreferEarlier selects the earlier instant in a local-time fold. PreferEarlier // PreferLater selects the later instant in a local-time fold. PreferLater // ShiftForward advances a nonexistent local time through a timezone gap. ShiftForward )
type LocalTime ¶
type LocalTime struct {
// contains filtered or unexported fields
}
LocalTime is a nanosecond-precision wall-clock time without a date or zone. Its zero value is midnight.
func NewLocalTime ¶
NewLocalTime constructs a wall-clock time in the half-open day [00:00,24:00).
func (LocalTime) Nanosecond ¶
Nanosecond returns the fractional second component.
type Observation ¶
type Observation struct {
Operation Operation
Outcome Outcome
RangeCount int
SearchSteps int
Duration time.Duration
}
Observation contains only bounded operational data. It intentionally has no schedule label, source, revision, date, timezone, or customer fields.
type Observer ¶
type Observer func(Observation)
Observer receives one completed observation outside any lock. Panics are contained and cannot alter the query result.
type Outcome ¶
type Outcome uint8
Outcome is a bounded, non-sensitive operation result.
const ( // OutcomeClosed reports a successful query whose resource is closed. OutcomeClosed Outcome = iota // OutcomeOpen reports a successful query whose resource is open. OutcomeOpen // OutcomeFound reports a transition found within the search horizon. OutcomeFound // OutcomeError reports a typed query or search failure. OutcomeError )
type OutsideEffectivePolicy ¶
type OutsideEffectivePolicy uint8
OutsideEffectivePolicy controls queries outside inclusive effective dates.
const ( // OutsideClosed treats dates outside the effective range as closed. OutsideClosed OutsideEffectivePolicy = iota // OutsideError rejects queries outside the effective range. OutsideError )
type OverlapPolicy ¶
type OverlapPolicy uint8
OverlapPolicy makes normalization of overlapping or adjacent input explicit.
const ( // RejectOverlap rejects overlapping ranges but permits adjacency. RejectOverlap OverlapPolicy = iota // RejectOverlapAndAdjacent rejects both overlap and adjacency. RejectOverlapAndAdjacent // MergeOverlap merges overlap but preserves adjacent ranges. MergeOverlap // MergeAdjacent merges both overlapping and adjacent ranges. MergeAdjacent )
type Range ¶
type Range struct {
// contains filtered or unexported fields
}
Range is a start-inclusive, end-exclusive local-time interval. If End is earlier than Start, the interval is overnight and belongs to its start date.
type ResolvedLocal ¶
ResolvedLocal records the instant and DST classification selected by policy.
type RuleKind ¶
type RuleKind uint8
RuleKind identifies the broad rule source used by a query.
const ( // RuleNone means no schedule rule supplied availability. RuleNone RuleKind = iota // RuleWeekly means the current date's weekly rule supplied availability. RuleWeekly // RuleWeeklySpill means the preceding date's overnight rule supplied it. RuleWeeklySpill // RuleException means a dated exception supplied the final result. RuleException // RuleComposition means schedule algebra supplied the final result. RuleComposition // RuleOutsideEffective means the queried date is outside configured dates. RuleOutsideEffective )
type Schedule ¶
type Schedule struct {
// contains filtered or unexported fields
}
Schedule is an immutable availability value. Its zero value is closed and carries no timezone; it never means always open.
func NewSchedule ¶
NewSchedule validates and copies all caller-owned input.
func (Schedule) CanonicalJSON ¶
CanonicalJSON returns stable, compact, versioned JSON.
func (Schedule) Compare ¶
Compare returns -1, 0, or 1 according to the schedules' canonical byte ordering. It includes provenance and composition shape, like Equal.
func (Schedule) EffectiveInstantRanges ¶
func (s Schedule) EffectiveInstantRanges(start, end time.Time) ([]InstantRange, error)
EffectiveInstantRanges returns clipped absolute availability within a bounded interval of at most 366 elapsed days.
func (Schedule) EffectiveRanges ¶
func (s Schedule) EffectiveRanges(date Date) ([]DailyRange, error)
EffectiveRanges returns normalized availability fragments for one civil date.
func (Schedule) Equal ¶
Equal reports canonical equality, including provenance and composition shape.
func (Schedule) HumanSummary ¶
HumanSummary returns deterministic presentation text that is not a wire encoding and cannot be parsed by UnmarshalText. It excludes labels and exception provenance, reporting only the number of dated exceptions.
func (Schedule) Intersection ¶
Intersection returns a schedule open only when both operands are open.
func (Schedule) IsOpen ¶
func (s Schedule) IsOpen(instant time.Time) (Availability, error)
IsOpen evaluates an absolute instant in the schedule's explicit timezone.
func (Schedule) IsOpenLocal ¶
func (s Schedule) IsOpenLocal(date Date, localTime LocalTime, policy LocalResolutionPolicy) (Availability, error)
IsOpenLocal resolves a civil date and wall-clock time under the explicit DST policy, then evaluates the selected instant in the schedule timezone.
func (Schedule) IsOpenNow ¶
func (s Schedule) IsOpenNow(clock Clock) (Availability, error)
IsOpenNow evaluates an injected clock's current instant.
func (Schedule) MarshalJSON ¶
MarshalJSON implements json.Marshaler with the canonical encoding.
func (Schedule) MarshalText ¶
MarshalText implements encoding.TextMarshaler using canonical JSON text.
func (Schedule) NextClosing ¶
NextClosing finds the first closing boundary strictly after instant.
func (Schedule) NextOpening ¶
NextOpening finds the first opening boundary strictly after instant.
func (Schedule) NextTransition ¶
NextTransition finds the first availability boundary strictly after instant. The horizon must be positive and no greater than 366 elapsed days.
func (Schedule) ObserveIsOpen ¶
func (s Schedule) ObserveIsOpen(instant time.Time, elapsedClock ElapsedClock, observer Observer) (Availability, error)
ObserveIsOpen runs IsOpen and reports bounded operational data. A nil clock disables elapsed measurement and reports a zero duration.
func (Schedule) ObserveNextTransition ¶
func (s Schedule) ObserveNextTransition(instant time.Time, horizon time.Duration, elapsedClock ElapsedClock, observer Observer) (Transition, error)
ObserveNextTransition runs a bounded transition search and reports its outcome. A nil clock disables elapsed measurement and reports a zero duration.
func (Schedule) OpenDuration ¶
OpenDuration returns elapsed open time within a bounded absolute interval.
func (Schedule) Overlay ¶
Overlay returns a schedule where explicit right-hand rules override left-hand availability and inherited right-hand rules leave it unchanged.
func (Schedule) PreviousTransition ¶
PreviousTransition finds the nearest availability boundary strictly before instant within a positive horizon of at most 366 elapsed days.
func (Schedule) Ranges ¶
Ranges resolves the effective weekly rule for date. Missing and inherited weekly rules are closed because there is no lower-precedence source.
func (Schedule) ResolveLocal ¶
func (s Schedule) ResolveLocal(date Date, localTime LocalTime, policy LocalResolutionPolicy) (ResolvedLocal, error)
ResolveLocal converts a civil date and wall-clock time in the schedule zone. Gaps and folds are never resolved without the caller-selected policy.
func (*Schedule) Scan ¶
Scan implements sql.Scanner for JSON/JSONB bytes, strings, and NULL. NULL produces the fail-closed zero schedule.
func (Schedule) SemanticallyEqual ¶
SemanticallyEqual compares interval semantics while ignoring metadata only.
func (Schedule) Timezone ¶
Timezone returns the explicit IANA timezone identity, or empty for zero value.
func (*Schedule) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler using the strict parser.
func (*Schedule) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler using the strict parser.
type Transition ¶
type Transition struct {
Instant time.Time
Kind TransitionKind
Explanation Explanation
}
Transition is an explained availability boundary.
type TransitionKind ¶
type TransitionKind uint8
TransitionKind identifies an opening or closing boundary.
const ( // TransitionOpen identifies a boundary whose following instant is open. TransitionOpen TransitionKind = iota // TransitionClose identifies a boundary whose following instant is closed. TransitionClose )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
adapters
|
|
|
calendar
Package openinghourscalendar adapts calendar civil dates and bounded business-calendar holidays to opening-hours values.
|
Package openinghourscalendar adapts calendar civil dates and bounded business-calendar holidays to opening-hours values. |
|
config
Package openinghoursconfig adapts canonical schedule documents from configuration sources while leaving environment and file ownership to the caller.
|
Package openinghoursconfig adapts canonical schedule documents from configuration sources while leaving environment and file ownership to the caller. |
|
temporal
Package openinghourstemporal provides lossless adapters for temporal/timeofday values.
|
Package openinghourstemporal provides lossless adapters for temporal/timeofday values. |
|
validation
Package openinghoursvalidation adapts schedule validation to the shared validation contract.
|
Package openinghoursvalidation adapts schedule validation to the shared validation contract. |
|
wire
Package openinghourswire adapts schedules to byte-oriented wire registries.
|
Package openinghourswire adapts schedules to byte-oriented wire registries. |
|
Package compile provides an immutable prepared schedule handle for repeated queries.
|
Package compile provides an immutable prepared schedule handle for repeated queries. |
|
Package encoding exposes the canonical schedule wire contract without shadowing human-readable formatting concerns in the root package.
|
Package encoding exposes the canonical schedule wire contract without shadowing human-readable formatting concerns in the root package. |
|
Package openinghourscalendar is the compatibility path for github.com/faustbrian/go-opening-hours/adapters/calendar.
|
Package openinghourscalendar is the compatibility path for github.com/faustbrian/go-opening-hours/adapters/calendar. |
|
Package openinghoursconfig is the compatibility path for github.com/faustbrian/go-opening-hours/adapters/config.
|
Package openinghoursconfig is the compatibility path for github.com/faustbrian/go-opening-hours/adapters/config. |
|
Package openinghourstemporal is the compatibility path for github.com/faustbrian/go-opening-hours/adapters/temporal.
|
Package openinghourstemporal is the compatibility path for github.com/faustbrian/go-opening-hours/adapters/temporal. |
|
Package openinghourstest provides panic-on-error builders for static tests.
|
Package openinghourstest provides panic-on-error builders for static tests. |
|
Package openinghoursvalidation is the compatibility path for github.com/faustbrian/go-opening-hours/adapters/validation.
|
Package openinghoursvalidation is the compatibility path for github.com/faustbrian/go-opening-hours/adapters/validation. |
|
Package openinghourswire is the compatibility path for github.com/faustbrian/go-opening-hours/adapters/wire.
|
Package openinghourswire is the compatibility path for github.com/faustbrian/go-opening-hours/adapters/wire. |
|
Package postgres provides nullable JSONB persistence values.
|
Package postgres provides nullable JSONB persistence values. |