mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
Merge pull request #120 from bizy01/master
redis&&mysql log datetime handle
This commit is contained in:
commit
33e44430e1
@ -29,6 +29,10 @@ var examples = []string{
|
|||||||
"September 17, 2012 10:09am",
|
"September 17, 2012 10:09am",
|
||||||
"September 17, 2012 at 10:09am PST-08",
|
"September 17, 2012 at 10:09am PST-08",
|
||||||
"September 17, 2012, 10:10:09",
|
"September 17, 2012, 10:10:09",
|
||||||
|
"06/Jan/2008:15:04:05 -0700",
|
||||||
|
"06/Jan/2008 15:04:05 -0700",
|
||||||
|
"171113 14:14:20",
|
||||||
|
"14 May 2019 19:11:40.164",
|
||||||
"October 7, 1970",
|
"October 7, 1970",
|
||||||
"October 7th, 1970",
|
"October 7th, 1970",
|
||||||
"12 Feb 2006, 19:17",
|
"12 Feb 2006, 19:17",
|
||||||
|
36
parseany.go
36
parseany.go
@ -55,6 +55,7 @@ type timeState uint8
|
|||||||
const (
|
const (
|
||||||
dateStart dateState = iota // 0
|
dateStart dateState = iota // 0
|
||||||
dateDigit
|
dateDigit
|
||||||
|
dateDigitSt
|
||||||
dateYearDash
|
dateYearDash
|
||||||
dateYearDashAlphaDash
|
dateYearDashAlphaDash
|
||||||
dateYearDashDash
|
dateYearDashDash
|
||||||
@ -295,6 +296,7 @@ iterRunes:
|
|||||||
p.stateDate = dateDigitDash
|
p.stateDate = dateDigitDash
|
||||||
}
|
}
|
||||||
case '/':
|
case '/':
|
||||||
|
// 08/May/2005
|
||||||
// 03/31/2005
|
// 03/31/2005
|
||||||
// 2014/02/24
|
// 2014/02/24
|
||||||
p.stateDate = dateDigitSlash
|
p.stateDate = dateDigitSlash
|
||||||
@ -363,9 +365,13 @@ iterRunes:
|
|||||||
// 02 Jan 2018 23:59:34
|
// 02 Jan 2018 23:59:34
|
||||||
// 12 Feb 2006, 19:17
|
// 12 Feb 2006, 19:17
|
||||||
// 12 Feb 2006, 19:17:22
|
// 12 Feb 2006, 19:17:22
|
||||||
|
if i == 6 {
|
||||||
|
p.stateDate = dateDigitSt
|
||||||
|
} else {
|
||||||
p.stateDate = dateDigitWs
|
p.stateDate = dateDigitWs
|
||||||
p.dayi = 0
|
p.dayi = 0
|
||||||
p.daylen = i
|
p.daylen = i
|
||||||
|
}
|
||||||
case '年':
|
case '年':
|
||||||
// Chinese Year
|
// Chinese Year
|
||||||
p.stateDate = dateDigitChineseYear
|
p.stateDate = dateDigitChineseYear
|
||||||
@ -376,6 +382,11 @@ iterRunes:
|
|||||||
}
|
}
|
||||||
p.part1Len = i
|
p.part1Len = i
|
||||||
|
|
||||||
|
case dateDigitSt:
|
||||||
|
p.set(0, "060102")
|
||||||
|
i = i - 1
|
||||||
|
p.stateTime = timeStart
|
||||||
|
break iterRunes
|
||||||
case dateYearDash:
|
case dateYearDash:
|
||||||
// dateYearDashDashT
|
// dateYearDashDashT
|
||||||
// 2006-01-02T15:04:05Z07:00
|
// 2006-01-02T15:04:05Z07:00
|
||||||
@ -441,6 +452,12 @@ iterRunes:
|
|||||||
p.set(p.moi, "Jan")
|
p.set(p.moi, "Jan")
|
||||||
p.yeari = i + 1
|
p.yeari = i + 1
|
||||||
p.stateDate = dateDigitDashAlphaDash
|
p.stateDate = dateDigitDashAlphaDash
|
||||||
|
case '/':
|
||||||
|
p.set(0, "02")
|
||||||
|
p.molen = i - p.moi
|
||||||
|
p.set(p.moi, "Jan")
|
||||||
|
p.yeari = i + 1
|
||||||
|
p.stateDate = dateDigitSlash
|
||||||
}
|
}
|
||||||
|
|
||||||
case dateDigitDashAlphaDash:
|
case dateDigitDashAlphaDash:
|
||||||
@ -498,6 +515,16 @@ iterRunes:
|
|||||||
p.setDay()
|
p.setDay()
|
||||||
}
|
}
|
||||||
break iterRunes
|
break iterRunes
|
||||||
|
case ':':
|
||||||
|
p.stateTime = timeStart
|
||||||
|
if p.yearlen == 0 {
|
||||||
|
p.yearlen = i - p.yeari
|
||||||
|
p.setYear()
|
||||||
|
} else if p.daylen == 0 {
|
||||||
|
p.daylen = i - p.dayi
|
||||||
|
p.setDay()
|
||||||
|
}
|
||||||
|
break iterRunes
|
||||||
case '/':
|
case '/':
|
||||||
if p.yearlen > 0 {
|
if p.yearlen > 0 {
|
||||||
// 2014/07/10 06:55:38.156283
|
// 2014/07/10 06:55:38.156283
|
||||||
@ -519,6 +546,11 @@ iterRunes:
|
|||||||
p.yeari = i + 1
|
p.yeari = i + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
if unicode.IsLetter(r) {
|
||||||
|
p.moi = i
|
||||||
|
p.stateDate = dateDigitDashAlpha
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case dateDigitColon:
|
case dateDigitColon:
|
||||||
@ -1638,6 +1670,9 @@ iterRunes:
|
|||||||
p.t = &t
|
p.t = &t
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
case dateDigitSt:
|
||||||
|
// 171113 14:14:20
|
||||||
|
return p, nil
|
||||||
|
|
||||||
case dateYearDash:
|
case dateYearDash:
|
||||||
// 2006-01
|
// 2006-01
|
||||||
@ -2002,6 +2037,7 @@ func (p *parser) parse() (time.Time, error) {
|
|||||||
p.format = p.format[p.skip:]
|
p.format = p.format[p.skip:]
|
||||||
p.datestr = p.datestr[p.skip:]
|
p.datestr = p.datestr[p.skip:]
|
||||||
}
|
}
|
||||||
|
|
||||||
//gou.Debugf("parse %q AS %q", p.datestr, string(p.format))
|
//gou.Debugf("parse %q AS %q", p.datestr, string(p.format))
|
||||||
if p.loc == nil {
|
if p.loc == nil {
|
||||||
return time.Parse(string(p.format), p.datestr)
|
return time.Parse(string(p.format), p.datestr)
|
||||||
|
@ -508,6 +508,11 @@ var testParseFormat = []dateTest{
|
|||||||
{in: "2009-15-12T22:15Z", err: true},
|
{in: "2009-15-12T22:15Z", err: true},
|
||||||
{in: "5,000-9,999", 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: "oct 7, 1970", out: "Jan 2, 2006"},
|
||||||
{in: "sept. 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"},
|
{in: "May 05, 2015, 05:05:07", out: "Jan 02, 2006, 15:04:05"},
|
||||||
|
Loading…
Reference in New Issue
Block a user