tj / go-naturaldate

Natural date/time parsing for Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support "6 month" with the future direction

NightMachinery opened this issue · comments

Prerequisites

  • I searched to see if the issue already exists.

Description

~/scripts/golang
❯ datenat.go 6 months from now
2021/03/03

~/scripts/golang
❯ datenat.go 6 month
2020/08/31

~/scripts/golang
❯ datenat.go 6 months
2020/08/31

~/scripts/golang
❯ datenat.go 6 months later
2020/08/31

Also, it's very jarring that the parsing succeeds on these examples. I think these should throw an error, as they contain important keywords like month that have been discarded.

BTW, that datenat.go is a simple CLI wrapper.

Same problem with 1 year, 2 years, etc.

Getting months by name is also broken:

❯ datenat.go 'next February'
2021/03/03

~/Base/_Code/python/fin master
❯ datenat.go 'next November'
2020/12/01

~/Base/_Code/python/fin master
❯ datenat.go 'next December'
2020/12/31

SGTM, happy to take a look at a PR, might be a little while until I can get to it

Hi, just wanted to add that I ended up here looking for a library that could support this specific use case. I tried to get something to parse "5 minutes" as a Duration instead of Time, implemented it using this library and substracting time.Now(), but didn't work as I expected :(