mirror of
https://github.com/araddon/dateparse.git
synced 2025-01-18 18:56:47 +08:00
Refactor time/date parsing
This commit is contained in:
parent
7b436dd68b
commit
942c3ab04f
150
parseany.go
150
parseany.go
@ -9,15 +9,8 @@ import (
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/araddon/gou"
|
||||
)
|
||||
|
||||
func init() {
|
||||
gou.SetupLogging("debug")
|
||||
gou.SetColorOutput()
|
||||
}
|
||||
|
||||
type dateState uint8
|
||||
type timeState uint8
|
||||
|
||||
@ -47,14 +40,15 @@ const (
|
||||
dateAlphaWsAlphaYearmaybe
|
||||
dateWeekdayComma
|
||||
dateWeekdayAbbrevComma
|
||||
dateWeekdayAbbrevCommaDash
|
||||
//dateWeekdayAbbrevCommaDash
|
||||
)
|
||||
const (
|
||||
// Time state
|
||||
timeIgnore timeState = iota
|
||||
timeStart
|
||||
timeWs
|
||||
timeWsAlpha // 3
|
||||
timeWsAlpha
|
||||
timeWsAlphaWs
|
||||
timeWsAlphaZoneOffset
|
||||
timeWsAlphaZoneOffsetWs
|
||||
timeWsAlphaZoneOffsetWsYear
|
||||
@ -63,7 +57,6 @@ const (
|
||||
timeWsAMPM
|
||||
timeWsOffset
|
||||
timeWsOffsetWs
|
||||
timeWsOffsetAlpha
|
||||
timeWsOffsetColonAlpha
|
||||
timeWsOffsetColon
|
||||
timeWsYear
|
||||
@ -73,11 +66,14 @@ const (
|
||||
timePeriod
|
||||
timePeriodOffset
|
||||
timePeriodOffsetColon
|
||||
timePeriodOffsetColonWs
|
||||
timePeriodWs
|
||||
timePeriodWsAlpha
|
||||
timePeriodWsOffset
|
||||
timePeriodWsOffsetWs
|
||||
timePeriodWsOffsetWsAlpha
|
||||
timePeriodWsOffsetColon
|
||||
timePeriodWsOffsetColonAlpha
|
||||
timeZ
|
||||
timeZDigit
|
||||
)
|
||||
@ -286,7 +282,7 @@ func (p *parser) parse() (time.Time, error) {
|
||||
p.format = p.format[p.skip:]
|
||||
p.datestr = p.datestr[p.skip:]
|
||||
}
|
||||
gou.Debugf("parse %q AS %s", p.datestr, string(p.format))
|
||||
//gou.Debugf("parse %q AS %s", p.datestr, string(p.format))
|
||||
if p.loc == nil {
|
||||
return time.Parse(string(p.format), p.datestr)
|
||||
}
|
||||
@ -528,10 +524,14 @@ iterRunes:
|
||||
// 12 Feb 2006, 19:17:22
|
||||
switch r {
|
||||
case ',':
|
||||
p.yearlen = i - p.yeari
|
||||
p.setYear()
|
||||
i++
|
||||
break iterRunes
|
||||
case ' ':
|
||||
break iterRunes
|
||||
// case ' ':
|
||||
// p.yearlen = i - p.yeari
|
||||
// p.setYear()
|
||||
// break iterRunes
|
||||
}
|
||||
case dateDigitWsMolong:
|
||||
// 18 January 2018
|
||||
@ -577,8 +577,7 @@ iterRunes:
|
||||
// Mon, 02 Jan 2006 15:04:05 -0700
|
||||
// Thu, 13 Jul 2017 08:58:40 +0100
|
||||
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
||||
// dateWeekdayAbbrevCommaDash
|
||||
// Mon, 02-Jan-06 15:04:05 MST
|
||||
// Mon, 02-Jan-06 15:04:05 MST
|
||||
|
||||
switch {
|
||||
case r == ' ':
|
||||
@ -623,7 +622,6 @@ iterRunes:
|
||||
p.stateTime = timeStart
|
||||
break iterRunes
|
||||
}
|
||||
//case r == '-':
|
||||
}
|
||||
case dateWeekdayAbbrevComma:
|
||||
// Mon, 02 Jan 2006 15:04:05 MST
|
||||
@ -631,10 +629,9 @@ iterRunes:
|
||||
// Thu, 13 Jul 2017 08:58:40 +0100
|
||||
// Thu, 4 Jan 2018 17:53:36 +0000
|
||||
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
||||
// dateWeekdayAbbrevCommaDash
|
||||
// Mon, 02-Jan-06 15:04:05 MST
|
||||
switch {
|
||||
case r == ' ':
|
||||
// Mon, 02-Jan-06 15:04:05 MST
|
||||
switch r {
|
||||
case ' ', '-':
|
||||
if p.dayi == 0 {
|
||||
p.dayi = i + 1
|
||||
} else if p.moi == 0 {
|
||||
@ -651,10 +648,6 @@ iterRunes:
|
||||
p.stateTime = timeStart
|
||||
break iterRunes
|
||||
}
|
||||
|
||||
case r == '-':
|
||||
p.stateDate = dateWeekdayAbbrevCommaDash
|
||||
break iterRunes
|
||||
}
|
||||
|
||||
case dateAlphaWs:
|
||||
@ -729,7 +722,6 @@ iterRunes:
|
||||
p.yeari = i + 1
|
||||
p.stateDate = dateAlphaWsAlphaYearmaybe
|
||||
p.stateTime = timeStart
|
||||
gou.Infof("%d %s dateAlphaWsAlpha %s %s", i, string(r), p.ds(), p.ts())
|
||||
}
|
||||
} else if unicode.IsDigit(r) {
|
||||
if p.dayi == 0 {
|
||||
@ -744,7 +736,6 @@ iterRunes:
|
||||
i = i - 3
|
||||
p.stateDate = dateAlphaWsAlpha
|
||||
p.yeari = 0
|
||||
gou.Warnf("hm, not year")
|
||||
break iterRunes
|
||||
} else if r == ' ' {
|
||||
// must be year format, not 15:04
|
||||
@ -763,12 +754,19 @@ iterRunes:
|
||||
if i < len(p.datestr) {
|
||||
i++
|
||||
}
|
||||
// ensure we skip any whitespace prefix
|
||||
for ; i < len(datestr); i++ {
|
||||
r := rune(datestr[i])
|
||||
if r != ' ' {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
iterTimeRunes:
|
||||
for ; i < len(datestr); i++ {
|
||||
r := rune(datestr[i])
|
||||
|
||||
gou.Debugf("%d %s iterTimeRunes %s %s", i, string(r), p.ds(), p.ts())
|
||||
//gou.Debugf("%d %s iterTimeRunes %s %s", i, string(r), p.ds(), p.ts())
|
||||
|
||||
switch p.stateTime {
|
||||
case timeStart:
|
||||
@ -857,22 +855,21 @@ iterRunes:
|
||||
// 06:20:00 UTC
|
||||
// 15:44:11 UTC+0100 2015
|
||||
// 18:04:07 GMT+0100 (GMT Daylight Time)
|
||||
// 17:57:51 MST 2009
|
||||
// timeWsAMPMMaybe
|
||||
// 05:24:37 PM
|
||||
// timeWsOffset
|
||||
// 15:04:05 -0700
|
||||
// 00:12:00 +0000 UTC
|
||||
// timeWsOffsetColon
|
||||
// 15:04:05 -07:00
|
||||
// 17:57:51 -0700 2009
|
||||
// timeWsOffsetColonAlpha
|
||||
// 00:12:00 +00:00 UTC
|
||||
// timeWsOffsetAlpha
|
||||
// 00:12:00 +0000 UTC
|
||||
// timeWsYear
|
||||
// 00:12:00 2008
|
||||
// timeZ
|
||||
// 15:04:05.99Z
|
||||
gou.Infof("timeWs")
|
||||
switch r {
|
||||
case 'A', 'P':
|
||||
// Could be AM/PM or could be PST or similar
|
||||
@ -885,6 +882,7 @@ iterRunes:
|
||||
if unicode.IsLetter(r) {
|
||||
// 06:20:00 UTC
|
||||
// 15:44:11 UTC+0100 2015
|
||||
// 17:57:51 MST 2009
|
||||
p.tzi = i
|
||||
p.stateTime = timeWsAlpha
|
||||
//break iterTimeRunes
|
||||
@ -896,6 +894,8 @@ iterRunes:
|
||||
}
|
||||
case timeWsAlpha:
|
||||
// 06:20:00 UTC
|
||||
// timeWsAlphaWs
|
||||
// 17:57:51 MST 2009
|
||||
// timeWsAlphaZoneOffset
|
||||
// timeWsAlphaZoneOffsetWs
|
||||
// timeWsAlphaZoneOffsetWsExtra
|
||||
@ -912,7 +912,14 @@ iterRunes:
|
||||
}
|
||||
p.stateTime = timeWsAlphaZoneOffset
|
||||
p.offseti = i
|
||||
case ' ':
|
||||
// 17:57:51 MST 2009
|
||||
p.stateTime = timeWsAlphaWs
|
||||
p.yeari = i + 1
|
||||
}
|
||||
case timeWsAlphaWs:
|
||||
// 17:57:51 MST 2009
|
||||
|
||||
case timeWsAlphaZoneOffset:
|
||||
// timeWsAlphaZoneOffset
|
||||
// timeWsAlphaZoneOffsetWs
|
||||
@ -971,29 +978,32 @@ iterRunes:
|
||||
// 15:04:05 -0700
|
||||
// timeWsOffsetWs
|
||||
// 17:57:51 -0700 2009
|
||||
// 00:12:00 +0000 UTC
|
||||
// timeWsOffsetColon
|
||||
// 15:04:05 -07:00
|
||||
// timeWsOffsetColonAlpha
|
||||
// 00:12:00 +00:00 UTC
|
||||
// timeWsOffsetAlpha
|
||||
// 00:12:00 +0000 UTC
|
||||
gou.Infof("timeWsOffset")
|
||||
switch r {
|
||||
case ':':
|
||||
p.stateTime = timeWsOffsetColon
|
||||
case ' ':
|
||||
p.set(p.offseti, "-0700")
|
||||
gou.Warnf("end of offset?")
|
||||
p.yeari = i + 1
|
||||
p.stateTime = timeWsOffsetWs
|
||||
default:
|
||||
if unicode.IsLetter(r) {
|
||||
// 00:12:00 +0000 UTC
|
||||
p.stateTime = timeWsOffsetAlpha
|
||||
break iterTimeRunes
|
||||
}
|
||||
}
|
||||
case timeWsOffsetWs:
|
||||
|
||||
// 17:57:51 -0700 2009
|
||||
// 00:12:00 +0000 UTC
|
||||
if unicode.IsDigit(r) {
|
||||
p.yearlen = i - p.yeari + 1
|
||||
if p.yearlen == 4 {
|
||||
p.setYear()
|
||||
}
|
||||
} else if unicode.IsLetter(r) {
|
||||
if p.tzi == 0 {
|
||||
p.tzi = i
|
||||
}
|
||||
}
|
||||
case timeWsOffsetColon:
|
||||
// timeWsOffsetColon
|
||||
// 15:04:05 -07:00
|
||||
@ -1051,6 +1061,7 @@ iterRunes:
|
||||
// 19:55:00.799+0100
|
||||
// timePeriodOffsetColon
|
||||
// 15:04:05.999-07:00
|
||||
// 13:31:51.999-07:00 MST
|
||||
if r == ':' {
|
||||
p.stateTime = timePeriodOffsetColon
|
||||
}
|
||||
@ -1058,7 +1069,15 @@ iterRunes:
|
||||
// timePeriodOffset
|
||||
// timePeriodOffsetColon
|
||||
// 15:04:05.999-07:00
|
||||
|
||||
// 13:31:51.999 -07:00 MST
|
||||
switch r {
|
||||
case ' ':
|
||||
p.set(p.offseti, "-07:00")
|
||||
p.stateTime = timePeriodOffsetColonWs
|
||||
p.tzi = i + 1
|
||||
}
|
||||
case timePeriodOffsetColonWs:
|
||||
// continue
|
||||
case timePeriodWs:
|
||||
// timePeriodWs
|
||||
// timePeriodWsOffset
|
||||
@ -1067,6 +1086,8 @@ iterRunes:
|
||||
// timePeriodWsOffsetAlpha
|
||||
// 00:07:31.945167 +0000 UTC
|
||||
// 00:00:00.000 +0000 UTC
|
||||
// timePeriodWsOffsetColon
|
||||
// 13:31:51.999 -07:00 MST
|
||||
// timePeriodWsAlpha
|
||||
// 06:20:00.000 UTC
|
||||
if p.offseti == 0 {
|
||||
@ -1094,9 +1115,13 @@ iterRunes:
|
||||
// timePeriodWsOffsetAlpha
|
||||
// 00:07:31.945167 +0000 UTC
|
||||
// 00:00:00.000 +0000 UTC
|
||||
// timePeriodWsOffsetColon
|
||||
// 13:31:51.999 -07:00 MST
|
||||
// timePeriodWsAlpha
|
||||
// 06:20:00.000 UTC
|
||||
switch r {
|
||||
case ':':
|
||||
p.stateTime = timePeriodWsOffsetColon
|
||||
case ' ':
|
||||
p.set(p.offseti, "-0700")
|
||||
default:
|
||||
@ -1108,6 +1133,20 @@ iterRunes:
|
||||
}
|
||||
}
|
||||
|
||||
case timePeriodWsOffsetColon:
|
||||
// 13:31:51.999 -07:00 MST
|
||||
switch r {
|
||||
case ' ':
|
||||
p.set(p.offseti, "-07:00")
|
||||
default:
|
||||
if unicode.IsLetter(r) {
|
||||
// 13:31:51.999 -07:00 MST
|
||||
p.tzi = i
|
||||
p.stateTime = timePeriodWsOffsetColonAlpha
|
||||
}
|
||||
}
|
||||
case timePeriodWsOffsetColonAlpha:
|
||||
// continue
|
||||
case timeZ:
|
||||
// timeZ
|
||||
// 15:04:05.99Z
|
||||
@ -1124,7 +1163,9 @@ iterRunes:
|
||||
}
|
||||
|
||||
switch p.stateTime {
|
||||
case timeWsAlpha:
|
||||
case timeWsAlphaWs:
|
||||
p.yearlen = i - p.yeari
|
||||
p.setYear()
|
||||
case timeWsYear:
|
||||
p.yearlen = i - p.yeari
|
||||
p.setYear()
|
||||
@ -1138,7 +1179,11 @@ iterRunes:
|
||||
case timeWsOffset:
|
||||
p.set(p.offseti, "-0700")
|
||||
case timeWsOffsetWs:
|
||||
// 17:57:51 -0700 2009
|
||||
// 17:57:51 -0700 2009
|
||||
// 00:12:00 +0000 UTC
|
||||
case timeWsOffsetColon:
|
||||
// 17:57:51 -07:00
|
||||
p.set(p.offseti, "-07:00")
|
||||
case timeOffsetColon:
|
||||
// 15:04:05+07:00
|
||||
p.set(p.offseti, "-07:00")
|
||||
@ -1147,6 +1192,14 @@ iterRunes:
|
||||
p.set(p.offseti, "-0700")
|
||||
case timePeriodOffsetColon:
|
||||
p.set(p.offseti, "-07:00")
|
||||
case timePeriodWsOffsetColonAlpha:
|
||||
p.tzlen = i - p.tzi
|
||||
switch p.tzlen {
|
||||
case 3:
|
||||
p.set(p.tzi, "MST")
|
||||
case 4:
|
||||
p.set(p.tzi, "MST ")
|
||||
}
|
||||
case timePeriodWsOffset:
|
||||
p.set(p.offseti, "-0700")
|
||||
}
|
||||
@ -1266,7 +1319,7 @@ iterRunes:
|
||||
case dateAlphaWsAlphaYearmaybe:
|
||||
return p.parse()
|
||||
|
||||
case dateDigitSlash: // starts digit then slash 02/ (but nothing else)
|
||||
case dateDigitSlash:
|
||||
// 3/1/2014
|
||||
// 10/13/2014
|
||||
// 01/02/2006
|
||||
@ -1287,16 +1340,11 @@ iterRunes:
|
||||
// Monday, 02-Jan-06 15:04:05 MST
|
||||
return p.parse()
|
||||
|
||||
case dateWeekdayAbbrevComma: // Starts alpha then comma
|
||||
case dateWeekdayAbbrevComma:
|
||||
// Mon, 02-Jan-06 15:04:05 MST
|
||||
// Mon, 02 Jan 2006 15:04:05 MST
|
||||
return p.parse()
|
||||
|
||||
case dateWeekdayAbbrevCommaDash:
|
||||
// Mon, 02-Jan-06 15:04:05 MST
|
||||
// Mon, 2-Jan-06 15:04:05 MST
|
||||
return p.parse()
|
||||
|
||||
}
|
||||
|
||||
return time.Time{}, fmt.Errorf("Could not find date format for %s", datestr)
|
||||
|
777
parseany_test.go
777
parseany_test.go
@ -121,7 +121,7 @@ func TestOne(t *testing.T) {
|
||||
}
|
||||
|
||||
type dateTest struct {
|
||||
in, out string
|
||||
in, out, loc string
|
||||
}
|
||||
|
||||
// {in: , out: },
|
||||
@ -142,12 +142,275 @@ var testInputs = []dateTest{
|
||||
{in: "Thu May 8 17:57:51 2009", out: "2009-05-08 17:57:51 +0000 UTC"},
|
||||
// RubyDate = "Mon Jan 02 15:04:05 -0700 2006"
|
||||
{in: "Mon Jan 02 15:04:05 -0700 2006", out: "2006-01-02 22:04:05 +0000 UTC"},
|
||||
{in: "Thu May 08 17:57:51 -0700 2009", out: "2009-05-08 17:57:51 +0000 UTC"},
|
||||
{in: "Thu May 08 11:57:51 -0700 2009", out: "2009-05-08 18:57:51 +0000 UTC"},
|
||||
// UnixDate = "Mon Jan _2 15:04:05 MST 2006"
|
||||
{in: "Mon Jan 2 15:04:05 MST 2006", out: "2006-01-02 15:04:05 +0000 UTC"},
|
||||
{in: "Thu May 8 17:57:51 MST 2009", out: "2009-05-08 17:57:51 +0000 UTC"},
|
||||
{in: "Thu May 8 17:57:51 PST 2009", out: "2009-05-08 17:57:51 +0000 UTC"},
|
||||
{in: "Thu May 08 17:57:51 PST 2009", out: "2009-05-08 17:57:51 +0000 UTC"},
|
||||
{in: "Thu May 08 05:05:07 PST 2009", out: "2009-05-08 05:05:07 +0000 UTC"},
|
||||
{in: "Thu May 08 5:5:7 PST 2009", out: "2009-05-08 05:05:07 +0000 UTC"},
|
||||
// ??
|
||||
{in: "Mon Aug 10 15:44:11 UTC+0000 2015", out: "2015-08-10 15:44:11 +0000 UTC"},
|
||||
{in: "Mon Aug 10 15:44:11 PST-0700 2015", out: "2015-08-10 22:44:11 +0000 UTC"},
|
||||
{in: "Mon Aug 10 15:44:11 CEST+0200 2015", out: "2015-08-10 13:44:11 +0000 UTC"},
|
||||
{in: "Mon Aug 1 15:44:11 CEST+0200 2015", out: "2015-08-01 13:44:11 +0000 UTC"},
|
||||
{in: "Mon Aug 1 5:44:11 CEST+0200 2015", out: "2015-08-01 03:44:11 +0000 UTC"},
|
||||
// ??
|
||||
{in: "Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)", out: "2015-07-03 17:04:07 +0000 UTC"},
|
||||
{in: "Fri Jul 3 2015 06:04:07 GMT+0100 (GMT Daylight Time)", out: "2015-07-03 05:04:07 +0000 UTC"},
|
||||
{in: "Fri Jul 3 2015 06:04:07 PST-0700 (Pacific Daylight Time)", out: "2015-07-03 13:04:07 +0000 UTC"},
|
||||
// ?
|
||||
{in: "Fri, 03 Jul 2015 08:08:08 MST", out: "2015-07-03 08:08:08 +0000 UTC"},
|
||||
{in: "Fri, 03 Jul 2015 08:08:08 PST", out: "2015-07-03 15:08:08 +0000 UTC", loc: "America/Los_Angeles"},
|
||||
{in: "Fri, 03 Jul 2015 08:08:08 PST", out: "2015-07-03 08:08:08 +0000 UTC"},
|
||||
{in: "Fri, 3 Jul 2015 08:08:08 MST", out: "2015-07-03 08:08:08 +0000 UTC"},
|
||||
{in: "Fri, 03 Jul 2015 8:08:08 MST", out: "2015-07-03 08:08:08 +0000 UTC"},
|
||||
{in: "Fri, 03 Jul 2015 8:8:8 MST", out: "2015-07-03 08:08:08 +0000 UTC"},
|
||||
// ?
|
||||
{in: "Thu, 03 Jul 2017 08:08:04 +0100", out: "2017-07-03 07:08:04 +0000 UTC"},
|
||||
{in: "Thu, 03 Jul 2017 08:08:04 -0100", out: "2017-07-03 09:08:04 +0000 UTC"},
|
||||
{in: "Thu, 3 Jul 2017 08:08:04 +0100", out: "2017-07-03 07:08:04 +0000 UTC"},
|
||||
{in: "Thu, 03 Jul 2017 8:08:04 +0100", out: "2017-07-03 07:08:04 +0000 UTC"},
|
||||
{in: "Thu, 03 Jul 2017 8:8:4 +0100", out: "2017-07-03 07:08:04 +0000 UTC"},
|
||||
//
|
||||
{in: "Tue, 11 Jul 2017 04:08:03 +0200 (CEST)", out: "2017-07-11 02:08:03 +0000 UTC"},
|
||||
{in: "Tue, 5 Jul 2017 04:08:03 -0700 (CEST)", out: "2017-07-05 11:08:03 +0000 UTC"},
|
||||
{in: "Tue, 11 Jul 2017 04:08:03 +0200 (CEST)", out: "2017-07-11 02:08:03 +0000 UTC", loc: "Europe/Berlin"},
|
||||
// day, dd-Mon-yy hh:mm:zz TZ
|
||||
{in: "Fri, 03-Jul-15 08:08:08 MST", out: "2015-07-03 08:08:08 +0000 UTC"},
|
||||
{in: "Fri, 03-Jul-15 08:08:08 PST", out: "2015-07-03 15:08:08 +0000 UTC", loc: "America/Los_Angeles"},
|
||||
{in: "Fri, 03-Jul 2015 08:08:08 PST", out: "2015-07-03 08:08:08 +0000 UTC"},
|
||||
{in: "Fri, 3-Jul-15 08:08:08 MST", out: "2015-07-03 08:08:08 +0000 UTC"},
|
||||
{in: "Fri, 03-Jul-15 8:08:08 MST", out: "2015-07-03 08:08:08 +0000 UTC"},
|
||||
{in: "Fri, 03-Jul-15 8:8:8 MST", out: "2015-07-03 08:08:08 +0000 UTC"},
|
||||
// RFC850 = "Monday, 02-Jan-06 15:04:05 MST"
|
||||
{in: "Wednesday, 07-May-09 08:00:43 MST", out: "2009-05-07 08:00:43 +0000 UTC"},
|
||||
{in: "Wednesday, 28-Feb-18 09:01:00 MST", out: "2018-02-28 09:01:00 +0000 UTC"},
|
||||
{in: "Wednesday, 28-Feb-18 09:01:00 MST", out: "2018-02-28 16:01:00 +0000 UTC", loc: "America/Denver"},
|
||||
// with offset then with variations on non-zero filled stuff
|
||||
{in: "Monday, 02 Jan 2006 15:04:05 +0100", out: "2006-01-02 14:04:05 +0000 UTC"},
|
||||
{in: "Wednesday, 28 Feb 2018 09:01:00 -0300", out: "2018-02-28 12:01:00 +0000 UTC"},
|
||||
{in: "Wednesday, 2 Feb 2018 09:01:00 -0300", out: "2018-02-02 12:01:00 +0000 UTC"},
|
||||
{in: "Wednesday, 2 Feb 2018 9:01:00 -0300", out: "2018-02-02 12:01:00 +0000 UTC"},
|
||||
{in: "Wednesday, 2 Feb 2018 09:1:00 -0300", out: "2018-02-02 12:01:00 +0000 UTC"},
|
||||
// 12 Feb 2006, 19:17:08
|
||||
{in: "07 Feb 2004, 09:07", out: "2004-02-07 09:07:00 +0000 UTC"},
|
||||
{in: "07 Feb 2004, 09:07:07", out: "2004-02-07 09:07:07 +0000 UTC"},
|
||||
{in: "7 Feb 2004, 09:07:07", out: "2004-02-07 09:07:07 +0000 UTC"},
|
||||
{in: "07 Feb 2004, 9:7:7", out: "2004-02-07 09:07:07 +0000 UTC"},
|
||||
// 12 Feb 2006, 19:17:08 GMT
|
||||
{in: "07 Feb 2004, 09:07:07 GMT", out: "2004-02-07 09:07:07 +0000 UTC"},
|
||||
// 12 Feb 2006, 19:17:08 +0100
|
||||
{in: "07 Feb 2004, 09:07:07 +0100", out: "2004-02-07 08:07:07 +0000 UTC"},
|
||||
// 2013-Feb-03
|
||||
{in: "2013-Feb-03", out: "2013-02-03 00:00:00 +0000 UTC"},
|
||||
// 03 February 2013
|
||||
{in: "03 February 2013", out: "2013-02-03 00:00:00 +0000 UTC"},
|
||||
{in: "3 February 2013", out: "2013-02-03 00:00:00 +0000 UTC"},
|
||||
// Chinese 2014年04月18日
|
||||
{in: "2014年04月08日", out: "2014-04-08 00:00:00 +0000 UTC"},
|
||||
{in: "2014年04月08日 19:17:22", out: "2014-04-08 19:17:22 +0000 UTC"},
|
||||
// mm/dd/yyyy
|
||||
{in: "03/31/2014", out: "2014-03-31 00:00:00 +0000 UTC"},
|
||||
{in: "3/31/2014", out: "2014-03-31 00:00:00 +0000 UTC"},
|
||||
{in: "3/5/2014", out: "2014-03-05 00:00:00 +0000 UTC"},
|
||||
// mm/dd/yy
|
||||
{in: "08/08/71", out: "1971-08-08 00:00:00 +0000 UTC"},
|
||||
{in: "8/8/71", out: "1971-08-08 00:00:00 +0000 UTC"},
|
||||
// mm/dd/yy hh:mm:ss
|
||||
{in: "04/02/2014 04:08:09", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "4/2/2014 04:08:09", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "04/02/2014 4:08:09", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "04/02/2014 4:8:9", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "04/02/2014 04:08", out: "2014-04-02 04:08:00 +0000 UTC"},
|
||||
{in: "04/02/2014 4:8", out: "2014-04-02 04:08:00 +0000 UTC"},
|
||||
{in: "04/02/2014 04:08:09.123", out: "2014-04-02 04:08:09.123 +0000 UTC"},
|
||||
{in: "04/02/2014 04:08:09.12312", out: "2014-04-02 04:08:09.12312 +0000 UTC"},
|
||||
{in: "04/02/2014 04:08:09.123123", out: "2014-04-02 04:08:09.123123 +0000 UTC"},
|
||||
// mm/dd/yy hh:mm:ss AM
|
||||
{in: "04/02/2014 04:08:09 AM", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "04/02/2014 04:08:09 PM", out: "2014-04-02 16:08:09 +0000 UTC"},
|
||||
{in: "04/02/2014 04:08 AM", out: "2014-04-02 04:08:00 +0000 UTC"},
|
||||
{in: "04/02/2014 04:08 PM", out: "2014-04-02 16:08:00 +0000 UTC"},
|
||||
{in: "04/02/2014 4:8 AM", out: "2014-04-02 04:08:00 +0000 UTC"},
|
||||
{in: "04/02/2014 4:8 PM", out: "2014-04-02 16:08:00 +0000 UTC"},
|
||||
{in: "04/02/2014 04:08:09.123 AM", out: "2014-04-02 04:08:09.123 +0000 UTC"},
|
||||
{in: "04/02/2014 04:08:09.123 PM", out: "2014-04-02 16:08:09.123 +0000 UTC"},
|
||||
// yyyy/mm/dd
|
||||
{in: "2014/04/02", out: "2014-04-02 00:00:00 +0000 UTC"},
|
||||
{in: "2014/03/31", out: "2014-03-31 00:00:00 +0000 UTC"},
|
||||
{in: "2014/4/2", out: "2014-04-02 00:00:00 +0000 UTC"},
|
||||
// yyyy/mm/dd hh:mm:ss AM
|
||||
{in: "2014/04/02 04:08", out: "2014-04-02 04:08:00 +0000 UTC"},
|
||||
{in: "2014/03/31 04:08", out: "2014-03-31 04:08:00 +0000 UTC"},
|
||||
{in: "2014/4/2 04:08", out: "2014-04-02 04:08:00 +0000 UTC"},
|
||||
{in: "2014/04/02 4:8", out: "2014-04-02 04:08:00 +0000 UTC"},
|
||||
{in: "2014/04/02 04:08:09", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "2014/03/31 04:08:09", out: "2014-03-31 04:08:09 +0000 UTC"},
|
||||
{in: "2014/4/2 04:08:09", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "2014/04/02 04:08:09.123", out: "2014-04-02 04:08:09.123 +0000 UTC"},
|
||||
{in: "2014/04/02 04:08:09.123123", out: "2014-04-02 04:08:09.123123 +0000 UTC"},
|
||||
{in: "2014/04/02 04:08:09 AM", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "2014/03/31 04:08:09 AM", out: "2014-03-31 04:08:09 +0000 UTC"},
|
||||
{in: "2014/4/2 04:08:09 AM", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "2014/04/02 04:08:09.123 AM", out: "2014-04-02 04:08:09.123 +0000 UTC"},
|
||||
{in: "2014/04/02 04:08:09.123 PM", out: "2014-04-02 16:08:09.123 +0000 UTC"},
|
||||
// yyyy-mm-dd
|
||||
{in: "2014-04-02", out: "2014-04-02 00:00:00 +0000 UTC"},
|
||||
{in: "2014-03-31", out: "2014-03-31 00:00:00 +0000 UTC"},
|
||||
{in: "2014-4-2", out: "2014-04-02 00:00:00 +0000 UTC"},
|
||||
// yyyy-mm
|
||||
{in: "2014-04", out: "2014-04-01 00:00:00 +0000 UTC"},
|
||||
// yyyy-mm-dd hh:mm:ss AM
|
||||
{in: "2014-04-02 04:08", out: "2014-04-02 04:08:00 +0000 UTC"},
|
||||
{in: "2014-03-31 04:08", out: "2014-03-31 04:08:00 +0000 UTC"},
|
||||
{in: "2014-4-2 04:08", out: "2014-04-02 04:08:00 +0000 UTC"},
|
||||
{in: "2014-04-02 4:8", out: "2014-04-02 04:08:00 +0000 UTC"},
|
||||
{in: "2014-04-02 04:08:09", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "2014-03-31 04:08:09", out: "2014-03-31 04:08:09 +0000 UTC"},
|
||||
{in: "2014-4-2 04:08:09", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "2014-04-02 04:08:09.123", out: "2014-04-02 04:08:09.123 +0000 UTC"},
|
||||
{in: "2014-04-02 04:08:09.123123", out: "2014-04-02 04:08:09.123123 +0000 UTC"},
|
||||
{in: "2014-04-02 04:08:09.12312312", out: "2014-04-02 04:08:09.12312312 +0000 UTC"},
|
||||
{in: "2014-04-02 04:08:09 AM", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "2014-03-31 04:08:09 AM", out: "2014-03-31 04:08:09 +0000 UTC"},
|
||||
{in: "2014-04-26 05:24:37 PM", out: "2014-04-26 17:24:37 +0000 UTC"},
|
||||
{in: "2014-4-2 04:08:09 AM", out: "2014-04-02 04:08:09 +0000 UTC"},
|
||||
{in: "2014-04-02 04:08:09.123 AM", out: "2014-04-02 04:08:09.123 +0000 UTC"},
|
||||
{in: "2014-04-02 04:08:09.123 PM", out: "2014-04-02 16:08:09.123 +0000 UTC"},
|
||||
// yyyy-mm-dd hh:mm:ss,000
|
||||
{in: "2014-05-11 08:20:13,787", out: "2014-05-11 08:20:13.787 +0000 UTC"},
|
||||
// yyyy-mm-dd hh:mm:ss +0000
|
||||
{in: "2012-08-03 18:31:59 +0000", out: "2012-08-03 18:31:59 +0000 UTC"},
|
||||
{in: "2012-08-03 13:31:59 -0600", out: "2012-08-03 19:31:59 +0000 UTC"},
|
||||
{in: "2012-08-03 18:31:59.257000000 +0000", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2012-08-03 8:1:59.257000000 +0000", out: "2012-08-03 08:01:59.257 +0000 UTC"},
|
||||
{in: "2012-8-03 18:31:59.257000000 +0000", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2012-8-3 18:31:59.257000000 +0000", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.123456 +0000", out: "2014-04-26 17:24:37.123456 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.12 +0000", out: "2014-04-26 17:24:37.12 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.1 +0000", out: "2014-04-26 17:24:37.1 +0000 UTC"},
|
||||
{in: "2014-05-11 08:20:13 +0000", out: "2014-05-11 08:20:13 +0000 UTC"},
|
||||
|
||||
// 13:31:51.999 -07:00 MST
|
||||
// yyyy-mm-dd hh:mm:ss +00:00
|
||||
{in: "2012-08-03 18:31:59 +00:00", out: "2012-08-03 18:31:59 +0000 UTC"},
|
||||
{in: "2014-05-01 08:02:13 +00:00", out: "2014-05-01 08:02:13 +0000 UTC"},
|
||||
{in: "2014-5-01 08:02:13 +00:00", out: "2014-05-01 08:02:13 +0000 UTC"},
|
||||
{in: "2014-05-1 08:02:13 +00:00", out: "2014-05-01 08:02:13 +0000 UTC"},
|
||||
{in: "2012-08-03 13:31:59 -06:00", out: "2012-08-03 19:31:59 +0000 UTC"},
|
||||
{in: "2012-08-03 18:31:59.257000000 +00:00", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2012-08-03 8:1:59.257000000 +00:00", out: "2012-08-03 08:01:59.257 +0000 UTC"},
|
||||
{in: "2012-8-03 18:31:59.257000000 +00:00", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2012-8-3 18:31:59.257000000 +00:00", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.123456 +00:00", out: "2014-04-26 17:24:37.123456 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.12 +00:00", out: "2014-04-26 17:24:37.12 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.1 +00:00", out: "2014-04-26 17:24:37.1 +0000 UTC"},
|
||||
// yyyy-mm-dd hh:mm:ss +0000 TZ
|
||||
// Golang Native Format
|
||||
{in: "2012-08-03 18:31:59 +0000 UTC", out: "2012-08-03 18:31:59 +0000 UTC"},
|
||||
{in: "2012-08-03 13:31:59 -0600 MST", out: "2012-08-03 19:31:59 +0000 UTC", loc: "America/Denver"},
|
||||
{in: "2015-02-18 00:12:00 +0000 UTC", out: "2015-02-18 00:12:00 +0000 UTC"},
|
||||
{in: "2015-02-18 00:12:00 +0000 GMT", out: "2015-02-18 00:12:00 +0000 UTC"},
|
||||
{in: "2015-02-08 03:02:00 +0200 CEST", out: "2015-02-08 01:02:00 +0000 UTC", loc: "Europe/Berlin"},
|
||||
{in: "2015-02-08 03:02:00 +0300 MSK", out: "2015-02-08 00:02:00 +0000 UTC"},
|
||||
{in: "2015-2-08 03:02:00 +0300 MSK", out: "2015-02-08 00:02:00 +0000 UTC"},
|
||||
{in: "2015-02-8 03:02:00 +0300 MSK", out: "2015-02-08 00:02:00 +0000 UTC"},
|
||||
{in: "2015-2-8 03:02:00 +0300 MSK", out: "2015-02-08 00:02:00 +0000 UTC"},
|
||||
{in: "2012-08-03 18:31:59.257000000 +0000 UTC", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2012-08-03 8:1:59.257000000 +0000 UTC", out: "2012-08-03 08:01:59.257 +0000 UTC"},
|
||||
{in: "2012-8-03 18:31:59.257000000 +0000 UTC", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2012-8-3 18:31:59.257000000 +0000 UTC", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.123456 +0000 UTC", out: "2014-04-26 17:24:37.123456 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.12 +0000 UTC", out: "2014-04-26 17:24:37.12 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.1 +0000 UTC", out: "2014-04-26 17:24:37.1 +0000 UTC"},
|
||||
// yyyy-mm-dd hh:mm:ss TZ
|
||||
{in: "2012-08-03 18:31:59 UTC", out: "2012-08-03 18:31:59 +0000 UTC"},
|
||||
{in: "2014-12-16 06:20:00 GMT", out: "2014-12-16 06:20:00 +0000 UTC"},
|
||||
{in: "2012-08-03 13:31:59 MST", out: "2012-08-03 20:31:59 +0000 UTC", loc: "America/Denver"},
|
||||
{in: "2012-08-03 18:31:59.257000000 UTC", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2012-08-03 8:1:59.257000000 UTC", out: "2012-08-03 08:01:59.257 +0000 UTC"},
|
||||
{in: "2012-8-03 18:31:59.257000000 UTC", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2012-8-3 18:31:59.257000000 UTC", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.123456 UTC", out: "2014-04-26 17:24:37.123456 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.12 UTC", out: "2014-04-26 17:24:37.12 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.1 UTC", out: "2014-04-26 17:24:37.1 +0000 UTC"},
|
||||
// This one is pretty special, it is TIMEZONE based but starts with P to emulate collions with PM
|
||||
{in: "2014-04-26 05:24:37 PST", out: "2014-04-26 05:24:37 +0000 UTC"},
|
||||
{in: "2014-04-26 05:24:37 PST", out: "2014-04-26 12:24:37 +0000 UTC", loc: "America/Los_Angeles"},
|
||||
// yyyy-mm-dd hh:mm:ss+00:00
|
||||
{in: "2012-08-03 18:31:59+00:00", out: "2012-08-03 18:31:59 +0000 UTC"},
|
||||
{in: "2017-07-19 03:21:51+00:00", out: "2017-07-19 03:21:51 +0000 UTC"},
|
||||
// yyyy-mm-dd hh:mm:ss.000+00:00 PST
|
||||
{in: "2012-08-03 18:31:59.000+00:00 PST", out: "2012-08-03 18:31:59 +0000 UTC", loc: "America/Los_Angeles"},
|
||||
// yyyy-mm-dd hh:mm:ss +00:00 TZ
|
||||
{in: "2012-08-03 18:31:59 +00:00 UTC", out: "2012-08-03 18:31:59 +0000 UTC"},
|
||||
{in: "2012-08-03 13:31:51 -07:00 MST", out: "2012-08-03 20:31:51 +0000 UTC", loc: "America/Denver"},
|
||||
{in: "2012-08-03 18:31:59.257000000 +00:00 UTC", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2012-08-03 13:31:51.123 -08:00 PST", out: "2012-08-03 21:31:51.123 +0000 UTC", loc: "America/Los_Angeles"},
|
||||
{in: "2012-08-03 13:31:51.123 +02:00 CEST", out: "2012-08-03 11:31:51.123 +0000 UTC", loc: "Europe/Berlin"},
|
||||
{in: "2012-08-03 8:1:59.257000000 +00:00 UTC", out: "2012-08-03 08:01:59.257 +0000 UTC"},
|
||||
{in: "2012-8-03 18:31:59.257000000 +00:00 UTC", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2012-8-3 18:31:59.257000000 +00:00 UTC", out: "2012-08-03 18:31:59.257 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.123456 +00:00 UTC", out: "2014-04-26 17:24:37.123456 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.12 +00:00 UTC", out: "2014-04-26 17:24:37.12 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.1 +00:00 UTC", out: "2014-04-26 17:24:37.1 +0000 UTC"},
|
||||
// yyyy-mm-ddThh:mm:ss
|
||||
{in: "2009-08-12T22:15:09", out: "2009-08-12 22:15:09 +0000 UTC"},
|
||||
{in: "2009-08-08T02:08:08", out: "2009-08-08 02:08:08 +0000 UTC"},
|
||||
{in: "2009-08-08T2:8:8", out: "2009-08-08 02:08:08 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09.123", out: "2009-08-12 22:15:09.123 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09.123456", out: "2009-08-12 22:15:09.123456 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09.12", out: "2009-08-12 22:15:09.12 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09.1", out: "2009-08-12 22:15:09.1 +0000 UTC"},
|
||||
{in: "2014-04-26 17:24:37.3186369", out: "2014-04-26 17:24:37.3186369 +0000 UTC"},
|
||||
// yyyy-mm-ddThh:mm:ss-07:00
|
||||
{in: "2009-08-12T22:15:09-07:00", out: "2009-08-13 05:15:09 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09-03:00", out: "2009-08-13 01:15:09 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:9-07:00", out: "2009-08-13 05:15:09 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09.123-07:00", out: "2009-08-13 05:15:09.123 +0000 UTC"},
|
||||
{in: "2016-06-21T19:55:00+01:00", out: "2016-06-21 18:55:00 +0000 UTC"},
|
||||
{in: "2016-06-21T19:55:00.799+01:00", out: "2016-06-21 18:55:00.799 +0000 UTC"},
|
||||
// yyyy-mm-ddThh:mm:ss-0700
|
||||
{in: "2009-08-12T22:15:09-0700", out: "2009-08-13 05:15:09 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09-0300", out: "2009-08-13 01:15:09 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:9-0700", out: "2009-08-13 05:15:09 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09.123-0700", out: "2009-08-13 05:15:09.123 +0000 UTC"},
|
||||
{in: "2016-06-21T19:55:00+0100", out: "2016-06-21 18:55:00 +0000 UTC"},
|
||||
{in: "2016-06-21T19:55:00.799+0100", out: "2016-06-21 18:55:00.799 +0000 UTC"},
|
||||
{in: "2016-06-21T19:55:00+0100", out: "2016-06-21 18:55:00 +0000 UTC"},
|
||||
{in: "2016-06-21T19:55:00-0700", out: "2016-06-22 02:55:00 +0000 UTC"},
|
||||
{in: "2016-06-21T19:55:00.799+0100", out: "2016-06-21 18:55:00.799 +0000 UTC"},
|
||||
// yyyy-mm-ddThh:mm:ssZ
|
||||
{in: "2009-08-12T22:15Z", out: "2009-08-12 22:15:00 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09Z", out: "2009-08-12 22:15:09 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09.99Z", out: "2009-08-12 22:15:09.99 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09.9999Z", out: "2009-08-12 22:15:09.9999 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:09.99999999Z", out: "2009-08-12 22:15:09.99999999 +0000 UTC"},
|
||||
{in: "2009-08-12T22:15:9.99999999Z", out: "2009-08-12 22:15:09.99999999 +0000 UTC"},
|
||||
// mm.dd.yyyy
|
||||
{in: "3.31.2014", out: "2014-03-31 00:00:00 +0000 UTC"},
|
||||
{in: "3.3.2014", out: "2014-03-03 00:00:00 +0000 UTC"},
|
||||
{in: "03.31.2014", out: "2014-03-31 00:00:00 +0000 UTC"},
|
||||
// mm.dd.yy
|
||||
{in: "08.21.71", out: "1971-08-21 00:00:00 +0000 UTC"},
|
||||
// yyyymmdd and similar
|
||||
{in: "2014", out: "2014-01-01 00:00:00 +0000 UTC"},
|
||||
{in: "20140601", out: "2014-06-01 00:00:00 +0000 UTC"},
|
||||
// all digits: unix secs, ms etc
|
||||
{in: "1332151919", out: "2012-03-19 10:11:59 +0000 UTC"},
|
||||
{in: "1332151919", out: "2012-03-19 10:11:59 +0000 UTC", loc: "America/Denver"},
|
||||
{in: "1384216367111", out: "2013-11-12 00:32:47.111 +0000 UTC"},
|
||||
{in: "1384216367111222", out: "2013-11-12 00:32:47.111222 +0000 UTC"},
|
||||
{in: "1384216367111222333", out: "2013-11-12 00:32:47.111222333 +0000 UTC"},
|
||||
}
|
||||
|
||||
/*
|
||||
{in: , out: },
|
||||
|
||||
|
||||
*/
|
||||
func TestParse(t *testing.T) {
|
||||
|
||||
// Lets ensure we are operating on UTC
|
||||
@ -159,499 +422,45 @@ func TestParse(t *testing.T) {
|
||||
assert.NotEqual(t, nil, err)
|
||||
|
||||
assert.Equal(t, true, testDidPanic("NOT GONNA HAPPEN"))
|
||||
|
||||
for _, th := range testInputs {
|
||||
ts = MustParse(th.in)
|
||||
got := fmt.Sprintf("%v", ts.In(time.UTC))
|
||||
assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in)
|
||||
}
|
||||
|
||||
// RFC850 = "Monday, 02-Jan-06 15:04:05 MST"
|
||||
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)))
|
||||
|
||||
// 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)))
|
||||
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)))
|
||||
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)))
|
||||
|
||||
// Another weird one, year on the end after UTC?
|
||||
ts = MustParse("Mon Aug 10 15:44:11 UTC+0000 2015")
|
||||
assert.Equal(t, "2015-08-10 15:44:11 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
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)))
|
||||
ts = MustParse("Mon Aug 10 15:44:11 CEST+0200 2015")
|
||||
assert.Equal(t, "2015-08-10 13:44:11 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
// Easily the worst Date format I have ever seen
|
||||
// "Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)"
|
||||
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)))
|
||||
|
||||
ts = MustParse("Fri, 03 Jul 2015 13:04:07 MST")
|
||||
assert.Equal(t, "2015-07-03 13:04:07 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
// not sure if this is anything close to a standard, never seen it before
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
// // 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)))
|
||||
|
||||
ts = MustParse("2013-Feb-03")
|
||||
assert.Equal(t, "2013-02-03 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
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)))
|
||||
|
||||
//---------------------------------------------
|
||||
// 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)))
|
||||
|
||||
//---------------------------------------------
|
||||
// mm/dd/yyyy ?
|
||||
|
||||
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)))
|
||||
|
||||
// what type of date is this? 08/21/71
|
||||
ts = MustParse("08/21/71")
|
||||
assert.Equal(t, "1971-08-21 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
// m/d/yy
|
||||
ts = MustParse("8/1/71")
|
||||
assert.Equal(t, "1971-08-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
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)))
|
||||
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)))
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
//---------------------------------------------
|
||||
// yyyy/mm/dd ?
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
//---------------------------------------------
|
||||
// yyyy-mm-dd ?
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
// 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)))
|
||||
for _, th := range testInputs {
|
||||
if len(th.loc) > 0 {
|
||||
loc, err := time.LoadLocation(th.loc)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected to load location %q but got %v", th.loc, err)
|
||||
}
|
||||
ts, err = ParseIn(th.in, loc)
|
||||
if err != nil {
|
||||
t.Fatalf("expected to parse %q but got %v", th.in, err)
|
||||
}
|
||||
got := fmt.Sprintf("%v", ts.In(time.UTC))
|
||||
assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in)
|
||||
if th.out != got {
|
||||
panic("whoops")
|
||||
}
|
||||
} else {
|
||||
ts = MustParse(th.in)
|
||||
got := fmt.Sprintf("%v", ts.In(time.UTC))
|
||||
assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in)
|
||||
if th.out != got {
|
||||
panic("whoops")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)))
|
||||
|
||||
// 2015-06-25 01:25:37.115208593 +0000 UTC
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
// 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)))
|
||||
|
||||
ts = MustParse("2014-04-26")
|
||||
assert.Equal(t, "2014-04-26 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts = MustParse("2014-04")
|
||||
assert.Equal(t, "2014-04-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
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)))
|
||||
|
||||
_, err = ParseAny("2014-13-13 08:20:13,787") // month 13 doesn't exist so error
|
||||
assert.NotEqual(t, nil, err)
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
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)))
|
||||
|
||||
//---------------------------------------------
|
||||
// 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)))
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
// yyyymmdd and similar
|
||||
ts = MustParse("2014")
|
||||
assert.Equal(t, "2014-01-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts = MustParse("20140601")
|
||||
assert.Equal(t, "2014-06-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts = MustParse("1332151919")
|
||||
assert.Equal(t, "2012-03-19 10:11:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts = MustParse("1384216367111")
|
||||
assert.Equal(t, "2013-11-12 00:32:47.111 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, _ = ParseIn("1384216367111", time.UTC)
|
||||
assert.Equal(t, "2013-11-12 00:32:47.111 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts = MustParse("1384216367111222")
|
||||
assert.Equal(t, "2013-11-12 00:32:47.111222 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
// Nanoseconds
|
||||
ts = MustParse("1384216367111222333")
|
||||
assert.Equal(t, "2013-11-12 00:32:47.111222333 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
// some errors
|
||||
|
||||
_, err = ParseAny("138421636711122233311111") // too many digits
|
||||
assert.NotEqual(t, nil, err)
|
||||
|
||||
_, err = ParseAny("-1314")
|
||||
assert.NotEqual(t, nil, err)
|
||||
|
||||
_, err = ParseAny("2014-13-13 08:20:13,787") // month 13 doesn't exist so error
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func testDidPanic(datestr string) (paniced bool) {
|
||||
|
Loading…
Reference in New Issue
Block a user