Merge pull request #9 from junichif/master

Parse another format
This commit is contained in:
Aaron Raddon 2017-05-03 14:45:44 -07:00 committed by GitHub
commit b008e51bc1
2 changed files with 26 additions and 15 deletions

View File

@ -209,22 +209,9 @@ iterRunes:
return time.Time{}, err return time.Time{}, err
} }
} else { } else {
// updated to include timestamps of different precisions if t, err := time.Parse("2006-01-02T15:04:05Z", datestr); err == nil {
if t, err := time.Parse("2006-01-02T15:04:05.999999999Z", datestr); err == nil {
return t, nil return t, nil
} else if t, err := time.Parse("2006-01-02T15:04:05.99999999Z", datestr); err == nil { } else if t, err := time.Parse("2006-01-02T15:04:05", datestr); err == nil {
return t, nil
} else if t, err := time.Parse("2006-01-02T15:04:05.9999999Z", datestr); err == nil {
return t, nil
} else if t, err := time.Parse("2006-01-02T15:04:05.999999Z", datestr); err == nil {
return t, nil
} else if t, err := time.Parse("2006-01-02T15:04:05.99999Z", datestr); err == nil {
return t, nil
} else if t, err := time.Parse("2006-01-02T15:04:05.9999Z", datestr); err == nil {
return t, nil
} else if t, err := time.Parse("2006-01-02T15:04:05.999Z", datestr); err == nil {
return t, nil
} else if t, err := time.Parse("2006-01-02T15:04:05.99Z", datestr); err == nil {
return t, nil return t, nil
} else { } else {
return time.Time{}, err return time.Time{}, err

View File

@ -270,6 +270,30 @@ func TestParse(t *testing.T) {
assertf(t, err == nil, "%v", err) assertf(t, err == nil, "%v", err)
assert(t, "2009-08-12 22:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) assert(t, "2009-08-12 22:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2009-08-12T22:15:09.99Z")
assertf(t, err == nil, "%v", err)
assert(t, "2009-08-12 22:15:09.99 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2009-08-12T22:15:09.9999Z")
assertf(t, err == nil, "%v", err)
assert(t, "2009-08-12 22:15:09.9999 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2009-08-12T22:15:09.99999999Z")
assertf(t, err == nil, "%v", err)
assert(t, "2009-08-12 22:15:09.99999999 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2009-08-12T22:15:09.123")
assertf(t, err == nil, "%v", err)
assert(t, "2009-08-12 22:15:09.123 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2009-08-12T22:15:09.12")
assertf(t, err == nil, "%v", err)
assert(t, "2009-08-12 22:15:09.12 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2009-08-12T22:15:09.1")
assertf(t, err == nil, "%v", err)
assert(t, "2009-08-12 22:15:09.1 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2009-08-12T22:15:09") ts, err = ParseAny("2009-08-12T22:15:09")
assertf(t, err == nil, "%v", err) assertf(t, err == nil, "%v", err)
assert(t, "2009-08-12 22:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) assert(t, "2009-08-12 22:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))