mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
allow golangs wierd m=+0.00000 offset closes #57
This commit is contained in:
parent
b8014f0dba
commit
b0e7f69efa
43
parseany.go
43
parseany.go
@ -49,32 +49,32 @@ const (
|
|||||||
)
|
)
|
||||||
const (
|
const (
|
||||||
// Time state
|
// Time state
|
||||||
timeIgnore timeState = iota
|
timeIgnore timeState = iota // 0
|
||||||
timeStart
|
timeStart
|
||||||
timeWs
|
timeWs
|
||||||
timeWsAlpha
|
timeWsAlpha
|
||||||
timeWsAlphaWs
|
timeWsAlphaWs
|
||||||
timeWsAlphaZoneOffset
|
timeWsAlphaZoneOffset // 5
|
||||||
timeWsAlphaZoneOffsetWs
|
timeWsAlphaZoneOffsetWs
|
||||||
timeWsAlphaZoneOffsetWsYear
|
timeWsAlphaZoneOffsetWsYear
|
||||||
timeWsAlphaZoneOffsetWsExtra
|
timeWsAlphaZoneOffsetWsExtra
|
||||||
timeWsAMPMMaybe
|
timeWsAMPMMaybe
|
||||||
timeWsAMPM
|
timeWsAMPM // 10
|
||||||
timeWsOffset
|
timeWsOffset
|
||||||
timeWsOffsetWs
|
timeWsOffsetWs // 12
|
||||||
timeWsOffsetColonAlpha
|
timeWsOffsetColonAlpha
|
||||||
timeWsOffsetColon
|
timeWsOffsetColon
|
||||||
timeWsYear
|
timeWsYear // 15
|
||||||
timeOffset
|
timeOffset
|
||||||
timeOffsetColon
|
timeOffsetColon
|
||||||
timeAlpha
|
timeAlpha
|
||||||
timePeriod
|
timePeriod
|
||||||
timePeriodOffset
|
timePeriodOffset // 20
|
||||||
timePeriodOffsetColon
|
timePeriodOffsetColon
|
||||||
timePeriodOffsetColonWs
|
timePeriodOffsetColonWs
|
||||||
timePeriodWs
|
timePeriodWs
|
||||||
timePeriodWsAlpha
|
timePeriodWsAlpha
|
||||||
timePeriodWsOffset
|
timePeriodWsOffset // 25
|
||||||
timePeriodWsOffsetWs
|
timePeriodWsOffsetWs
|
||||||
timePeriodWsOffsetWsAlpha
|
timePeriodWsOffsetWsAlpha
|
||||||
timePeriodWsOffsetColon
|
timePeriodWsOffsetColon
|
||||||
@ -833,6 +833,7 @@ iterRunes:
|
|||||||
// 05:24:37 PM
|
// 05:24:37 PM
|
||||||
// 06:20:00 UTC
|
// 06:20:00 UTC
|
||||||
// 00:12:00 +0000 UTC
|
// 00:12:00 +0000 UTC
|
||||||
|
// 22:18:00 +0000 UTC m=+0.000000001
|
||||||
// 15:04:05 -0700
|
// 15:04:05 -0700
|
||||||
// 15:04:05 -07:00
|
// 15:04:05 -07:00
|
||||||
// 15:04:05 2008
|
// 15:04:05 2008
|
||||||
@ -854,6 +855,7 @@ iterRunes:
|
|||||||
// 00:00:00.000 +0000
|
// 00:00:00.000 +0000
|
||||||
// timePeriodWsOffsetAlpha
|
// timePeriodWsOffsetAlpha
|
||||||
// 00:07:31.945167 +0000 UTC
|
// 00:07:31.945167 +0000 UTC
|
||||||
|
// 22:18:00.001 +0000 UTC m=+0.000000001
|
||||||
// 00:00:00.000 +0000 UTC
|
// 00:00:00.000 +0000 UTC
|
||||||
// timePeriodWsAlpha
|
// timePeriodWsAlpha
|
||||||
// 06:20:00.000 UTC
|
// 06:20:00.000 UTC
|
||||||
@ -1054,16 +1056,27 @@ iterRunes:
|
|||||||
case timeWsOffsetWs:
|
case timeWsOffsetWs:
|
||||||
// 17:57:51 -0700 2009
|
// 17:57:51 -0700 2009
|
||||||
// 00:12:00 +0000 UTC
|
// 00:12:00 +0000 UTC
|
||||||
if unicode.IsDigit(r) {
|
// 22:18:00.001 +0000 UTC m=+0.000000001
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case unicode.IsDigit(r):
|
||||||
p.yearlen = i - p.yeari + 1
|
p.yearlen = i - p.yeari + 1
|
||||||
if p.yearlen == 4 {
|
if p.yearlen == 4 {
|
||||||
p.setYear()
|
p.setYear()
|
||||||
}
|
}
|
||||||
} else if unicode.IsLetter(r) {
|
case unicode.IsLetter(r):
|
||||||
if p.tzi == 0 {
|
if p.tzi == 0 {
|
||||||
p.tzi = i
|
p.tzi = i
|
||||||
}
|
}
|
||||||
|
case r == '=':
|
||||||
|
// eff you golang
|
||||||
|
if datestr[i-1] == 'm' {
|
||||||
|
p.extra = i - 2
|
||||||
|
p.trimExtra()
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case timeWsOffsetColon:
|
case timeWsOffsetColon:
|
||||||
// timeWsOffsetColon
|
// timeWsOffsetColon
|
||||||
// 15:04:05 -07:00
|
// 15:04:05 -07:00
|
||||||
@ -1098,6 +1111,7 @@ iterRunes:
|
|||||||
// timePeriodWsOffsetAlpha
|
// timePeriodWsOffsetAlpha
|
||||||
// 00:07:31.945167 +0000 UTC
|
// 00:07:31.945167 +0000 UTC
|
||||||
// 00:00:00.000 +0000 UTC
|
// 00:00:00.000 +0000 UTC
|
||||||
|
// 22:18:00.001 +0000 UTC m=+0.000000001
|
||||||
// timePeriodWsAlpha
|
// timePeriodWsAlpha
|
||||||
// 06:20:00.000 UTC
|
// 06:20:00.000 UTC
|
||||||
switch r {
|
switch r {
|
||||||
@ -1175,6 +1189,7 @@ iterRunes:
|
|||||||
// timePeriodWsOffsetAlpha
|
// timePeriodWsOffsetAlpha
|
||||||
// 00:07:31.945167 +0000 UTC
|
// 00:07:31.945167 +0000 UTC
|
||||||
// 00:00:00.000 +0000 UTC
|
// 00:00:00.000 +0000 UTC
|
||||||
|
// 03:02:00.001 +0300 MSK m=+0.000000001
|
||||||
// timePeriodWsOffsetColon
|
// timePeriodWsOffsetColon
|
||||||
// 13:31:51.999 -07:00 MST
|
// 13:31:51.999 -07:00 MST
|
||||||
// timePeriodWsAlpha
|
// timePeriodWsAlpha
|
||||||
@ -1188,10 +1203,18 @@ iterRunes:
|
|||||||
if unicode.IsLetter(r) {
|
if unicode.IsLetter(r) {
|
||||||
// 00:07:31.945167 +0000 UTC
|
// 00:07:31.945167 +0000 UTC
|
||||||
// 00:00:00.000 +0000 UTC
|
// 00:00:00.000 +0000 UTC
|
||||||
|
// 03:02:00.001 +0300 MSK m=+0.000000001
|
||||||
p.stateTime = timePeriodWsOffsetWsAlpha
|
p.stateTime = timePeriodWsOffsetWsAlpha
|
||||||
break iterTimeRunes
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case timePeriodWsOffsetWsAlpha:
|
||||||
|
// 03:02:00.001 +0300 MSK m=+0.000000001
|
||||||
|
// eff you golang
|
||||||
|
if r == '=' && datestr[i-1] == 'm' {
|
||||||
|
p.extra = i - 2
|
||||||
|
p.trimExtra()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
case timePeriodWsOffsetColon:
|
case timePeriodWsOffsetColon:
|
||||||
// 13:31:51.999 -07:00 MST
|
// 13:31:51.999 -07:00 MST
|
||||||
|
@ -126,8 +126,10 @@ func TestInLocation(t *testing.T) {
|
|||||||
func TestOne(t *testing.T) {
|
func TestOne(t *testing.T) {
|
||||||
time.Local = time.UTC
|
time.Local = time.UTC
|
||||||
var ts time.Time
|
var ts time.Time
|
||||||
ts = MustParse("2018-04-02T22:18+0000")
|
// {in: "2015-02-08 03:02:00 +0300 MSK m=+0.000000001", out: "2015-02-08 00:02:00 +0000 UTC"},
|
||||||
assert.Equal(t, "2018-04-02 22:18:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
// {in: "2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001", out: "2015-02-08 00:02:00.001 +0000 UTC"},
|
||||||
|
ts = MustParse("2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001")
|
||||||
|
assert.Equal(t, "2015-02-08 00:02:00.001 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
}
|
}
|
||||||
|
|
||||||
type dateTest struct {
|
type dateTest struct {
|
||||||
@ -347,6 +349,9 @@ var testInputs = []dateTest{
|
|||||||
{in: "2014-04-26 17:24:37.123456 +0000 UTC", out: "2014-04-26 17:24:37.123456 +0000 UTC"},
|
{in: "2014-04-26 17:24:37.123456 +0000 UTC", out: "2014-04-26 17:24:37.123456 +0000 UTC"},
|
||||||
{in: "2014-04-26 17:24:37.12 +0000 UTC", out: "2014-04-26 17:24:37.12 +0000 UTC"},
|
{in: "2014-04-26 17:24:37.12 +0000 UTC", out: "2014-04-26 17:24:37.12 +0000 UTC"},
|
||||||
{in: "2014-04-26 17:24:37.1 +0000 UTC", out: "2014-04-26 17:24:37.1 +0000 UTC"},
|
{in: "2014-04-26 17:24:37.1 +0000 UTC", out: "2014-04-26 17:24:37.1 +0000 UTC"},
|
||||||
|
{in: "2015-02-08 03:02:00 +0200 CEST m=+0.000000001", out: "2015-02-08 01:02:00 +0000 UTC", loc: "Europe/Berlin"},
|
||||||
|
{in: "2015-02-08 03:02:00 +0300 MSK m=+0.000000001", out: "2015-02-08 00:02:00 +0000 UTC"},
|
||||||
|
{in: "2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001", out: "2015-02-08 00:02:00.001 +0000 UTC"},
|
||||||
// yyyy-mm-dd hh:mm:ss TZ
|
// yyyy-mm-dd hh:mm:ss TZ
|
||||||
{in: "2012-08-03 18:31:59 UTC", out: "2012-08-03 18:31:59 +0000 UTC"},
|
{in: "2012-08-03 18:31:59 UTC", out: "2012-08-03 18:31:59 +0000 UTC"},
|
||||||
{in: "2014-12-16 06:20:00 GMT", out: "2014-12-16 06:20:00 +0000 UTC"},
|
{in: "2014-12-16 06:20:00 GMT", out: "2014-12-16 06:20:00 +0000 UTC"},
|
||||||
|
Loading…
Reference in New Issue
Block a user