expand Chinese time format

adapt to the prefix of year, month and day.
This commit is contained in:
Wendell Sun 2021-07-30 13:42:58 +08:00
parent 6b43995a97
commit edefb14d7b
2 changed files with 30 additions and 6 deletions

View File

@ -397,6 +397,9 @@ iterRunes:
} }
case '年': case '年':
// Chinese Year // Chinese Year
p.yearlen = i - 2
p.moi = i + 1
p.setYear()
p.stateDate = dateDigitChineseYear p.stateDate = dateDigitChineseYear
case ',': case ',':
return nil, unknownErr(datestr) return nil, unknownErr(datestr)
@ -709,9 +712,20 @@ iterRunes:
// 2014年04月08日 // 2014年04月08日
// weekday %Y年%m月%e日 %A %I:%M %p // weekday %Y年%m月%e日 %A %I:%M %p
// 2013年07月18日 星期四 10:27 上午 // 2013年07月18日 星期四 10:27 上午
if r == ' ' { switch r {
case '月':
// month
p.molen = i - p.moi - 2
p.dayi = i + 1
p.setMonth()
case '日':
// day
p.daylen = i - p.dayi - 2
p.houri = i + 1
p.setDay()
case ' ':
p.stateDate = dateDigitChineseYearWs p.stateDate = dateDigitChineseYearWs
break break iterRunes
} }
case dateDigitDot: case dateDigitDot:
// This is the 2nd period // This is the 2nd period
@ -1929,13 +1943,19 @@ iterRunes:
return p, nil return p, nil
case dateDigitChineseYear: case dateDigitChineseYear:
// dateDigitChineseYear
// 2014年04月08日 // 2014年04月08日
p.format = []byte("2006年01月02日")
return p, nil return p, nil
case dateDigitChineseYearWs: case dateDigitChineseYearWs:
p.format = []byte("2006年01月02日 15:04:05") index := p.houri
for _, b := range []byte(" 15:04:05") {
if index >= len(p.format) {
break
}
p.format[index] = b
index++
}
// p.format = []byte("2006年01月02日 15:04:05")
return p, nil return p, nil
case dateWeekdayComma: case dateWeekdayComma:

View File

@ -169,7 +169,11 @@ var testInputs = []dateTest{
{in: "3 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日 // Chinese 2014年04月18日
{in: "2014年04月08日", out: "2014-04-08 00:00:00 +0000 UTC"}, {in: "2014年04月08日", out: "2014-04-08 00:00:00 +0000 UTC"},
{in: "2014年4月8日", out: "2014-04-08 00:00:00 +0000 UTC"},
{in: "2014年4月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"}, {in: "2014年04月08日 19:17:22", out: "2014-04-08 19:17:22 +0000 UTC"},
{in: "2014年4月8日 19:17:22", out: "2014-04-08 19:17:22 +0000 UTC"},
{in: "2014年04月8日 19:17:22", out: "2014-04-08 19:17:22 +0000 UTC"},
// mm/dd/yyyy // mm/dd/yyyy
{in: "03/31/2014", out: "2014-03-31 00:00:00 +0000 UTC"}, {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/31/2014", out: "2014-03-31 00:00:00 +0000 UTC"},