github.com/robertoortis/gqlgenm@v0.7.2/graphql/time.go (about) 1 package graphql 2 3 import ( 4 "errors" 5 "io" 6 "strconv" 7 "time" 8 ) 9 10 func MarshalTime(t time.Time) Marshaler { 11 return WriterFunc(func(w io.Writer) { 12 io.WriteString(w, strconv.Quote(t.Format(time.RFC3339))) 13 }) 14 } 15 16 func UnmarshalTime(v interface{}) (time.Time, error) { 17 if tmpStr, ok := v.(string); ok { 18 return time.Parse(time.RFC3339, tmpStr) 19 } 20 return time.Time{}, errors.New("time should be RFC3339 formatted string") 21 }