mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
support short date format
This commit is contained in:
parent
eeec45e120
commit
fbec5be882
@ -40,7 +40,7 @@ const (
|
|||||||
var _ = u.EMPTY
|
var _ = u.EMPTY
|
||||||
|
|
||||||
var (
|
var (
|
||||||
shortDates = []string{"01/02/2006", "1/2/2006", "06/01/02", "01/02/06"}
|
shortDates = []string{"01/02/2006", "1/2/2006", "06/01/02", "01/02/06", "1/2/06"}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Given an unknown date format, detect the type, parse, return time
|
// Given an unknown date format, detect the type, parse, return time
|
||||||
@ -200,6 +200,7 @@ iterRunes:
|
|||||||
// 3/1/2014
|
// 3/1/2014
|
||||||
// 10/13/2014
|
// 10/13/2014
|
||||||
// 01/02/2006
|
// 01/02/2006
|
||||||
|
// 1/2/06
|
||||||
if unicode.IsDigit(r) || r == '/' {
|
if unicode.IsDigit(r) || r == '/' {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -126,6 +126,12 @@ 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, "1971-08-21 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.T(t, "1971-08-21 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
// m/d/yy
|
||||||
|
ts, err = ParseAny("8/1/71")
|
||||||
|
assert.Tf(t, err == nil, "%v", err)
|
||||||
|
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||||
|
assert.T(t, "1971-08-01 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
ts, err = ParseAny("4/8/2014 22:05")
|
ts, err = ParseAny("4/8/2014 22:05")
|
||||||
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))
|
||||||
|
Loading…
Reference in New Issue
Block a user