mirror of
https://github.com/araddon/dateparse.git
synced 2025-01-19 11:16:12 +08:00
Implement support for yyyy mon dd (2013 May 02)
Incorporate PR https://github.com/araddon/dateparse/pull/142 from https://github.com/dferstay to fix https://github.com/araddon/dateparse/issues/141
This commit is contained in:
parent
301ffeee02
commit
18938f16ae
56
parseany.go
56
parseany.go
@ -95,6 +95,8 @@ const (
|
||||
dateAlphaSlashDigitSlash
|
||||
dateWeekdayComma
|
||||
dateWeekdayAbbrevComma
|
||||
dateYearWs
|
||||
dateYearWsMonthWs
|
||||
)
|
||||
const (
|
||||
// Time state
|
||||
@ -426,7 +428,15 @@ iterRunes:
|
||||
// 02 Jan 2018 23:59:34
|
||||
// 12 Feb 2006, 19:17
|
||||
// 12 Feb 2006, 19:17:22
|
||||
if i == 6 {
|
||||
// 2013 Jan 06 15:04:05
|
||||
if i == 4 {
|
||||
p.yearlen = i
|
||||
p.moi = i + 1
|
||||
if !p.setYear() {
|
||||
return p, unknownErr(datestr)
|
||||
}
|
||||
p.stateDate = dateYearWs
|
||||
} else if i == 6 {
|
||||
p.stateDate = dateDigitSt
|
||||
} else {
|
||||
p.stateDate = dateDigitWs
|
||||
@ -795,6 +805,45 @@ iterRunes:
|
||||
}
|
||||
break iterRunes
|
||||
}
|
||||
|
||||
case dateYearWs:
|
||||
// 2013 Jan 06 15:04:05
|
||||
// 2013 January 06 15:04:05
|
||||
if r == ' ' {
|
||||
p.molen = i - p.moi
|
||||
// Must be a valid short or long month
|
||||
if p.molen == 3 {
|
||||
p.set(p.moi, "Jan")
|
||||
p.dayi = i + 1
|
||||
p.stateDate = dateYearWsMonthWs
|
||||
} else {
|
||||
possibleFullMonth := strings.ToLower(p.datestr[p.moi:(p.moi + p.molen)])
|
||||
if i > 3 && isMonthFull(possibleFullMonth) {
|
||||
p.fullMonth = possibleFullMonth
|
||||
p.dayi = i + 1
|
||||
p.stateDate = dateYearWsMonthWs
|
||||
} else {
|
||||
return p, unknownErr(datestr)
|
||||
}
|
||||
}
|
||||
}
|
||||
case dateYearWsMonthWs:
|
||||
// 2013 Jan 06 15:04:05
|
||||
// 2013 January 06 15:04:05
|
||||
switch r {
|
||||
case ',':
|
||||
p.daylen = i - p.dayi
|
||||
p.setDay()
|
||||
i++
|
||||
p.stateTime = timeStart
|
||||
break iterRunes
|
||||
case ' ':
|
||||
p.daylen = i - p.dayi
|
||||
p.setDay()
|
||||
p.stateTime = timeStart
|
||||
break iterRunes
|
||||
}
|
||||
|
||||
case dateDigitChineseYear:
|
||||
// dateDigitChineseYear
|
||||
// 2014年04月08日
|
||||
@ -2142,6 +2191,11 @@ iterRunes:
|
||||
// Mon, 02 Jan 2006 15:04:05 MST
|
||||
return p, nil
|
||||
|
||||
case dateYearWsMonthWs:
|
||||
// 2013 May 02 11:37:55
|
||||
// 2013 December 02 11:37:55
|
||||
return p, nil
|
||||
|
||||
}
|
||||
|
||||
return p, unknownErr(datestr)
|
||||
|
@ -404,6 +404,10 @@ var testInputs = []dateTest{
|
||||
{in: "2018-09-30 21:09:13.123 AMT", out: "2018-09-30 21:09:13.123 +0000 UTC", zname: "AMT"},
|
||||
{in: "2018-09-30 08:09:13.123 am AMT", out: "2018-09-30 08:09:13.123 +0000 UTC", zname: "AMT"},
|
||||
{in: "2018-09-30 08:09:13.123am AMT", out: "2018-09-30 08:09:13.123 +0000 UTC", zname: "AMT"},
|
||||
/// yyyy mmm dd https://github.com/araddon/dateparse/issues/141
|
||||
{in: "2013 May 02 11:37:55", out: "2013-05-02 11:37:55 +0000 UTC"},
|
||||
{in: "2013 June 02 11:37:55", out: "2013-06-02 11:37:55 +0000 UTC"},
|
||||
{in: "2013 December 02 11:37:55", out: "2013-12-02 11:37:55 +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
|
||||
|
Loading…
Reference in New Issue
Block a user