1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-12 13:26:13 +00:00

Handle time.Time to string conversion

This commit is contained in:
Darren Shepherd
2018-01-01 22:08:39 -07:00
parent b80039523f
commit c94e18869a

View File

@@ -27,6 +27,9 @@ func Singular(value interface{}) interface{} {
}
func ToString(value interface{}) string {
if t, ok := value.(time.Time); ok {
return t.Format(time.RFC3339)
}
single := Singular(value)
if single == nil {
return ""
@@ -37,7 +40,7 @@ func ToString(value interface{}) string {
func ToTimestamp(value interface{}) (int64, error) {
str := ToString(value)
if str == "" {
return 0, errors.New("Invalid date")
return 0, errors.New("invalid date")
}
t, err := time.Parse(time.RFC3339, str)
if err != nil {