araddon / dateparse

GoLang Parse many date strings without knowing format in advance.
MIT License
2.04k stars 163 forks source link

Names and addresses are parsed without an error #98

Open yonivy opened 4 years ago

yonivy commented 4 years ago
  1. Some name formats are successfully parsed as a valid date
  2. Some address formats are successfully parsed as a valid date

An working example can be found here. I also copied it here for reference.

package main

import (
    "fmt"
    "time"

    "github.com/araddon/dateparse"
)

func main() {   
    inputs := []string{
        // names
        "Wayne, Bruce",

        // addresses
        "Miami, Florida",

        // for some bizarre reason this fails to parse (that's good)
        "Doe, John",
    }

    for _, i := range inputs {
        dt, err := dateparse.ParseIn(i, time.FixedZone("", 0))
        fmt.Printf("input: %v\n", i)
        fmt.Printf("date:  %v\n", dt)
        fmt.Printf("error: %v\n\n", err)
    }   
}
input: Wayne, Bruce
date:  0000-01-01 00:00:00 +0000 +0000
error: <nil>

input: Miami, Florida
date:  0000-01-01 00:00:00 +0000 +0000
error: <nil>

input: Doe, John
date:  0001-01-01 00:00:00 +0000 UTC
error: parsing time "Doe, John" as "Mon, John": cannot parse "Doe, John" as "Mon"
phemmer commented 4 years ago

I have a somewhat similar issue which I think is related to this, in that if a string is only partially parsed, no error is emitted.

For example, I tried to parse 2019-09-01_01:00:00 (using ParseStrict), which ended up getting parsed as 2019-01-01 00:00:00 +0000 (only the year got parsed). If there were unknown data in the string, I would have expected some sort of error to be thrown. As it is there is no way to tell if the date was properly recognized, which is important when handling human input.

uditrana commented 4 years ago

Pretty much any string that satisfies the regex ^(\w+)(,\w+)+$gets parsed as a valid date. We are having to exempt out that regex to use this library.