when
when copied to clipboard
Common US dates not working.
Not getting a date back for standard U.S. format: "10/20" or "10/20/17". Getting a panic on "10/20/2017":
package main
import (
"fmt"
"os"
"time"
"github.com/olebedev/when"
"github.com/olebedev/when/rules/common"
"github.com/olebedev/when/rules/en"
)
func main() {
w := when.New(nil)
w.Add(en.All...)
w.Add(common.All...)
text := "10/20/2017"
r, err := w.Parse(text, time.Now())
if err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
if r == nil {
fmt.Println("NO MATCH")
os.Exit(1)
}
fmt.Println(
"the time",
r.Time.String(),
"mentioned in",
text[r.Index:r.Index+len(r.Text)],
)
}
Hi @JamesHaskell, thanks for the report! I will dig into it soon. It seems we have to add yet another rule for US date format.
@olebedev, as a solution you can just pass everything that looks like a date ((\d\s\:\.\-)
) into dateparse. Let's do OSS "Stand on the shoulders of giants" :)
The panic situation is resolved by #37. A wider discussion around parsing of the US data format is happening here #19.