GitHub - ijt/go-anytime: Parse natural and standardized dates/times and ranges in Go without knowing the format in advance (original) (raw)

Go Anytime

Go Report Card codecov GoDoc Awesome

Natural date time parsing for Go. This package was originally forked fromgithub.com/tj/go-naturaldate but has diverged so much that it needed a new name to avoid confusion. Here are the largest differences:

  1. The go-anytime module is written in terms of the github.com/ijt/goparsify parser combinator module, rather than the github.com/pointlander/peg parsing module. That made its development and debugging easier, and also means that its parsers can be use within other parsers that use ijt/goparsify.
  2. Ranges can be parsed using ParseRange or RangeParser, for example "from 3 feb 2022 until 6 oct 2022".
  3. Dates/times and ranges can be replaced in strings using the funcs ReplaceTimesByFunc, ReplaceRangesByFunc, and ReplaceDateRangesByFunc.
  4. Strings can be partitioned into time and non-time parts using the funcs PartitionTimes and PartitionTimesByFuncs.

Examples

Here are some examples of expressions that can be parsed by anytime.Parse() or anytime.Parser:

Range examples

Here are some examples of expressions that can be parsed by anytime.ParseRange() or anytime.RangeParser:

About

Parse natural and standardized dates/times and ranges in Go without knowing the format in advance

Resources

Readme

License

MIT license

Activity

Stars

33 stars

Watchers

1 watching

Forks

3 forks