mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
-add date only format
This commit is contained in:
parent
98484a1f48
commit
a2c6f47ce0
11
parseany.go
11
parseany.go
@ -212,10 +212,19 @@ func ParseAny(datestr string) (time.Time, error) {
|
||||
} else {
|
||||
u.Error("unknown format: ", datestr)
|
||||
}
|
||||
case !f.Has(HAS_SLASH):
|
||||
default:
|
||||
// 3/1/2014
|
||||
// 10/13/2014
|
||||
// 01/02/2006
|
||||
if t, err := time.Parse("01/02/2006", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
if t, err := time.Parse("1/2/2006", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
u.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
case f.Has(HAS_ALPHA) && f.Has(HAS_COMMA):
|
||||
switch {
|
||||
|
@ -75,10 +75,15 @@ func TestParse(t *testing.T) {
|
||||
//u.Debug(ts.Unix(), ts)
|
||||
assert.T(t, ts.Unix() == 1396994700)
|
||||
|
||||
ts, err = ParseAny("3/31/2014")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts.Unix(), ts)
|
||||
assert.T(t, ts.Unix() == 1396224000)
|
||||
|
||||
// Unix Time Stamp
|
||||
ts, err = ParseAny("1332151919")
|
||||
assert.T(t, err == nil)
|
||||
u.Debug(ts.Unix(), ts)
|
||||
//u.Debug(ts.Unix(), ts)
|
||||
assert.T(t, ts.Unix() == 1332151919)
|
||||
|
||||
ts2, err := ParseAny("2009-08-12T22:15:09-07:00")
|
||||
|
Loading…
Reference in New Issue
Block a user