Documentation
¶
Overview ¶
Package dtrexp parses and evaluates DTRExp (Date-Time Range & Recurrence Expression) strings, per DTRExp draft 2.8.
A DTRExp denotes a — possibly infinite — set of time intervals. It is not enumerated into dates; it is evaluated for coverage: "is this instant inside the set?". This package implements parsing/validation (with the spec's §9.1 warnings) and the covers check. Rendering, description and RRULE export are out of scope.
The evaluation model is time-zone agnostic: an expression carries no zone; the zone is a parameter of Covers (default UTC).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expression ¶
type Expression struct {
// contains filtered or unexported fields
}
Expression is a parsed DTRExp. It is one or more union branches; an instant is covered iff any branch covers it. Expression values are immutable after Parse and safe for concurrent use.
func Parse ¶
func Parse(s string) (*Expression, error)
Parse parses a DTRExp string. It returns an error for any syntactically or statically invalid expression; the error is always a ParseError carrying the offending character offset. A successfully parsed expression may still carry warnings (see Warnings) for statically unsatisfiable constructs that are legal but never match.
func (*Expression) Covers ¶
Covers reports whether the absolute instant t falls inside the set denoted by the expression, evaluated in IANA time zone tz. An empty tz means UTC. It returns an error only if tz is not a loadable IANA zone.
func (*Expression) CoversIn ¶
CoversIn is Covers with an already-resolved *time.Location (nil means UTC).
func (*Expression) Source ¶
func (e *Expression) Source() string
Source returns the original expression string.
func (*Expression) Warnings ¶
func (e *Expression) Warnings() []Warning
Warnings returns the §9.1 warnings collected during parsing — statically unsatisfiable expressions or branches that are legal but can never match. The slice is empty for a clean expression.
type ParseError ¶
ParseError is a positioned syntax error: what went wrong and where. Pos is the 0-based character offset of the offending input in the source string (DTR expressions are ASCII, so byte and character offsets coincide). Every error Parse returns for invalid source is a ParseError.
func (ParseError) Error ¶
func (e ParseError) Error() string
Error implements the error interface, rendering as "dtrexp: <msg> (at <pos>)".
type ValidationResult ¶
type ValidationResult struct {
Valid bool
Errors []ParseError
Warnings []Warning
}
ValidationResult is the outcome of Validate: whether the source parses, the positioned syntax errors when it does not, and the §9.1 warnings when it does. An expression can be valid and still warned.
func Validate ¶
func Validate(s string) ValidationResult
Validate checks a DTRExp string without failing: typo-shaped input comes back as data, never as a Go error. Errors is empty when Valid; parsing stops at the first syntax error, so it holds at most one entry. Warnings carries the same content as Warnings on the parsed expression.