Skip to content

Latest commit

 

History

History
61 lines (42 loc) · 1 KB

README.md

File metadata and controls

61 lines (42 loc) · 1 KB

when

Package when implements a natural language date/time arithmetic parser.

Parse a duration that resolves to a time in the future:

t, err := when.Parse("6 hours")

This can be reversed:

t, err := when.Parse("6 hours ago")

Digits up to twelve can be spelled:

t, err := when.Parse("six hours ago")

Short units are fine, too:

t, err := when.Parse("6h ago")

You don't need to use durations at all:

t, err := when.Parse("Jan 2nd at 3pm")

But if you do, they can be made relative to a specific time:

t, err := when.Parse("6 hours from Jan 2nd at 3pm")

Again, but in reverse:

t, err := when.Parse("6 hours before Jan 2nd at 3pm")

You can be a bit more casual with the time:

t, err := when.Parse("3 o'clock in the afternoon")

Or you can go full tilt:

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)