mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
new format(no seconds) closes #58
This commit is contained in:
parent
1d3842569f
commit
f40887f3bf
@ -821,7 +821,7 @@ iterRunes:
|
|||||||
for ; i < len(datestr); i++ {
|
for ; i < len(datestr); i++ {
|
||||||
r := rune(datestr[i])
|
r := rune(datestr[i])
|
||||||
|
|
||||||
//gou.Debugf("%d %s iterTimeRunes %s %s", i, string(r), p.ds(), p.ts())
|
//gou.Debugf("%d %s %d iterTimeRunes %s %s", i, string(r), p.stateTime, p.ds(), p.ts())
|
||||||
|
|
||||||
switch p.stateTime {
|
switch p.stateTime {
|
||||||
case timeStart:
|
case timeStart:
|
||||||
@ -871,7 +871,12 @@ iterRunes:
|
|||||||
case '-', '+':
|
case '-', '+':
|
||||||
// 03:21:51+00:00
|
// 03:21:51+00:00
|
||||||
p.stateTime = timeOffset
|
p.stateTime = timeOffset
|
||||||
p.seclen = i - p.seci
|
if p.seci == 0 {
|
||||||
|
// 22:18+0530
|
||||||
|
p.minlen = i - p.mini
|
||||||
|
} else {
|
||||||
|
p.seclen = i - p.seci
|
||||||
|
}
|
||||||
p.offseti = i
|
p.offseti = i
|
||||||
case '.':
|
case '.':
|
||||||
p.stateTime = timePeriod
|
p.stateTime = timePeriod
|
||||||
|
@ -126,8 +126,8 @@ 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("2014-05-11 08:20:13,787")
|
ts = MustParse("2018-04-02T22:18+0000")
|
||||||
assert.Equal(t, "2014-05-11 08:20:13.787 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.Equal(t, "2018-04-02 22:18:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
}
|
}
|
||||||
|
|
||||||
type dateTest struct {
|
type dateTest struct {
|
||||||
@ -310,6 +310,9 @@ var testInputs = []dateTest{
|
|||||||
{in: "2014-04-26 17:24:37.12 +0000", out: "2014-04-26 17:24:37.12 +0000 UTC"},
|
{in: "2014-04-26 17:24:37.12 +0000", out: "2014-04-26 17:24:37.12 +0000 UTC"},
|
||||||
{in: "2014-04-26 17:24:37.1 +0000", out: "2014-04-26 17:24:37.1 +0000 UTC"},
|
{in: "2014-04-26 17:24:37.1 +0000", out: "2014-04-26 17:24:37.1 +0000 UTC"},
|
||||||
{in: "2014-05-11 08:20:13 +0000", out: "2014-05-11 08:20:13 +0000 UTC"},
|
{in: "2014-05-11 08:20:13 +0000", out: "2014-05-11 08:20:13 +0000 UTC"},
|
||||||
|
// yyyy-mm-dd hh:mm:ss+0000
|
||||||
|
// yyyy-mm-dd hh:mm+0000
|
||||||
|
{in: "2014-05-11 08:20:13 +0530", out: "2014-05-11 02:50:13 +0000 UTC"},
|
||||||
|
|
||||||
// 13:31:51.999 -07:00 MST
|
// 13:31:51.999 -07:00 MST
|
||||||
// yyyy-mm-dd hh:mm:ss +00:00
|
// yyyy-mm-dd hh:mm:ss +00:00
|
||||||
@ -400,6 +403,8 @@ var testInputs = []dateTest{
|
|||||||
{in: "2016-06-21T19:55:00+0100", out: "2016-06-21 18:55:00 +0000 UTC"},
|
{in: "2016-06-21T19:55:00+0100", out: "2016-06-21 18:55:00 +0000 UTC"},
|
||||||
{in: "2016-06-21T19:55:00-0700", out: "2016-06-22 02:55:00 +0000 UTC"},
|
{in: "2016-06-21T19:55:00-0700", out: "2016-06-22 02:55:00 +0000 UTC"},
|
||||||
{in: "2016-06-21T19:55:00.799+0100", out: "2016-06-21 18:55:00.799 +0000 UTC"},
|
{in: "2016-06-21T19:55:00.799+0100", out: "2016-06-21 18:55:00.799 +0000 UTC"},
|
||||||
|
{in: "2016-06-21T19:55+0100", out: "2016-06-21 18:55:00 +0000 UTC"},
|
||||||
|
{in: "2016-06-21T19:55+0130", out: "2016-06-21 18:25:00 +0000 UTC"},
|
||||||
// yyyy-mm-ddThh:mm:ssZ
|
// yyyy-mm-ddThh:mm:ssZ
|
||||||
{in: "2009-08-12T22:15Z", out: "2009-08-12 22:15:00 +0000 UTC"},
|
{in: "2009-08-12T22:15Z", out: "2009-08-12 22:15:00 +0000 UTC"},
|
||||||
{in: "2009-08-12T22:15:09Z", out: "2009-08-12 22:15:09 +0000 UTC"},
|
{in: "2009-08-12T22:15:09Z", out: "2009-08-12 22:15:09 +0000 UTC"},
|
||||||
|
Loading…
Reference in New Issue
Block a user