From cf36286fa644d0f74fa8bcb0e67c0d18cf63bc19 Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Sun, 11 May 2014 10:22:53 -0700 Subject: [PATCH] doc readme --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ parseany_test.go | 39 ++++++++++++++++++-------------------- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e69de29..201e093 100644 --- a/README.md +++ b/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))) +} +``` \ No newline at end of file diff --git a/parseany_test.go b/parseany_test.go index 6f06f8e..fd98655 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -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))) }