GitXplorerGitXplorer
i

go-anytime

public
24 stars
2 forks
4 issues

Commits

List of commits on branch main.
Verified
3183858dfff2a929e53faad28f0b705586527da3

Merge pull request #65 from ijt/issue/64/dec-2031

iijt committed 2 years ago
Unverified
ae3874a6503fd083c557cdbc7a900e599d5b222e

handle test cases for "dec-2031" and "2031-dec"

iijt committed 2 years ago
Unverified
e245739a34233bb6df526fe327506d2e3214752c

add test cases for "dec-2031" and "2031-dec"

iijt committed 2 years ago
Unverified
cce23a42830e06f87498ebb0a6a3af7337fb75f7

put tests in a slightly more logical order

iijt committed 2 years ago
Verified
4f5e32e1a5273fca118210c395724eb5c57d0fb0

Merge pull request #63 from ijt/issue/62/MMM-DD-direction

iijt committed 2 years ago
Unverified
d94c87a4cb09ef5a3fcd196dc0aa38734e625068

shave off a few usec by adding a fast check for digits in parseDayOfMonthNoCheck

iijt committed 2 years ago

README

The README file for this repository.

Go Anytime

Go Report Card codecov GoDoc Awesome

Natural date time parsing for Go. This package was originally forked from github.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:

  • now
  • today
  • yesterday
  • 5 minutes ago
  • three days ago
  • last month
  • next month
  • one year from now
  • yesterday at 10am
  • last sunday at 5:30pm
  • next sunday at 22:45
  • next January
  • last February
  • next December 25th at 7:30am
  • next December 25th at 7:30am UTC-7
  • November 3rd, 1986 at 4:30pm
  • january 2017
  • january, 2017
  • oct 7, 1970
  • oct 7 1970
  • 7 oct 1970
  • 7 oct, 1970
  • September 17, 2012 UTC+7
  • September 17, 2012
  • 03 February 2013
  • 2 July 2013
  • 2014/3/31
  • 2014/3/31 UTC
  • 2014/3/31 UTC+1
  • 2014/03/31
  • 2014/03/31 UTC-1
  • 2014-04-26
  • 2014-4-26
  • 2014-4-6
  • 31/3/2014 UTC-8
  • 31-3-2014 UTC-8
  • 31/3/2014
  • 31-3-2014
  • January
  • december 20
  • thursday at 23:59
  • See the tests for more examples

Range examples

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

  • from 3 feb 2022 to 6 oct 2022
  • 3 feb 2022 to 6 oct 2022
  • from 3 feb 2022 until 6 oct 2022
  • from tuesday at 5pm -12:00 until thursday 23:52 +14:00
  • last year
  • today
  • next week