mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
commit
b07ab88828
@ -108,6 +108,15 @@ var examples = []string{
|
||||
"2014/4/02 03:00:51",
|
||||
"2012/03/19 10:11:59",
|
||||
"2012/03/19 10:11:59.3186369",
|
||||
// yyyy:mm:dd
|
||||
"2014:3:31",
|
||||
"2014:03:31",
|
||||
"2014:4:8 22:05",
|
||||
"2014:04:08 22:05",
|
||||
"2014:04:2 03:00:51",
|
||||
"2014:4:02 03:00:51",
|
||||
"2012:03:19 10:11:59",
|
||||
"2012:03:19 10:11:59.3186369",
|
||||
// Chinese
|
||||
"2014年04月08日",
|
||||
// yyyy-mm-ddThh
|
||||
|
84
parseany.go
84
parseany.go
@ -66,24 +66,31 @@ const (
|
||||
dateDigitDot // 10
|
||||
dateDigitDotDot
|
||||
dateDigitSlash
|
||||
dateDigitColon
|
||||
dateDigitChineseYear
|
||||
dateDigitChineseYearWs
|
||||
dateDigitWs // 15
|
||||
dateDigitChineseYearWs // 15
|
||||
dateDigitWs
|
||||
dateDigitWsMoYear
|
||||
dateDigitWsMolong
|
||||
dateAlpha
|
||||
dateAlphaWs
|
||||
dateAlphaWsDigit // 20
|
||||
dateAlphaWs // 20
|
||||
dateAlphaWsDigit
|
||||
dateAlphaWsDigitMore
|
||||
dateAlphaWsDigitMoreWs
|
||||
dateAlphaWsDigitMoreWsYear
|
||||
dateAlphaWs // 20
|
||||
dateAlphaWsDigit
|
||||
dateAlphaWsDigitMore
|
||||
dateAlphaWsDigitMoreWs
|
||||
dateAlphaWsDigitMoreWsYear
|
||||
dateAlphaWsMonth // 25
|
||||
dateAlphaWsDigitYearmaybe
|
||||
dateAlphaWsMonth
|
||||
dateAlphaWsMonthMore
|
||||
dateAlphaWsMonthSuffix
|
||||
dateAlphaWsMore
|
||||
dateAlphaWsAtTime
|
||||
dateAlphaWsAtTime // 30
|
||||
dateAlphaWsAlpha
|
||||
dateAlphaWsAlphaYearmaybe
|
||||
dateAlphaPeriodWsDigit
|
||||
dateWeekdayComma
|
||||
dateWeekdayAbbrevComma
|
||||
@ -289,6 +296,25 @@ iterRunes:
|
||||
}
|
||||
}
|
||||
|
||||
case ':':
|
||||
// 03/31/2005
|
||||
// 2014/02/24
|
||||
p.stateDate = dateDigitColon
|
||||
if i == 4 {
|
||||
p.yearlen = i
|
||||
p.moi = i + 1
|
||||
p.setYear()
|
||||
} else {
|
||||
p.ambiguousMD = true
|
||||
if p.preferMonthFirst {
|
||||
if p.molen == 0 {
|
||||
p.molen = i
|
||||
p.setMonth()
|
||||
p.dayi = i + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case '.':
|
||||
// 3.31.2014
|
||||
// 08.21.71
|
||||
@ -466,6 +492,45 @@ iterRunes:
|
||||
}
|
||||
}
|
||||
|
||||
case dateDigitColon:
|
||||
// 2014:07:10 06:55:38.156283
|
||||
// 03:19:2012 10:11:59
|
||||
// 04:2:2014 03:00:37
|
||||
// 3:1:2012 10:11:59
|
||||
// 4:8:2014 22:05
|
||||
// 3:1:2014
|
||||
// 10:13:2014
|
||||
// 01:02:2006
|
||||
// 1:2:06
|
||||
|
||||
switch r {
|
||||
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 ':':
|
||||
if p.yearlen > 0 {
|
||||
// 2014:07:10 06:55:38.156283
|
||||
if p.molen == 0 {
|
||||
p.molen = i - p.moi
|
||||
p.setMonth()
|
||||
p.dayi = i + 1
|
||||
}
|
||||
} else if p.preferMonthFirst {
|
||||
if p.daylen == 0 {
|
||||
p.daylen = i - p.dayi
|
||||
p.setDay()
|
||||
p.yeari = i + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case dateDigitWs:
|
||||
// 18 January 2018
|
||||
// 8 January 2018
|
||||
@ -1664,6 +1729,13 @@ iterRunes:
|
||||
// 2014/10/13
|
||||
return p, nil
|
||||
|
||||
case dateDigitColon:
|
||||
// 3:1:2014
|
||||
// 10:13:2014
|
||||
// 01:02:2006
|
||||
// 2014:10:13
|
||||
return p, nil
|
||||
|
||||
case dateDigitChineseYear:
|
||||
// dateDigitChineseYear
|
||||
// 2014年04月08日
|
||||
|
@ -184,6 +184,16 @@ var testInputs = []dateTest{
|
||||
{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
|
||||
{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"},
|
||||
@ -311,6 +321,10 @@ var testInputs = []dateTest{
|
||||
// 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+00:00
|
||||
{in: "2012:08:03 18:31:59+00:00", out: "2012-08-03 18:31:59 +0000 UTC"},
|
||||
// dd:mm:yyyy hh:mm:ss+00:00
|
||||
{in: "08:03:2012 18:31:59+00:00", out: "2012-08-03 18:31:59 +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
|
||||
|
Loading…
Reference in New Issue
Block a user