dateparse/parseany_test.go

677 lines
28 KiB
Go
Raw Normal View History

2014-04-21 10:56:17 +08:00
package dateparse
import (
2014-04-25 08:51:56 +08:00
"fmt"
2014-04-21 10:56:17 +08:00
"testing"
"time"
2017-07-14 10:57:15 +08:00
"github.com/stretchr/testify/assert"
2014-04-21 10:56:17 +08:00
)
2017-07-27 06:34:40 +08:00
// Lets test to see how this performs using different Timezones/Locations
// Also of note, try changing your server/machine timezones and repeat
2017-07-27 07:42:12 +08:00
//
// !!!!! The time-zone of local machine effects the results!
// https://play.golang.org/p/IDHRalIyXh
// https://github.com/golang/go/issues/18012
2017-11-19 03:07:33 +08:00
func TestInLocation(t *testing.T) {
2017-07-27 06:34:40 +08:00
2017-07-27 07:42:12 +08:00
denverLoc, err := time.LoadLocation("America/Denver")
assert.Equal(t, nil, err)
// Start out with time.UTC
2017-07-27 06:34:40 +08:00
time.Local = time.UTC
2014-05-07 12:15:43 +08:00
2017-07-27 07:42:12 +08:00
// Just normal parse to test out zone/offset
ts := MustParse("2013-02-01 00:00:00")
zone, offset := ts.Zone()
assert.Equal(t, 0, offset, "Should have found offset = 0 %v", offset)
assert.Equal(t, "UTC", zone, "Should have found zone = UTC %v", zone)
assert.Equal(t, "2013-02-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
// Now lets set to denver (MST/MDT) and re-parse the same time string
// and since no timezone info in string, we expect same result
time.Local = denverLoc
ts = MustParse("2013-02-01 00:00:00")
zone, offset = ts.Zone()
assert.Equal(t, 0, offset, "Should have found offset = 0 %v", offset)
assert.Equal(t, "UTC", zone, "Should have found zone = UTC %v", zone)
assert.Equal(t, "2013-02-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("Tue, 5 Jul 2017 16:28:13 -0700 (MST)")
assert.Equal(t, "2017-07-05 23:28:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-27 07:42:12 +08:00
// Now we are going to use ParseIn() and see that it gives different answer
// with different zone, offset
time.Local = nil
ts, err = ParseIn("2013-02-01 00:00:00", denverLoc)
assert.Equal(t, nil, err)
zone, offset = ts.Zone()
assert.Equal(t, -25200, offset, "Should have found offset = -25200 %v %v", offset, denverLoc)
assert.Equal(t, "MST", zone, "Should have found zone = MST %v", zone)
assert.Equal(t, "2013-02-01 07:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-03-02 10:36:46 +08:00
ts, err = ParseIn("18 January 2018", denverLoc)
assert.Equal(t, nil, err)
zone, offset = ts.Zone()
assert.Equal(t, -25200, offset, "Should have found offset = 0 %v", offset)
assert.Equal(t, "MST", zone, "Should have found zone = UTC %v", zone)
assert.Equal(t, "2018-01-18 07:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-27 07:42:12 +08:00
// Now we are going to use ParseLocal() and see that it gives same
// answer as ParseIn when we have time.Local set to a location
time.Local = denverLoc
ts, err = ParseLocal("2013-02-01 00:00:00")
2017-07-14 10:57:15 +08:00
assert.Equal(t, nil, err)
2017-07-27 07:42:12 +08:00
zone, offset = ts.Zone()
assert.Equal(t, -25200, offset, "Should have found offset = -25200 %v %v", offset, denverLoc)
assert.Equal(t, "MST", zone, "Should have found zone = MST %v", zone)
assert.Equal(t, "2013-02-01 07:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
// Lets advance past daylight savings time start
// use parseIn and see offset/zone has changed to Daylight Savings Equivalents
ts, err = ParseIn("2013-04-01 00:00:00", denverLoc)
assert.Equal(t, nil, err)
zone, offset = ts.Zone()
assert.Equal(t, -21600, offset, "Should have found offset = -21600 %v %v", offset, denverLoc)
assert.Equal(t, "MDT", zone, "Should have found zone = MDT %v", zone)
assert.Equal(t, "2013-04-01 06:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
// reset to UTC
time.Local = time.UTC
2017-07-27 06:34:40 +08:00
// UnixDate = "Mon Jan _2 15:04:05 MST 2006"
2017-07-27 07:42:12 +08:00
ts = MustParse("Mon Jan 2 15:04:05 MST 2006")
2017-07-27 06:34:40 +08:00
2017-08-13 00:48:28 +08:00
_, offset = ts.Zone()
2017-07-27 07:42:12 +08:00
assert.Equal(t, 0, offset, "Should have found offset = 0 %v", offset)
2017-07-27 06:34:40 +08:00
assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-27 07:42:12 +08:00
// Now lets set to denver(mst/mdt)
time.Local = denverLoc
2017-07-27 06:34:40 +08:00
ts = MustParse("Mon Jan 2 15:04:05 MST 2006")
// this time is different from one above parsed with time.Local set to UTC
_, offset = ts.Zone()
2017-07-27 07:42:12 +08:00
assert.Equal(t, -25200, offset, "Should have found offset = -25200 %v", offset)
2017-07-27 06:34:40 +08:00
assert.Equal(t, "2006-01-02 22:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
// Now Reset To UTC
time.Local = time.UTC
// RFC850 = "Monday, 02-Jan-06 15:04:05 MST"
ts = MustParse("Monday, 02-Jan-06 15:04:05 MST")
_, offset = ts.Zone()
2017-07-27 07:42:12 +08:00
assert.Equal(t, 0, offset, "Should have found offset = 0 %v", offset)
2017-07-27 06:34:40 +08:00
assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-27 07:42:12 +08:00
// Now lets set to denver
time.Local = denverLoc
2017-07-27 06:34:40 +08:00
ts = MustParse("Monday, 02-Jan-06 15:04:05 MST")
_, offset = ts.Zone()
2017-07-27 07:42:12 +08:00
assert.NotEqual(t, 0, offset, "Should have found offset %v", offset)
2017-07-27 06:34:40 +08:00
assert.Equal(t, "2006-01-02 22:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
}
2018-02-28 12:05:14 +08:00
func TestOne(t *testing.T) {
time.Local = time.UTC
var ts time.Time
2018-03-02 10:36:46 +08:00
ts = MustParse("Mon Aug 10 15:44:11 PST-0700 2015")
assert.Equal(t, "2015-08-10 22:44:11 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-28 12:05:14 +08:00
}
2017-07-27 06:34:40 +08:00
func TestParse(t *testing.T) {
2018-03-02 10:36:46 +08:00
/*
TODO:
- move to testharness
- replace all the default go dates 2006 with others
- more tests on AM/PM zones, offsets for each variation
*/
2017-07-27 06:34:40 +08:00
// Lets ensure we are operating on UTC
time.Local = time.UTC
2017-04-24 02:24:32 +08:00
2014-06-16 02:18:20 +08:00
zeroTime := time.Time{}.Unix()
ts, err := ParseAny("INVALID")
2017-07-14 10:57:15 +08:00
assert.Equal(t, zeroTime, ts.Unix())
assert.NotEqual(t, nil, err)
2017-07-27 07:42:12 +08:00
assert.Equal(t, true, testDidPanic("NOT GONNA HAPPEN"))
2015-08-11 01:54:01 +08:00
2017-07-14 10:57:15 +08:00
// TODO: Is a utf8 date valid?
// ts = MustParse("2014-04\u221226")
// assert.Equal(t, "2014-04-26 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("May 8, 2009 5:57:51 PM")
assert.Equal(t, "2009-05-08 17:57:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-08 23:03:45 +08:00
ts = MustParse("May 8, 2009 5:57:1 PM")
assert.Equal(t, "2009-05-08 17:57:01 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("May 8, 2009 5:7:51 PM")
assert.Equal(t, "2009-05-08 17:07:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-04-26 07:59:10 +08:00
2014-05-21 13:53:52 +08:00
// ANSIC = "Mon Jan _2 15:04:05 2006"
2017-07-14 10:57:15 +08:00
ts = MustParse("Mon Jan 2 15:04:05 2006")
assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-05-21 13:53:52 +08:00
// RubyDate = "Mon Jan 02 15:04:05 -0700 2006"
2017-07-14 10:57:15 +08:00
ts = MustParse("Mon Jan 02 15:04:05 -0700 2006")
assert.Equal(t, "2006-01-02 22:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)), "%v")
2014-05-21 13:53:52 +08:00
2017-07-27 06:34:40 +08:00
// UnixDate = "Mon Jan _2 15:04:05 MST 2006"
ts = MustParse("Mon Jan 2 15:04:05 MST 2006")
assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-06-16 02:18:20 +08:00
2017-07-27 06:34:40 +08:00
// RFC850 = "Monday, 02-Jan-06 15:04:05 MST"
2018-03-02 10:36:46 +08:00
ts = MustParse("Wednesday, 07-May-09 08:00:43 MST")
assert.Equal(t, "2009-05-07 08:00:43 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("Wednesday, 28-Feb-18 09:01:00 MST")
assert.Equal(t, "2018-02-28 09:01:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
// ST_WEEKDAYCOMMADELTA
// Monday, 02 Jan 2006 15:04:05 -0700
// Monday, 02 Jan 2006 15:04:05 +0100
ts = MustParse("Monday, 02 Jan 2006 15:04:05 +0100")
assert.Equal(t, "2006-01-02 14:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-08 23:03:45 +08:00
ts = MustParse("Monday, 02 Jan 2006 15:04:5 +0100")
assert.Equal(t, "2006-01-02 14:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("Monday, 02 Jan 2006 15:4:05 +0100")
assert.Equal(t, "2006-01-02 14:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("Monday, 02 Jan 2006 15:04:05 -0100")
assert.Equal(t, "2006-01-02 16:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2015-08-11 01:54:01 +08:00
// Another weird one, year on the end after UTC?
2018-03-02 10:36:46 +08:00
ts = MustParse("Mon Aug 10 15:44:11 UTC+0000 2015")
2017-07-14 10:57:15 +08:00
assert.Equal(t, "2015-08-10 15:44:11 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-03-02 10:36:46 +08:00
ts = MustParse("Mon Aug 10 15:44:11 PST-0700 2015")
assert.Equal(t, "2015-08-10 22:44:11 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2015-08-11 01:54:01 +08:00
2018-03-02 10:36:46 +08:00
// Easily the worst Date format I have ever seen
2015-07-04 01:27:48 +08:00
// "Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)"
2017-07-14 10:57:15 +08:00
ts = MustParse("Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)")
assert.Equal(t, "2015-07-03 17:04:07 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2015-07-04 01:27:48 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("Mon, 02 Jan 2006 15:04:05 MST")
2017-07-27 06:34:40 +08:00
assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-08 23:03:45 +08:00
ts = MustParse("Mon, 2 Jan 2006 15:4:05 MST")
assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("Mon, 2 Jan 2006 15:4:5 MST")
assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("Mon, 02-Jan-06 15:04:05 MST")
assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 22:02:22 +08:00
ts = MustParse("Tue, 11 Jul 2017 16:28:13 +0200 (CEST)")
assert.Equal(t, "2017-07-11 14:28:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("Tue, 5 Jul 2017 16:28:13 -0700 (CEST)")
assert.Equal(t, "2017-07-05 23:28:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("Thu, 13 Jul 2017 08:58:40 +0100")
assert.Equal(t, "2017-07-13 07:58:40 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 00:11:41 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("Mon, 02 Jan 2006 15:04:05 -0700")
assert.Equal(t, "2006-01-02 22:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-08 23:03:45 +08:00
ts = MustParse("Mon, 02 Jan 2006 15:4:05 -0700")
assert.Equal(t, "2006-01-02 22:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("Mon, 02 Jan 2006 15:4:5 -0700")
assert.Equal(t, "2006-01-02 22:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-01-05 15:08:24 +08:00
ts = MustParse("Thu, 4 Jan 2018 17:53:36 +0000")
assert.Equal(t, "2018-01-04 17:53:36 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-02-06 02:04:03 +08:00
// not sure if this is anything close to a standard, never seen it before
2017-07-14 10:57:15 +08:00
ts = MustParse("12 Feb 2006, 19:17")
assert.Equal(t, "2006-02-12 19:17:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2 Feb 2006, 19:17")
assert.Equal(t, "2006-02-02 19:17:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("12 Feb 2006, 19:17:22")
assert.Equal(t, "2006-02-12 19:17:22 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-02-06 02:04:03 +08:00
ts = MustParse("2 Feb 2006, 19:17:22")
assert.Equal(t, "2006-02-02 19:17:22 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("12 Feb 2006 19:17")
assert.Equal(t, "2006-02-12 19:17:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2 Feb 2006 19:17")
assert.Equal(t, "2006-02-02 19:17:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("12 Feb 2006 19:17:22")
assert.Equal(t, "2006-02-12 19:17:22 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2 Feb 2006 19:17:22")
assert.Equal(t, "2006-02-02 19:17:22 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-26 08:35:33 +08:00
// // 19 Dec 2013 12:15:23 GMT
// ts = MustParse("12 Feb 2006 19:17:22 GMT")
// assert.Equal(t, "2006-02-12 19:17:22 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
// ts = MustParse("2 Feb 2006 19:17:22 GMT")
// assert.Equal(t, "2006-02-02 19:17:22 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
// // 28 Mar 2010 15:45:30 +1100
// ts = MustParse("12 Feb 2006 19:17:22")
// assert.Equal(t, "2006-02-12 19:17:22 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-27 07:55:21 +08:00
ts = MustParse("2013-Feb-03")
assert.Equal(t, "2013-02-03 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-01-25 09:59:25 +08:00
ts = MustParse("03 February 2013")
assert.Equal(t, "2013-02-03 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("3 February 2013")
assert.Equal(t, "2013-02-03 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-11-19 03:07:33 +08:00
//---------------------------------------------
// Chinese 2014年04月18日
ts = MustParse("2014年04月08日")
assert.Equal(t, "2014-04-08 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014年04月08日 19:17:22")
assert.Equal(t, "2014-04-08 19:17:22 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
//---------------------------------------------
// mm/dd/yyyy ?
2014-04-21 10:56:17 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("3/31/2014")
assert.Equal(t, "2014-03-31 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-04-28 04:26:17 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("03/31/2014")
assert.Equal(t, "2014-03-31 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-04-28 04:26:17 +08:00
// what type of date is this? 08/21/71
2017-07-14 10:57:15 +08:00
ts = MustParse("08/21/71")
assert.Equal(t, "1971-08-21 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2016-01-06 03:34:31 +08:00
// m/d/yy
2017-07-14 10:57:15 +08:00
ts = MustParse("8/1/71")
assert.Equal(t, "1971-08-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2016-01-06 03:34:31 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("4/8/2014 22:05")
assert.Equal(t, "2014-04-08 22:05:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-11-19 02:21:24 +08:00
ts = MustParse("4/18/2014 22:05")
assert.Equal(t, "2014-04-18 22:05:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("04/08/2014 22:05")
assert.Equal(t, "2014-04-08 22:05:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-04-28 05:33:33 +08:00
2017-11-19 02:21:24 +08:00
ts = MustParse("4/8/14 22:05")
assert.Equal(t, "2014-04-08 22:05:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("4/18/14 22:05")
assert.Equal(t, "2014-04-18 22:05:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("10/18/14 22:05")
assert.Equal(t, "2014-10-18 22:05:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("04/2/2014 4:00:51")
assert.Equal(t, "2014-04-02 04:00:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-05-12 04:33:13 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("8/8/1965 01:00:01 PM")
assert.Equal(t, "1965-08-08 13:00:01 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-02-14 08:49:48 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("8/8/1965 12:00:01 AM")
assert.Equal(t, "1965-08-08 00:00:01 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-02-14 08:49:48 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("8/8/1965 01:00 PM")
assert.Equal(t, "1965-08-08 13:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-02-14 10:39:03 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("08/8/1965 01:00 PM")
assert.Equal(t, "1965-08-08 13:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-02-14 08:49:48 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("8/08/1965 1:00 PM")
assert.Equal(t, "1965-08-08 13:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2015-10-01 03:09:08 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("8/8/1965 12:00 AM")
assert.Equal(t, "1965-08-08 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-05-12 04:33:13 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("8/13/1965 01:00 PM")
assert.Equal(t, "1965-08-13 13:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-04-26 07:59:10 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("4/02/2014 03:00:51")
assert.Equal(t, "2014-04-02 03:00:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("03/19/2012 10:11:59")
assert.Equal(t, "2012-03-19 10:11:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("03/19/2012 10:11:59.3186369")
assert.Equal(t, "2012-03-19 10:11:59.3186369 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
//---------------------------------------------
// yyyy/mm/dd ?
2017-07-14 10:57:15 +08:00
ts = MustParse("2014/3/31")
assert.Equal(t, "2014-03-31 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014/03/31")
assert.Equal(t, "2014-03-31 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014/4/8 22:05")
assert.Equal(t, "2014-04-08 22:05:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-08 23:03:45 +08:00
ts = MustParse("2014/4/8 2:05")
assert.Equal(t, "2014-04-08 02:05:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("2014/04/08 22:05")
assert.Equal(t, "2014-04-08 22:05:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014/04/2 03:00:51")
assert.Equal(t, "2014-04-02 03:00:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014/4/02 03:00:51")
assert.Equal(t, "2014-04-02 03:00:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2012/03/19 10:11:59")
assert.Equal(t, "2012-03-19 10:11:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2012/03/19 10:11:59.318")
assert.Equal(t, "2012-03-19 10:11:59.318 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2012/03/19 10:11:59.3186369")
assert.Equal(t, "2012-03-19 10:11:59.3186369 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2012/03/19 10:11:59.318636945")
assert.Equal(t, "2012-03-19 10:11:59.318636945 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2012/03/19 10:11 PM")
assert.Equal(t, "2012-03-19 22:11:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2012/03/19 1:11 PM")
assert.Equal(t, "2012-03-19 13:11:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2012/3/19 10:11 PM")
assert.Equal(t, "2012-03-19 22:11:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2012/3/3 10:11 PM")
assert.Equal(t, "2012-03-03 22:11:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2012/03/19 10:11:59 PM")
assert.Equal(t, "2012-03-19 22:11:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2012/3/3 10:11:59 PM")
assert.Equal(t, "2012-03-03 22:11:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2012/03/03 10:11:59.345 PM")
assert.Equal(t, "2012-03-03 22:11:59.345 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
//---------------------------------------------
// yyyy-mm-dd ?
2017-07-14 10:57:15 +08:00
ts = MustParse("2009-08-12T22:15:09-07:00")
assert.Equal(t, "2009-08-13 05:15:09 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-08 23:03:45 +08:00
ts = MustParse("2009-08-12T22:15:9-07:00")
assert.Equal(t, "2009-08-13 05:15:09 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("2009-08-12T22:15:09.123-07:00")
assert.Equal(t, "2009-08-13 05:15:09.123 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)), "%v", ts.In(time.UTC))
ts = MustParse("2009-08-12T22:15Z")
assert.Equal(t, "2009-08-12 22:15:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)), "%v", ts.In(time.UTC))
ts = MustParse("2009-08-12T22:15:09Z")
assert.Equal(t, "2009-08-12 22:15:09 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)), "%v", ts.In(time.UTC))
ts = MustParse("2009-08-12T22:15:09.99Z")
assert.Equal(t, "2009-08-12 22:15:09.99 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2009-08-12T22:15:09.9999Z")
assert.Equal(t, "2009-08-12 22:15:09.9999 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2009-08-12T22:15:09.99999999Z")
assert.Equal(t, "2009-08-12 22:15:09.99999999 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-08 23:03:45 +08:00
ts = MustParse("2009-08-12T22:15:9.99999999Z")
assert.Equal(t, "2009-08-12 22:15:09.99999999 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
// https://github.com/golang/go/issues/5294
_, err = ParseAny(time.RFC3339)
assert.NotEqual(t, nil, err)
ts = MustParse("2009-08-12T22:15:09.123")
assert.Equal(t, "2009-08-12 22:15:09.123 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2009-08-12T22:15:09.123456")
assert.Equal(t, "2009-08-12 22:15:09.123456 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2009-08-12T22:15:09.12")
assert.Equal(t, "2009-08-12 22:15:09.12 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2009-08-12T22:15:09.1")
assert.Equal(t, "2009-08-12 22:15:09.1 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2009-08-12T22:15:09")
assert.Equal(t, "2009-08-12 22:15:09 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014-04-26 17:24:37.3186369")
assert.Equal(t, "2014-04-26 17:24:37.3186369 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-05-07 03:32:49 +08:00
2015-06-26 08:24:55 +08:00
// 2015-06-25 01:25:37.115208593 +0000 UTC
2017-07-14 10:57:15 +08:00
ts = MustParse("2012-08-03 18:31:59.257000000 +0000 UTC")
assert.Equal(t, "2012-08-03 18:31:59.257 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-08 23:03:45 +08:00
ts = MustParse("2012-08-03 8:1:59.257000000 +0000 UTC")
assert.Equal(t, "2012-08-03 08:01:59.257 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2012-8-03 18:31:59.257000000 +0000 UTC")
assert.Equal(t, "2012-08-03 18:31:59.257 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2012-8-3 18:31:59.257000000 +0000 UTC")
assert.Equal(t, "2012-08-03 18:31:59.257 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("2015-09-30 18:48:56.35272715 +0000 UTC")
assert.Equal(t, "2015-09-30 18:48:56.35272715 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2015-06-26 08:24:55 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2017-01-27 00:07:31.945167")
assert.Equal(t, "2017-01-27 00:07:31.945167 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2015-10-01 03:09:08 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2012-08-03 18:31:59.257000000")
assert.Equal(t, "2012-08-03 18:31:59.257 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-01-31 09:18:48 +08:00
ts = MustParse("2013-04-01 22:43")
assert.Equal(t, "2013-04-01 22:43:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("2013-04-01 22:43:22")
assert.Equal(t, "2013-04-01 22:43:22 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-05-12 09:08:56 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04-26 17:24:37.123")
assert.Equal(t, "2014-04-26 17:24:37.123 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-05-12 09:22:16 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04-26 17:24:37.123456 +0000 UTC")
assert.Equal(t, "2014-04-26 17:24:37.123456 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-05-07 09:14:58 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04-26 17:24:37.123456 UTC")
assert.Equal(t, "2014-04-26 17:24:37.123456 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-04-12 06:30:42 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04-26 17:24:37.123 UTC")
assert.Equal(t, "2014-04-26 17:24:37.123 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-04-12 06:30:42 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04-26 17:24:37.12 UTC")
assert.Equal(t, "2014-04-26 17:24:37.12 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-04-12 06:30:42 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04-26 17:24:37.1 UTC")
assert.Equal(t, "2014-04-26 17:24:37.1 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-04-12 06:30:42 +08:00
2018-02-14 12:44:26 +08:00
ts = MustParse("2014-04-26 09:04:37.123 +0800")
assert.Equal(t, "2014-04-26 01:04:37.123 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014-04-26 9:04:37.123 +0800")
assert.Equal(t, "2014-04-26 01:04:37.123 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014-04-26 09:4:37.123 +0800")
assert.Equal(t, "2014-04-26 01:04:37.123 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014-04-26 9:4:37.123 +0800")
assert.Equal(t, "2014-04-26 01:04:37.123 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-04-12 06:30:42 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04-26 17:24:37.123 -0800")
assert.Equal(t, "2014-04-27 01:24:37.123 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-04-12 06:30:42 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04-26 17:24:37.123456 +0800")
assert.Equal(t, "2014-04-26 09:24:37.123456 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-04-12 06:30:42 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04-26 17:24:37.123456 -0800")
assert.Equal(t, "2014-04-27 01:24:37.123456 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-04-12 06:30:42 +08:00
ts = MustParse("2017-07-19 03:21:51+00:00")
assert.Equal(t, "2017-07-19 03:21:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-14 12:44:26 +08:00
ts = MustParse("2017-07-09 03:01:51 +00:00 UTC")
assert.Equal(t, "2017-07-09 03:01:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2017-7-09 03:01:51 +00:00 UTC")
assert.Equal(t, "2017-07-09 03:01:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2017-07-9 03:01:51 +00:00 UTC")
assert.Equal(t, "2017-07-09 03:01:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2017-7-9 03:01:51 +00:00 UTC")
assert.Equal(t, "2017-07-09 03:01:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2017-07-19 03:01:51 +00:00 UTC")
assert.Equal(t, "2017-07-19 03:01:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2017-07-19 3:01:51 +00:00 UTC")
assert.Equal(t, "2017-07-19 03:01:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2017-07-19 03:1:51 +00:00 UTC")
assert.Equal(t, "2017-07-19 03:01:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2017-07-19 3:1:51 +00:00 UTC")
assert.Equal(t, "2017-07-19 03:01:51 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
// Golang Native Format
ts = MustParse("2015-02-18 00:12:00 +0000 UTC")
assert.Equal(t, "2015-02-18 00:12:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2018-02-14 12:44:26 +08:00
ts = MustParse("2015-02-18 00:12:00 +0000 GMT")
assert.Equal(t, "2015-02-18 00:12:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2015-02-08 03:02:00 +0300 MSK")
assert.Equal(t, "2015-02-08 00:02:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2015-2-08 03:02:00 +0300 MSK")
assert.Equal(t, "2015-02-08 00:02:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2015-02-8 03:02:00 +0300 MSK")
assert.Equal(t, "2015-02-08 00:02:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2015-2-8 03:02:00 +0300 MSK")
assert.Equal(t, "2015-02-08 00:02:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-12-16 06:20:00 UTC")
assert.Equal(t, "2014-12-16 06:20:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2016-09-13 22:40:04 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-12-16 06:20:00 GMT")
assert.Equal(t, "2014-12-16 06:20:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-12-03 06:57:00 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-12-16 06:20:00 +0000 UTC")
assert.Equal(t, "2014-12-16 06:20:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-05-07 12:15:43 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04-26 05:24:37 PM")
assert.Equal(t, "2014-04-26 17:24:37 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-05-11 23:28:23 +08:00
// This one is pretty special, it is TIMEZONE based but starts with P to emulate collions with PM
ts = MustParse("2014-04-26 05:24:37 PST")
assert.Equal(t, "2014-04-26 05:24:37 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04-26")
assert.Equal(t, "2014-04-26 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2016-03-02 05:25:00 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-04")
assert.Equal(t, "2014-04-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("2014-05-11 08:20:13,787")
assert.Equal(t, "2014-05-11 08:20:13.787 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-12 02:00:40 +08:00
2017-07-18 05:46:18 +08:00
_, err = ParseAny("2014-13-13 08:20:13,787") // month 13 doesn't exist so error
2017-07-14 10:57:15 +08:00
assert.NotEqual(t, nil, err)
2017-07-12 02:00:40 +08:00
2018-02-14 12:44:26 +08:00
ts = MustParse("2014-05-01 08:02:13 +00:00")
assert.Equal(t, "2014-05-01 08:02:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014-5-01 08:02:13 +00:00")
assert.Equal(t, "2014-05-01 08:02:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014-05-1 08:02:13 +00:00")
assert.Equal(t, "2014-05-01 08:02:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2014-5-1 08:02:13 +00:00")
assert.Equal(t, "2014-05-01 08:02:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-06-15 04:56:12 +08:00
2017-07-18 05:46:18 +08:00
ts = MustParse("2014-05-11 08:20:13 +0000")
assert.Equal(t, "2014-05-11 08:20:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("2016-06-21T19:55:00+01:00")
assert.Equal(t, "2016-06-21 18:55:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2016-06-21T19:55:00.799+01:00")
assert.Equal(t, "2016-06-21 18:55:00.799 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-18 05:46:18 +08:00
ts = MustParse("2016-06-21T19:55:00+0100")
assert.Equal(t, "2016-06-21 18:55:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2016-06-21T19:55:00-0700")
assert.Equal(t, "2016-06-22 02:55:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("2016-06-21T19:55:00.799+0100")
assert.Equal(t, "2016-06-21 18:55:00.799 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-06-15 04:56:12 +08:00
2018-01-12 05:21:04 +08:00
//---------------------------------------------
// mm.dd.yyyy
// mm.dd.yy
ts = MustParse("3.31.2014")
assert.Equal(t, "2014-03-31 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("03.31.2014")
assert.Equal(t, "2014-03-31 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("08.21.71")
assert.Equal(t, "1971-08-21 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
//---------------------------------------------
2016-03-02 05:25:00 +08:00
// yyyymmdd and similar
2017-07-14 10:57:15 +08:00
ts = MustParse("2014")
assert.Equal(t, "2014-01-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2016-03-02 05:25:00 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("20140601")
assert.Equal(t, "2014-06-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2015-08-19 06:50:04 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("1332151919")
assert.Equal(t, "2012-03-19 10:11:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-07-11 06:25:23 +08:00
2017-07-14 10:57:15 +08:00
ts = MustParse("1384216367111")
assert.Equal(t, "2013-11-12 00:32:47.111 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-10-08 09:30:17 +08:00
ts, _ = ParseIn("1384216367111", time.UTC)
assert.Equal(t, "2013-11-12 00:32:47.111 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2017-07-14 10:57:15 +08:00
ts = MustParse("1384216367111222")
assert.Equal(t, "2013-11-12 00:32:47.111222 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
2014-05-11 23:28:23 +08:00
2017-07-14 10:57:15 +08:00
// Nanoseconds
ts = MustParse("1384216367111222333")
assert.Equal(t, "2013-11-12 00:32:47.111222333 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
_, err = ParseAny("138421636711122233311111") // too many digits
assert.NotEqual(t, nil, err)
2017-10-08 00:34:59 +08:00
_, err = ParseAny("-1314")
assert.NotEqual(t, nil, err)
2017-07-14 10:57:15 +08:00
}
2017-10-04 18:50:25 +08:00
func testDidPanic(datestr string) (paniced bool) {
defer func() {
if r := recover(); r != nil {
paniced = true
}
}()
MustParse(datestr)
return false
}
2018-02-28 12:05:14 +08:00
func TestPStruct(t *testing.T) {
denverLoc, err := time.LoadLocation("America/Denver")
assert.Equal(t, nil, err)
p := newParser("08.21.71", denverLoc)
p.setMonth()
assert.Equal(t, 0, p.moi)
p.setDay()
assert.Equal(t, 0, p.dayi)
p.set(-1, "not")
p.set(15, "not")
assert.Equal(t, "08.21.71", p.datestr)
assert.Equal(t, "08.21.71", string(p.format))
}