mirror of
https://github.com/araddon/dateparse.git
synced 2025-04-11 19:30:33 +08:00
Merge 6848514672dc31083a71ece6a6672dd486b044e2 into 6b43995a97dee4b2c7fc0bdff8e124da9f31a57e
This commit is contained in:
commit
d1ea0a8b49
30
parseany.go
30
parseany.go
@ -531,6 +531,35 @@ iterRunes:
|
||||
}
|
||||
p.stateTime = timeStart
|
||||
break iterRunes
|
||||
case ':':
|
||||
p.link++
|
||||
if p.link == 2 {
|
||||
// we need to find if this was 4 digits, aka year
|
||||
// or 2 digits which makes it ambiguous year/day
|
||||
length := i - (p.moi + p.molen + 2)
|
||||
if length == 4 {
|
||||
p.yearlen = 4
|
||||
p.set(p.yeari, "2006")
|
||||
// We now also know that part1 was the day
|
||||
p.dayi = 0
|
||||
p.daylen = p.part1Len
|
||||
p.setDay()
|
||||
} else if length == 2 {
|
||||
// We have no idea if this is
|
||||
// yy-mon-dd OR dd-mon-yy
|
||||
//
|
||||
// We are going to ASSUME (bad, bad) that it is dd-mon-yy which is a horible assumption
|
||||
p.ambiguousMD = true
|
||||
p.yearlen = 2
|
||||
p.set(p.yeari, "06")
|
||||
// We now also know that part1 was the day
|
||||
p.dayi = 0
|
||||
p.daylen = p.part1Len
|
||||
p.setDay()
|
||||
}
|
||||
p.stateTime = timeStart
|
||||
break iterRunes
|
||||
}
|
||||
}
|
||||
|
||||
case dateDigitYearSlash:
|
||||
@ -1965,6 +1994,7 @@ type parser struct {
|
||||
datestr string
|
||||
fullMonth string
|
||||
skip int
|
||||
link int
|
||||
extra int
|
||||
part1Len int
|
||||
yeari int
|
||||
|
@ -526,6 +526,41 @@ func TestParseErrors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var testParseFormat = []dateTest{
|
||||
// errors
|
||||
{in: "3", err: true},
|
||||
{in: `{"hello"}`, err: true},
|
||||
{in: "2009-15-12T22:15Z", err: true},
|
||||
{in: "5,000-9,999", err: true},
|
||||
//
|
||||
{in: "06/May/2008 15:04:05 -0700", out: "02/Jan/2006 15:04:05 -0700"},
|
||||
{in: "06/May/2008:15:04:05 -0700", out: "02/Jan/2006:15:04:05 -0700"},
|
||||
{in: "14 May 2019 19:11:40.164", out: "02 Jan 2006 15:04:05.000"},
|
||||
{in: "171113 14:14:20", out: "060102 15:04:05"},
|
||||
|
||||
{in: "oct 7, 1970", out: "Jan 2, 2006"},
|
||||
{in: "sept. 7, 1970", out: "Jan. 2, 2006"},
|
||||
{in: "May 05, 2015, 05:05:07", out: "Jan 02, 2006, 15:04:05"},
|
||||
// 03 February 2013
|
||||
{in: "03 February 2013", out: "02 January 2006"},
|
||||
// 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: "2006-01-02 15:04:05 -07:00"},
|
||||
// yyyy-mm-dd hh:mm:ss +0000 TZ
|
||||
// Golang Native Format
|
||||
{in: "2012-08-03 18:31:59 +0000 UTC", out: "2006-01-02 15:04:05 -0700 UTC"},
|
||||
// yyyy-mm-dd hh:mm:ss TZ
|
||||
{in: "2012-08-03 18:31:59 UTC", out: "2006-01-02 15:04:05 UTC"},
|
||||
// yyyy-mm-ddThh:mm:ss-07:00
|
||||
{in: "2009-08-12T22:15:09-07:00", out: "2006-01-02T15:04:05-07:00"},
|
||||
// yyyy-mm-ddThh:mm:ss-0700
|
||||
{in: "2009-08-12T22:15:09-0700", out: "2006-01-02T15:04:05-0700"},
|
||||
// yyyy-mm-ddThh:mm:ssZ
|
||||
{in: "2009-08-12T22:15Z", out: "2006-01-02T15:04Z"},
|
||||
|
||||
{in: "8-Mar-2018::14:09:27", out: "2-Jan-2006::15:04:05"},
|
||||
}
|
||||
|
||||
func TestParseLayout(t *testing.T) {
|
||||
|
||||
time.Local = time.UTC
|
||||
|
Loading…
x
Reference in New Issue
Block a user