Skip to content

ruggi/quando

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quando

Parse time and date with natural language.

The parser.Parse function returns a Result:

type Result struct {
    // The parsed time
    Time time.Time
    // The parsed duration
    Duration time.Duration
    // The text resulting from removing the matching time/date tokens from the original string
    Text string
    // The boundaries of the matching tokens
    Boundaries []Boundary
}

Usage

package main

import (
    "github.com/ruggi/quando"
)

func main() {
    p := quando.NewParser()
    res, err := p.Parse("buy groceries tomorrow at 2pm")
    if err != nil {
        // ...
    }

    fmt.Println(res.Time) // tomorrow at 2pm
    fmt.Println(res.Text) // "buy groceries"
}

Some examples

Input Time Duration Text
buy groceries today (midnight) 0 buy groceries
buy groceries in 5 minutes now + 5 minutes 0 buy groceries
gym for 3 hours in 2 weeks 2 weeks from now 3h gym
send christmas cards on dec 23, 2050 at 16:30 2050/12/23 16:30:00 0 send christmas cards

Credits

This started inspired by when, but with a slightly different take (e.g. support for durations, timezones, boundaries, etc.).

About

A Go package to parse dates, times, and durations with semi-natural language.

Resources

License

Stars

Watchers

Forks

Packages

No packages published