Added float64 to time conversion

This commit is contained in:
CBenni 2020-04-13 15:12:45 +02:00
parent 1ffadf5510
commit 6b8e137799
2 changed files with 3 additions and 0 deletions

View File

@ -1210,6 +1210,7 @@ func TestToTimeEE(t *testing.T) {
{uint(1482597504), time.Date(2016, 12, 24, 16, 38, 24, 0, time.UTC), false},
{uint64(1234567890), time.Date(2009, 2, 13, 23, 31, 30, 0, time.UTC), false},
{uint32(1234567890), time.Date(2009, 2, 13, 23, 31, 30, 0, time.UTC), false},
{float64(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},

View File

@ -39,6 +39,8 @@ func ToTimeE(i interface{}) (tim time.Time, err error) {
return time.Unix(int64(v), 0), nil
case uint32:
return time.Unix(int64(v), 0), nil
case float64:
return time.Unix(int64(v), 0), nil
default:
return time.Time{}, fmt.Errorf("unable to cast %#v of type %T to Time", i, i)
}