Documentation ¶
Overview ¶
Package anytime parses dates, times and ranges without requiring a format.
Index ¶
- func DefaultToFuture(o *opts)
- func DefaultToPast(o *opts)
- func I(s string) gp.Parser
- func Parse(s string, ref time.Time, opts ...func(o *opts)) (time.Time, error)
- func Parser(ref time.Time, options ...func(o *opts)) gp.Parser
- func PartitionTimes(s string, ref time.Time, options ...func(o *opts)) []any
- func PartitionTimesByFuncs(s string, ref time.Time, ntf func(nonTimeChunk string), ...)
- func RangeParser(ref time.Time, options ...func(o *opts)) gp.Parser
- func ReplaceDateRangesByFunc(s string, ref time.Time, f func(source string, r Range) string, ...) (string, error)
- func ReplaceRangesByFunc(s string, ref time.Time, f func(Range) string, options ...func(o *opts)) (string, error)
- func ReplaceTimesByFunc(s string, ref time.Time, f func(time.Time) string, options ...func(o *opts)) (string, error)
- type Range
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultToFuture ¶
func DefaultToFuture(o *opts)
DefaultToFuture sets the option to default to the future in case of ambiguous dates.
func DefaultToPast ¶
func DefaultToPast(o *opts)
DefaultToPast sets the option to default to the past in case of ambiguous dates.
func Parse ¶
Parse parses a string assumed to contain a date, a time, or a datetime in one of various formats.
func Parser ¶
Parser returns a parser of dates with a given reference time called ref. The result is a Range so that we have a time scale to work with, mainly for parsing implicit ranges within RangeParser().
func PartitionTimes ¶ added in v1.4.4
PartitionTimes returns a slice whose pieces are non-time pieces of s and time pieces of s, in order.
func PartitionTimesByFuncs ¶ added in v1.6.0
func PartitionTimesByFuncs(s string, ref time.Time, ntf func(nonTimeChunk string), tf func(timeChunk string, t time.Time), options ...func(o *opts))
PartitionTimesByFuncs partitions the given string s into time and non-time parts, calling ntf on the non-time parts and tf on the time parts in succession.
func RangeParser ¶
RangeParser takes a reference time ref and returns a parser for date ranges.
func ReplaceDateRangesByFunc ¶ added in v1.7.0
func ReplaceDateRangesByFunc(s string, ref time.Time, f func(source string, r Range) string, options ...func(o *opts)) (string, error)
ReplaceDateRangesByFunc replaces all ranges with duration over one day in the given string s by running func f on each found range and the source string that defines it.
func ReplaceRangesByFunc ¶ added in v1.4.0
func ReplaceRangesByFunc(s string, ref time.Time, f func(Range) string, options ...func(o *opts)) (string, error)
ReplaceRangesByFunc replaces all ranges found in the given string s by calling the func f. The ref and options arguments are the same as in ParseRange. Ranges like "today" that can also be parsed as non-ranges are skipped over.
func ReplaceTimesByFunc ¶ added in v1.4.0
func ReplaceTimesByFunc(s string, ref time.Time, f func(time.Time) string, options ...func(o *opts)) (string, error)
ReplaceTimesByFunc replaces all dates, times and datetimes found in the given string s by calling the func f. The ref and options arguments are the same as in Parse.
Types ¶
type Range ¶
Range is a time range.
func ParseRange ¶
ParseRange parses a string such as "from april 20 at 5pm to may 5 at 9pm" and returns a Range.
func RangeFromTimes ¶
RangeFromTimes returns a range given the start and end times.