@@ -3,45 +3,46 @@ package time
33import "time"
44
55// DeisDatetimeFormat is the standard date/time representation used in Deis.
6- const DeisDatetimeFormat string = "2006-01-02T15:04:05MST"
6+ const DeisDatetimeFormat = "2006-01-02T15:04:05MST"
7+
78// Different format to deal with the pyopenssl formatting
89// http://www.pyopenssl.org/en/stable/api/crypto.html#OpenSSL.crypto.X509.get_notAfter
9- const PyOpenSSLTimeDateTimeFormat string = "2006-01-02T15:04:05"
10+ const PyOpenSSLTimeDateTimeFormat = "2006-01-02T15:04:05"
1011
1112// Time represents the standard datetime format used across the Deis Platform.
1213type Time struct {
13- time.Time
14+ * time.Time
1415}
1516
1617func (t * Time ) format () string {
17- return t .Time . Format (DeisDatetimeFormat )
18+ return t .Format (DeisDatetimeFormat )
1819}
1920
2021// MarshalJSON implements the json.Marshaler interface.
2122// The time is a quoted string in Deis' datetime format.
2223func (t * Time ) MarshalJSON () ([]byte , error ) {
23- return []byte (t .Time . Format (`"` + DeisDatetimeFormat + `"` )), nil
24+ return []byte (t .Format (`"` + DeisDatetimeFormat + `"` )), nil
2425}
2526
2627// UnmarshalText implements the encoding.TextUnmarshaler interface.
2728// The time is expected to be in Deis' datetime format.
28- func (t * Time ) UnmarshalText (data []byte ) ( err error ) {
29+ func (t * Time ) UnmarshalText (data []byte ) error {
2930 tt , err := time .Parse (DeisDatetimeFormat , string (data ))
30- if err != nil {
31+ if _ , ok := err .( * time. ParseError ); ok {
3132 tt , err = time .Parse (PyOpenSSLTimeDateTimeFormat , string (data ))
3233 }
33- * t = Time {tt }
34- return
34+ * t = Time {& tt }
35+ return err
3536}
3637
3738// UnmarshalJSON implements the json.Unmarshaler interface.
3839// The time is expected to be a quoted string in Deis' datetime format.
39- func (t * Time ) UnmarshalJSON (data []byte ) ( err error ) {
40+ func (t * Time ) UnmarshalJSON (data []byte ) error {
4041 // Fractional seconds are handled implicitly by Parse.
4142 tt , err := time .Parse (`"` + DeisDatetimeFormat + `"` , string (data ))
42- if err != nil {
43+ if _ , ok := err .( * time. ParseError ); ok {
4344 tt , err = time .Parse (`"` + PyOpenSSLTimeDateTimeFormat + `"` , string (data ))
4445 }
45- * t = Time {tt }
46- return
46+ * t = Time {& tt }
47+ return err
4748}
0 commit comments