Documentation
¶
Index ¶
- Variables
- type Humantime
- func (st *Humantime) After(input string) (*TimeRange, error)
- func (st *Humantime) Ago(input string) (*TimeRange, error)
- func (st *Humantime) Before(input string) (*TimeRange, error)
- func (st *Humantime) FromTo(input string) (*TimeRange, error)
- func (st *Humantime) Parse(input string) (*TimeRange, error)
- func (st *Humantime) Since(input string) (*TimeRange, error)
- func (st *Humantime) Until(input string) (*TimeRange, error)
- type TimeRange
Constants ¶
This section is empty.
Variables ¶
var DurationWords = map[string]time.Duration{ "second": time.Second, "seconds": time.Second, "minute": time.Minute, "minutes": time.Minute, "hour": time.Hour, "hours": time.Hour, "day": time.Hour * 24, "days": time.Hour * 24, "week": time.Hour * 24 * 7, "weeks": time.Hour * 24 * 7, "month": time.Hour * 24 * 7 * 30, "months": time.Hour * 24 * 7 * 30, "year": time.Second * 31536000, "years": time.Second * 31536000, }
DurationWords turns word durations into time.Duration
var StringToWeekdays = map[string]time.Weekday{ "monday": time.Monday, "tuesday": time.Tuesday, "webnesday": time.Wednesday, "thursday": time.Thursday, "friday": time.Friday, "saturday": time.Saturday, "sunday": time.Sunday, }
StringToWeekdays maps words to their time.Weekday counterparts
var TimeSynonyms = map[string]func(*time.Location) time.Time{ "yesterday": func(loc *time.Location) time.Time { var now = time.Now().Add(time.Hour * -24) var y, m, d = now.Date() return time.Date(y, m, d, 0, 0, 0, 0, loc) }, "today": func(loc *time.Location) time.Time { var now = time.Now() var y, m, d = now.Date() return time.Date(y, m, d, 0, 0, 0, 0, loc) }, "tomorrow": func(loc *time.Location) time.Time { var now = time.Now().Add(time.Hour * 24) var y, m, d = now.Date() return time.Date(y, m, d, 0, 0, 0, 0, loc) }, }
TimeSynonyms maps relative time words to time.Time based on the current wall time
Functions ¶
This section is empty.
Types ¶
type Humantime ¶
type Humantime struct {
*time.Location
AMOrPMRegex *regexp.Regexp
ExactTimeRegex *regexp.Regexp
SynonymRegex *regexp.Regexp
AtTimeRegex *regexp.Regexp
WeekdayRegex *regexp.Regexp
}
Humantime facilitates converting time in English words to a time.Time type
func NewString2Time ¶
NewString2Time is just a constructor
func (*Humantime) After ¶
After takes a string starting with the word after and parses the remainder as time.Time, examples: after 3/15/2022 after May 8, 2009 5:57:51 PM after 2am after yesterday after yesterday at 4pm after yesterday at 13:34:32
func (*Humantime) Ago ¶
Ago takes a string starting with the word since and parses the remainder as time.Time, examples: 3 hours ago 8 days and three hours ago 1 year 2 months 3 days 4 hours 5 minutes 6 seconds ago
func (*Humantime) Before ¶
Before takes a string starting with the word before and parses the remainder as time.Time, examples: before 3/15/2022 before May 8, 2009 5:57:51 PM before 2am before tomorrow before tomorrow at 4pm before tomorrow at 13:34:32
func (*Humantime) FromTo ¶
FromTo takes a string in the format from [date phrase] to [date phrase] and parses the remainder as time.Time, examples: from yesterday to today from May 8, 2009 5:57:51 PM to Sep 12, 2021 3:21:22 PM
func (*Humantime) Parse ¶
Parse is the entry point for parsing English input and performs the switching between different phrase types
func (*Humantime) Since ¶
Since takes a string starting with the word since and parses the remainder as time.Time, examples: since 3/15/2022 since May 8, 2009 5:57:51 PM since 2am since yesterday since yesterday at 4pm since yesterday at 13:34:32
type TimeRange ¶
TimeRange is the return type of this package
func (*TimeRange) Get ¶
Get fulfills the flag.Getter interface https://pkg.go.dev/flag#Getter
func (*TimeRange) Set ¶
Set fulfills the flag.Value interface https://pkg.go.dev/flag#Value must end in the format " in [timezone]" e.g. "3pm in America/New_York"
func (TimeRange) String ¶
String fulfills the flag.Value interface https://pkg.go.dev/flag#Value