https://github.com/pnelson/when
Package when implements a natural language date/time arithmetic parser.
https://github.com/pnelson/when
Last synced: 6 months ago
JSON representation
Package when implements a natural language date/time arithmetic parser.
- Host: GitHub
- URL: https://github.com/pnelson/when
- Owner: pnelson
- License: isc
- Created: 2022-05-30T01:35:14.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-23T02:11:50.000Z (over 3 years ago)
- Last Synced: 2025-10-13T05:13:03.824Z (9 months ago)
- Language: Go
- Size: 51.8 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# when
Package when implements a natural language date/time arithmetic parser.
Parse a duration that resolves to a time in the future:
```go
t, err := when.Parse("6 hours")
```
This can be reversed:
```go
t, err := when.Parse("6 hours ago")
```
Digits up to twelve can be spelled:
```go
t, err := when.Parse("six hours ago")
```
Short units are fine, too:
```go
t, err := when.Parse("6h ago")
```
You don't need to use durations at all:
```go
t, err := when.Parse("Jan 2nd at 3pm")
```
But if you do, they can be made relative to a specific time:
```go
t, err := when.Parse("6 hours from Jan 2nd at 3pm")
```
Again, but in reverse:
```go
t, err := when.Parse("6 hours before Jan 2nd at 3pm")
```
You can be a bit more casual with the time:
```go
t, err := when.Parse("3 o'clock in the afternoon")
```
Or you can go full tilt:
```go
s := "1y 2M and 3w & 4d, 5h"
s += " from quarter past 3 o'clock in the afternoon"
s += " on the 2nd Tuesday of March"
s += " + 6 minutes - 7 seconds"
t, err := when.Parse(s)
```