merge pr utc support

This commit is contained in:
Aaron Raddon 2014-12-02 14:57:00 -08:00
commit 501e3eeb15
2 changed files with 22 additions and 0 deletions

View File

@ -16,6 +16,7 @@ const (
ST_DIGIT ST_DIGIT
ST_DIGITDASH ST_DIGITDASH
ST_DIGITDASHWS ST_DIGITDASHWS
ST_DIGITDASHWSALPHA
ST_DIGITDASHT ST_DIGITDASHT
ST_DIGITCOMMA ST_DIGITCOMMA
ST_DIGITCOLON ST_DIGITCOLON
@ -99,6 +100,7 @@ iterRunes:
// 2013-04-01 22:43:22 // 2013-04-01 22:43:22
// 2014-05-11 08:20:13,787 // 2014-05-11 08:20:13,787
// 2014-04-26 05:24:37 PM // 2014-04-26 05:24:37 PM
// 2014-12-16 06:20:00 UTC
switch r { switch r {
case 'A', 'P': case 'A', 'P':
if len(datestr) == len("2014-04-26 03:24:37 PM") { if len(datestr) == len("2014-04-26 03:24:37 PM") {
@ -121,6 +123,12 @@ iterRunes:
return time.Time{}, err return time.Time{}, err
} }
} }
default:
if unicode.IsLetter(r) {
// 2014-12-16 06:20:00 UTC
state = ST_DIGITDASHWSALPHA
break iterRunes
}
} }
case ST_DIGITDASHT: // starts digit then dash 02- then T case ST_DIGITDASHT: // starts digit then dash 02- then T
// 2006-01-02T15:04:05Z07:00 // 2006-01-02T15:04:05Z07:00
@ -353,6 +361,15 @@ iterRunes:
return time.Time{}, err return time.Time{}, err
} }
} }
case ST_DIGITDASHWSALPHA: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 3
// 2014-12-16 06:20:00 UTC
if len(datestr) == len("2006-01-02 15:04:05 UTC") {
if t, err := time.Parse("2006-01-02 15:04:05 UTC", datestr); err == nil {
return t, nil
} else {
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

@ -203,6 +203,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-04-26 17:24:37.123 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) assert.T(t, "2014-04-26 17:24:37.123 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2014-12-16 06:20:00 UTC")
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))