mirror of https://github.com/spf13/cast.git
Fixing parsing from string
This commit is contained in:
parent
8d351a4827
commit
e5ac093b2d
|
@ -1221,7 +1221,6 @@ func TestToTimeEE(t *testing.T) {
|
|||
{"1234567890", time.Date(2009, 2, 13, 23, 31, 30, 0, time.UTC), false},
|
||||
{time.Date(2009, 2, 13, 23, 31, 30, 0, time.UTC), time.Date(2009, 2, 13, 23, 31, 30, 0, time.UTC), false},
|
||||
// errors
|
||||
{"2006", time.Time{}, true},
|
||||
{testing.T{}, time.Time{}, true},
|
||||
}
|
||||
|
||||
|
|
5
caste.go
5
caste.go
|
@ -1272,10 +1272,9 @@ func parseDateWith(s string, dates []string) (d time.Time, e error) {
|
|||
if d, e = time.Parse(dateType, s); e == nil {
|
||||
return
|
||||
}
|
||||
if i, err := strconv.Atoi(dateType); err == nil {
|
||||
return time.Unix(int64(i), 0), nil
|
||||
}
|
||||
|
||||
if i, err := strconv.Atoi(s); err == nil {
|
||||
return time.Unix(int64(i), 0), nil
|
||||
}
|
||||
|
||||
return d, fmt.Errorf("unable to parse date: %s", s)
|
||||
|
|
Loading…
Reference in New Issue