-add date only format

This commit is contained in:
Aaron Raddon 2014-04-27 14:33:33 -07:00
parent 98484a1f48
commit a2c6f47ce0
2 changed files with 16 additions and 2 deletions

View File

@ -212,10 +212,19 @@ func ParseAny(datestr string) (time.Time, error) {
} else { } else {
u.Error("unknown format: ", datestr) u.Error("unknown format: ", datestr)
} }
case !f.Has(HAS_SLASH): default:
// 3/1/2014 // 3/1/2014
// 10/13/2014 // 10/13/2014
// 01/02/2006 // 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): case f.Has(HAS_ALPHA) && f.Has(HAS_COMMA):
switch { switch {

View File

@ -75,10 +75,15 @@ func TestParse(t *testing.T) {
//u.Debug(ts.Unix(), ts) //u.Debug(ts.Unix(), ts)
assert.T(t, ts.Unix() == 1396994700) 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 // Unix Time Stamp
ts, err = ParseAny("1332151919") ts, err = ParseAny("1332151919")
assert.T(t, err == nil) assert.T(t, err == nil)
u.Debug(ts.Unix(), ts) //u.Debug(ts.Unix(), ts)
assert.T(t, ts.Unix() == 1332151919) assert.T(t, ts.Unix() == 1332151919)
ts2, err := ParseAny("2009-08-12T22:15:09-07:00") ts2, err := ParseAny("2009-08-12T22:15:09-07:00")