mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
two more date formats
This commit is contained in:
parent
cf36286fa6
commit
9486d2dfd3
25
parseany.go
25
parseany.go
@ -108,6 +108,7 @@ iterRunes:
|
||||
}
|
||||
case 256: // starts digit then slash 02/
|
||||
// 03/19/2012 10:11:59
|
||||
// 04/2/2014 03:00:37
|
||||
// 3/1/2012 10:11:59
|
||||
// 4/8/2014 22:05
|
||||
// 3/1/2014
|
||||
@ -122,6 +123,7 @@ iterRunes:
|
||||
}
|
||||
case 2048: // starts digit then slash 02/ more digits/slashes then whitespace
|
||||
// 03/19/2012 10:11:59
|
||||
// 04/2/2014 03:00:37
|
||||
// 3/1/2012 10:11:59
|
||||
// 4/8/2014 22:05
|
||||
switch r {
|
||||
@ -246,6 +248,16 @@ iterRunes:
|
||||
} else {
|
||||
u.Error(err)
|
||||
}
|
||||
} else if len(datestr) == len("01/2/2006 15:04") {
|
||||
if t, err := time.Parse("01/2/2006 15:04", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
if t, err := time.Parse("1/02/2006 15:04", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
u.Error(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if t, err := time.Parse("1/2/2006 15:04", datestr); err == nil {
|
||||
return t, nil
|
||||
@ -256,13 +268,24 @@ iterRunes:
|
||||
case 268435456: // starts digit then slash 02/ more digits/slashes then whitespace double colons
|
||||
// 03/19/2012 10:11:59
|
||||
// 3/1/2012 10:11:59
|
||||
|
||||
// 03/1/2012 10:11:59
|
||||
// 3/01/2012 10:11:59
|
||||
if len(datestr) == len("01/02/2006 15:04:05") {
|
||||
if t, err := time.Parse("01/02/2006 15:04:05", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
u.Error(err)
|
||||
}
|
||||
} else if len(datestr) == len("01/2/2006 15:04:05") {
|
||||
if t, err := time.Parse("01/2/2006 15:04:05", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
if t, err := time.Parse("1/02/2006 15:04:05", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
u.Error(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if t, err := time.Parse("1/2/2006 15:04:05", datestr); err == nil {
|
||||
return t, nil
|
||||
|
@ -38,6 +38,7 @@ var _ = time.April
|
||||
|
||||
Apr 7, 2014 4:58:55 PM
|
||||
03/19/2012 10:11:59
|
||||
04/2/2014 03:00:37
|
||||
3/1/2014
|
||||
10/13/2014
|
||||
01/02/2006
|
||||
@ -83,6 +84,16 @@ func TestParse(t *testing.T) {
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-08 22:05:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("04/2/2014 03:00:51")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-02 03:00:51 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("4/02/2014 03:00:51")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-02 03:00:51 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("1332151919")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
@ -120,8 +131,8 @@ func TestParse(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWIP(t *testing.T) {
|
||||
// ts, err := ParseAny("2014-05-11 08:20:13,787")
|
||||
// ts, err := ParseAny("04/2/2014 03:00:51")
|
||||
// assert.T(t, err == nil)
|
||||
// u.Debug(ts.Unix(), ts)
|
||||
// assert.T(t, "2014-04-26 17:24:37 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
// u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
// assert.T(t, "2014-04-02 03:00:51 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user