Documentation
¶
Overview ¶
Package chronic is a pure-Go (no cgo) reimplementation of Ruby's `chronic` gem — a natural-language date and time parser. It turns English phrases such as "tomorrow", "next tuesday", "3 days ago", "may 27th" or "2016-05-27" into a concrete instant (or a Span), faithfully mirroring the deterministic grammar of chronic 0.10.2.
The entry point is Parse. It is deterministic: pass a fixed anchor via Options.Now and the result depends only on the input string, so it needs no Ruby runtime.
now := time.Date(2006, 8, 16, 14, 0, 0, 0, time.Local)
t, _ := chronic.Parse("tomorrow", chronic.Options{Now: now})
// t == 2006-08-17 12:00:00
Index ¶
Constants ¶
This section is empty.
Variables ¶
var TimeLoc = time.Local
TimeLoc is the location every constructed instant lives in. It mirrors MRI's Time.local, which builds times in the process-local zone. It is a package variable so callers (and the oracle tests) can pin it to a fixed zone for reproducibility.
Functions ¶
Types ¶
type Guess ¶
type Guess int
Guess selects whether Parse returns a single instant or the whole matched Span, and — for an instant — which point of the span to pick.
type Options ¶
type Options struct {
// Now is the anchor instant. Leave zero to use the current time. Pin it for
// deterministic parses.
Now time.Time
// Context resolves ambiguity toward the future (default) or past.
Context Context
// Guess selects the returned instant within the matched span.
Guess Guess
// AmbiguousTimeRange is the hour (1..12) an ambiguous bare time like "5" is
// assumed to fall within (AM..PM). Zero means the default of 6. Set
// AmbiguousTimeRangeNone to disable the assumption entirely.
AmbiguousTimeRange int
AmbiguousTimeRangeNone bool
// EndianLittle parses "03/04/2011" as day/month (d/m) rather than the
// default month/day (m/d).
EndianLittle bool
// WeekStart is the first day of the week ("sunday" default, or "monday").
WeekStart string
// Hours24 forces 24-hour interpretation when true; set Hours24Set together
// with Hours24=false to force 12-hour interpretation. When Hours24Set is
// false the parser auto-detects (the gem's nil).
Hours24 bool
Hours24Set bool
// AmbiguousYearFutureBias biases two-digit year expansion (default 50).
AmbiguousYearFutureBias int
}
Options configures a parse, mirroring Chronic::Parser's options hash. The zero value is valid and matches the gem's defaults (context future, guess middle, sunday week start, ambiguous-time-range 6, endian precedence middle-then- little, ambiguous-year-future-bias 50). Now defaults to time.Now.