Skip to content

Common US dates not working. #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JamesHaskell opened this issue Nov 4, 2017 · 3 comments
Closed

Common US dates not working. #10

JamesHaskell opened this issue Nov 4, 2017 · 3 comments

Comments

@JamesHaskell
Copy link

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)],
	)
}
@olebedev
Copy link
Owner

olebedev commented Nov 6, 2017

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.

@orsinium
Copy link

@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" :)

@olebedev
Copy link
Owner

olebedev commented May 31, 2023

The panic situation is resolved by #37. A wider discussion around parsing of the US data format is happening here #19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants