mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
doc readme
This commit is contained in:
parent
f85104b4d6
commit
cf36286fa6
49
README.md
49
README.md
@ -0,0 +1,49 @@
|
||||
Go Date Parser
|
||||
---------------------------
|
||||
|
||||
Parse *Any* date format
|
||||
|
||||
|
||||
```go
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
|
||||
ts, _ := ParseAny("May 8, 2009 5:57:51 PM")
|
||||
assert.T(t, "2009-05-08 17:57:51 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseAny("03/19/2012 10:11:59")
|
||||
assert.T(t, "2012-03-19 10:11:59 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseAny("3/31/2014")
|
||||
assert.T(t, "2014-03-31 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseAny("03/31/2014")
|
||||
assert.T(t, "2014-03-31 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseAny("4/8/2014 22:05")
|
||||
assert.T(t, "2014-04-08 22:05:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseAny("04/08/2014 22:05")
|
||||
assert.T(t, "2014-04-08 22:05:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseAny("1332151919")
|
||||
assert.T(t, "2012-03-19 10:11:59 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
assert.T(t, "2009-08-13 05:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseAny("2014-04-26 17:24:37.3186369")
|
||||
assert.T(t, "2014-04-26 17:24:37.3186369 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseAny("2014-04-26 17:24:37.123")
|
||||
assert.T(t, "2014-04-26 17:24:37.123 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseAny("2014-04-26 05:24:37 PM")
|
||||
assert.T(t, "2014-04-26 17:24:37 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseAny("2014-04-26")
|
||||
assert.T(t, "2014-04-26 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseAny("2014-05-11 08:20:13,787")
|
||||
assert.T(t, "2014-05-11 08:20:13.787 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
}
|
||||
```
|
@ -55,55 +55,52 @@ func init() {
|
||||
func TestParse(t *testing.T) {
|
||||
|
||||
ts, err := ParseAny("May 8, 2009 5:57:51 PM")
|
||||
assert.T(t, err == nil)
|
||||
assert.T(t, ts.In(time.UTC).Unix() == 1241805471)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2009-05-08 17:57:51 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("03/19/2012 10:11:59")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts.Unix(), ts)
|
||||
assert.T(t, ts.Unix() == 1332151919)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2012-03-19 10:11:59 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("3/31/2014")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts.Unix(), ts)
|
||||
assert.T(t, ts.Unix() == 1396224000)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-03-31 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("03/31/2014")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts.Unix(), ts)
|
||||
assert.T(t, ts.Unix() == 1396224000)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-03-31 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("4/8/2014 22:05")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts.Unix(), ts)
|
||||
//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/08/2014 22:05")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts.Unix(), ts)
|
||||
assert.T(t, ts.Unix() == 1396994700)
|
||||
//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)))
|
||||
|
||||
// Unix Time Stamp
|
||||
ts, err = ParseAny("1332151919")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts.Unix(), ts)
|
||||
assert.T(t, ts.Unix() == 1332151919)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2012-03-19 10:11:59 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts2, err := ParseAny("2009-08-12T22:15:09-07:00")
|
||||
ts, err = ParseAny("2009-08-12T22:15:09-07:00")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts2.In(time.UTC), " ", ts2.Unix())
|
||||
assert.T(t, "2009-08-13 05:15:09 +0000 UTC" == fmt.Sprintf("%v", ts2.In(time.UTC)))
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2009-08-13 05:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
//2014-04-26 05:24:37.3186369
|
||||
ts, err = ParseAny("2014-04-26 17:24:37.3186369")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-26 17:24:37.3186369 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
//2014-04-26 17:24:37.123
|
||||
ts, err = ParseAny("2014-04-26 17:24:37.123")
|
||||
assert.T(t, err == nil)
|
||||
//u.Debugf("unix=%v ts='%v'", ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-26 17:24:37.123 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2014-04-26 05:24:37 PM")
|
||||
@ -118,7 +115,7 @@ func TestParse(t *testing.T) {
|
||||
|
||||
ts, err = ParseAny("2014-05-11 08:20:13,787")
|
||||
assert.T(t, err == nil)
|
||||
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, "2014-05-11 08:20:13.787 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user