Skip to content

Commit 49ce800

Browse files
committed
Merge pull request #10 from helgi/time
feat(time): add a fallback understanding of pyopenssl formats
2 parents 09ab3eb + 8f6c0e0 commit 49ce800

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

time/time.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package time
33
import "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 string = "2006-01-02T15:04:05MST"
7+
// Different format to deal with the pyopenssl formatting
8+
// http://www.pyopenssl.org/en/stable/api/crypto.html#OpenSSL.crypto.X509.get_notAfter
9+
const PyOpenSSLTimeDateTimeFormat string = "2006-01-02T15:04:05"
710

811
// Time represents the standard datetime format used across the Deis Platform.
912
type Time struct {
@@ -24,6 +27,9 @@ func (t *Time) MarshalJSON() ([]byte, error) {
2427
// The time is expected to be in Deis' datetime format.
2528
func (t *Time) UnmarshalText(data []byte) (err error) {
2629
tt, err := time.Parse(DeisDatetimeFormat, string(data))
30+
if err != nil {
31+
tt, err = time.Parse(PyOpenSSLTimeDateTimeFormat, string(data))
32+
}
2733
*t = Time{tt}
2834
return
2935
}
@@ -33,6 +39,9 @@ func (t *Time) UnmarshalText(data []byte) (err error) {
3339
func (t *Time) UnmarshalJSON(data []byte) (err error) {
3440
// Fractional seconds are handled implicitly by Parse.
3541
tt, err := time.Parse(`"`+DeisDatetimeFormat+`"`, string(data))
42+
if err != nil {
43+
tt, err = time.Parse(`"`+PyOpenSSLTimeDateTimeFormat+`"`, string(data))
44+
}
3645
*t = Time{tt}
3746
return
3847
}

0 commit comments

Comments
 (0)