Skip to content

Commit

Permalink
Handle time.Time to string conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Jan 2, 2018
1 parent b800395 commit c94e188
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion types/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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 {
Expand Down

0 comments on commit c94e188

Please sign in to comment.