add support for GMT formatted offsets

This commit is contained in:
drewlanenga 2016-09-13 10:40:04 -04:00
parent 86f3852b68
commit c1159e2c50
2 changed files with 29 additions and 4 deletions

View File

@ -496,28 +496,44 @@ iterRunes:
case len("2006-01-02 15:04:05 UTC"): case len("2006-01-02 15:04:05 UTC"):
if t, err := time.Parse("2006-01-02 15:04:05 UTC", datestr); err == nil { if t, err := time.Parse("2006-01-02 15:04:05 UTC", datestr); err == nil {
return t, nil return t, nil
} else {
if t, err := time.Parse("2006-01-02 15:04:05 GMT", datestr); err == nil {
return t, nil
} else { } else {
return time.Time{}, err return time.Time{}, err
} }
}
case len("2015-02-18 00:12:00 +0000 UTC"): case len("2015-02-18 00:12:00 +0000 UTC"):
if t, err := time.Parse("2006-01-02 15:04:05 +0000 UTC", datestr); err == nil { if t, err := time.Parse("2006-01-02 15:04:05 +0000 UTC", datestr); err == nil {
return t, nil return t, nil
} else {
if t, err = time.Parse("2006-01-02 15:04:05 +0000 GMT", datestr); err == nil {
return t, nil
} else { } else {
return time.Time{}, err return time.Time{}, err
} }
}
case len("2015-09-30 18:48:56.35272715 +0000 UTC"): case len("2015-09-30 18:48:56.35272715 +0000 UTC"):
if t, err := time.Parse("2006-01-02 15:04:05.00000000 +0000 UTC", datestr); err == nil { if t, err := time.Parse("2006-01-02 15:04:05.00000000 +0000 UTC", datestr); err == nil {
return t, nil return t, nil
} else {
if t, err := time.Parse("2006-01-02 15:04:05.00000000 +0000 GMT", datestr); err == nil {
return t, nil
} else { } else {
return time.Time{}, err return time.Time{}, err
} }
}
case len("2015-06-25 01:25:37.115208593 +0000 UTC"): case len("2015-06-25 01:25:37.115208593 +0000 UTC"):
if t, err := time.Parse("2006-01-02 15:04:05.000000000 +0000 UTC", datestr); err == nil { if t, err := time.Parse("2006-01-02 15:04:05.000000000 +0000 UTC", datestr); err == nil {
return t, nil return t, nil
} else {
if t, err := time.Parse("2006-01-02 15:04:05.000000000 +0000 GMT", datestr); err == nil {
return t, nil
} else { } else {
return time.Time{}, err return time.Time{}, err
} }
} }
}
case ST_DIGITSLASH: // starts digit then slash 02/ (but nothing else) case ST_DIGITSLASH: // starts digit then slash 02/ (but nothing else)
// 3/1/2014 // 3/1/2014
// 10/13/2014 // 10/13/2014

View File

@ -117,6 +117,10 @@ func TestParse(t *testing.T) {
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
assert.T(t, "2006-01-02 22:04:05 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) assert.T(t, "2006-01-02 22:04:05 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2015-02-18 00:12:00 +0000 GMT")
assert.Tf(t, err == nil, "%v", err)
assert.T(t, "2015-02-18 00:12:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
// Golang Native Format // Golang Native Format
ts, err = ParseAny("2015-02-18 00:12:00 +0000 UTC") ts, err = ParseAny("2015-02-18 00:12:00 +0000 UTC")
assert.Tf(t, err == nil, "%v", err) assert.Tf(t, err == nil, "%v", err)
@ -277,6 +281,11 @@ func TestParse(t *testing.T) {
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
assert.T(t, "2014-12-16 06:20:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) assert.T(t, "2014-12-16 06:20:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2014-12-16 06:20:00 GMT")
assert.Tf(t, err == nil, "%v", err)
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
assert.T(t, "2014-12-16 06:20:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2014-04-26 05:24:37 PM") ts, err = ParseAny("2014-04-26 05:24:37 PM")
assert.Tf(t, err == nil, "%v", err) assert.Tf(t, err == nil, "%v", err)
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))