File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,17 +11,17 @@ const PyOpenSSLTimeDateTimeFormat = "2006-01-02T15:04:05"
1111
1212// Time represents the standard datetime format used across the Deis Platform.
1313type Time struct {
14- time.Time
14+ * time.Time
1515}
1616
1717func (t * Time ) format () string {
18- return t .Time . Format (DeisDatetimeFormat )
18+ return t .Format (DeisDatetimeFormat )
1919}
2020
2121// MarshalJSON implements the json.Marshaler interface.
2222// The time is a quoted string in Deis' datetime format.
2323func (t * Time ) MarshalJSON () ([]byte , error ) {
24- return []byte (t .Time . Format (`"` + DeisDatetimeFormat + `"` )), nil
24+ return []byte (t .Format (`"` + DeisDatetimeFormat + `"` )), nil
2525}
2626
2727// UnmarshalText implements the encoding.TextUnmarshaler interface.
@@ -31,7 +31,7 @@ func (t *Time) UnmarshalText(data []byte) error {
3131 if _ , ok := err .(* time.ParseError ); ok {
3232 tt , err = time .Parse (PyOpenSSLTimeDateTimeFormat , string (data ))
3333 }
34- * t = Time {tt }
34+ * t = Time {& tt }
3535 return err
3636}
3737
@@ -43,6 +43,6 @@ func (t *Time) UnmarshalJSON(data []byte) error {
4343 if _ , ok := err .(* time.ParseError ); ok {
4444 tt , err = time .Parse (`"` + PyOpenSSLTimeDateTimeFormat + `"` , string (data ))
4545 }
46- * t = Time {tt }
46+ * t = Time {& tt }
4747 return err
4848}
Original file line number Diff line number Diff line change 11package time
22
33import (
4+ "fmt"
45 "testing"
56)
67
78func TestUnMarshalText (t * testing.T ) {
89 dummyTime := Time {}
910
10- goodTimeFormats := []string {
11+ standardTimeFormats := []string {
1112 "2006-01-02T15:04:05MST" ,
12- "2006-01-02T15:04:05" ,
13+ "2006-01-02T15:04:05UTC" ,
14+ "2006-01-02T15:04:05PST" ,
1315 }
14- for _ , goodTime := range goodTimeFormats {
16+ for _ , goodTime := range standardTimeFormats {
1517 if dummyTime .UnmarshalText ([]byte (goodTime )) != nil {
1618 t .Error ("expected " + goodTime + " to be marshal-able." )
1719 }
20+ if dummyTime .Year () != 2006 {
21+ t .Error (fmt .Sprintf ("expected year to be 2006; got %d." , dummyTime .Year ()))
22+ }
23+ }
24+
25+ alternateTimeFormats := []string {
26+ "2007-01-02T15:04:05" ,
27+ "2007-01-02T15:04:05" ,
28+ "2007-01-02T15:04:05" ,
29+ }
30+
31+ for _ , goodTime := range alternateTimeFormats {
32+ if dummyTime .UnmarshalText ([]byte (goodTime )) != nil {
33+ t .Error ("expected " + goodTime + " to be marshal-able." )
34+ }
35+ if dummyTime .Year () != 2007 {
36+ t .Error (fmt .Sprintf ("expected year to be 2007; got %d." , dummyTime .Year ()))
37+ }
1838 }
1939
2040 badTime := "this is a bad time, isn't it?"
You can’t perform that action at this time.
0 commit comments