2019-02-09 12:30:49 +00:00
|
|
|
package utils
|
|
|
|
|
2019-03-05 01:14:52 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2019-03-09 18:14:55 +00:00
|
|
|
func ParseDateStringAsTime(dateString string) (time.Time, error) {
|
2019-02-09 12:30:49 +00:00
|
|
|
// https://stackoverflow.com/a/20234207 WTF?
|
2019-03-05 01:14:52 +00:00
|
|
|
|
|
|
|
t, e := time.Parse(time.RFC3339, dateString)
|
|
|
|
if e == nil {
|
2019-03-09 18:14:55 +00:00
|
|
|
return t, nil
|
2019-03-05 01:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t, e = time.Parse("2006-01-02", dateString)
|
|
|
|
if e == nil {
|
2019-03-09 18:14:55 +00:00
|
|
|
return t, nil
|
2019-03-05 01:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t, e = time.Parse("2006-01-02 15:04:05", dateString)
|
|
|
|
if e == nil {
|
2019-03-09 18:14:55 +00:00
|
|
|
return t, nil
|
2019-03-05 01:14:52 +00:00
|
|
|
}
|
|
|
|
|
2019-03-09 18:14:55 +00:00
|
|
|
return time.Time{}, fmt.Errorf("ParseDateStringAsTime failed: dateString <%s>", dateString)
|
2019-02-14 22:53:32 +00:00
|
|
|
}
|