fxtlabs / date

A Go package for working with dates
https://godoc.org/github.com/fxtlabs/date
BSD 3-Clause "New" or "Revised" License
19 stars 5 forks source link

time.Date normalization #3

Open scafoglieri opened 6 years ago

scafoglieri commented 6 years ago

Hi, the Go function time.Date() have the normalization feature "built-in", so with incorrect input (like 31/04/2018 or 32/02/2018) we get a date, but not the expected one. Since the time.Date() function does not return any error, this behaviour can be acceptable. But in your library (https://github.com/rickb777/date) the ParseISO() function return an error and so I prefer to get just an error instead of a wrong (but well formatted) result with the previous inputs.

So, just in case this is useful even to others, we can get an error in ParseISO() adding (in file parse.go line 149):

    _, err = time.Parse("2006-01-02", abs[:dash1] + "-" + abs[fm1:fm2] + "-" + abs[fd1:])
    if err != nil {
        return Date{}, err
    }

    t := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC)

Thanks Michele