Documentation
¶
Index ¶
- type Parser
- type Range
- func (r Range) Contains(t time.Time) bool
- func (r Range) ContainsRange(other Range) bool
- func (r Range) End() time.Time
- func (r Range) Equal(other Range) bool
- func (r Range) Intersection(other Range) Range
- func (r Range) IsAllDay() bool
- func (r Range) Overlaps(other Range) bool
- func (r Range) Start() time.Time
- func (r Range) String() string
- func (r Range) Union(other Range) Range
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser provides natural language parsing capabilities for time expressions. It uses a JavaScript implementation embedded in the Go binary.
func New ¶
New creates a new natural time expression parser. It initializes the JavaScript runtime and prepares the parsing functions.
Returns:
- An initialized Parser
- An error if initialization fails
func (*Parser) ParseDate ¶
ParseDate parses a natural language date expression and returns the corresponding time.
Parameters:
- expr: The natural language expression to parse
- base: The reference time for relative expressions
Returns:
- A pointer to the parsed time.Time, or nil if the expression could not be parsed
- An error if parsing fails
func (*Parser) ParseMulti ¶
ParseMulti parses a natural language time expression that may represent multiple time ranges.
Parameters:
- expr: The natural language expression to parse
- base: The reference time for relative expressions
Returns:
- A slice of Range objects
- An error if parsing fails
func (*Parser) ParseRange ¶
ParseRange parses a natural language time expression and returns a single time range.
Parameters:
- expr: The natural language expression to parse
- base: The reference time for relative expressions
Returns:
- A pointer to the parsed Range
- An error if parsing fails or if multiple ranges are returned
type Range ¶
Range is a time range represented as a half-open interval [start, end). The start time is inclusive, and the end time is exclusive.
func RangeFromTimes ¶
RangeFromTimes creates a Range from two times. The start time should be before or equal to the end time.
func (Range) Contains ¶
Contains checks if the given time is within this range. The range is half-open: [start, end), so start <= t < end.
func (Range) ContainsRange ¶
ContainsRange checks if another range is fully contained within this range.
func (Range) Equal ¶
Equal returns true if the two ranges are exactly equal, having the same start time and duration.
func (Range) Intersection ¶
Intersection returns the overlapping range between two ranges, or a zero-duration range at the latest start time if they don't overlap.
func (Range) Overlaps ¶
Overlaps checks if this range overlaps with another range. Two ranges overlap if they share any common time point. Note: If 'other' starts exactly at the same time as r.End(), it is not considered an overlap. Similarly, if r starts exactly at the same time as other.End(), it is also not considered an overlap.