Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand Chinese time format #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions parseany.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ iterRunes:
}
case '年':
// Chinese Year
p.yearlen = i - 2
p.moi = i + 1
p.setYear()
p.stateDate = dateDigitChineseYear
case ',':
return nil, unknownErr(datestr)
Expand Down Expand Up @@ -709,9 +712,20 @@ iterRunes:
// 2014年04月08日
// weekday %Y年%m月%e日 %A %I:%M %p
// 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
break
break iterRunes
}
case dateDigitDot:
// This is the 2nd period
Expand Down Expand Up @@ -1929,13 +1943,19 @@ iterRunes:
return p, nil

case dateDigitChineseYear:
// dateDigitChineseYear
// 2014年04月08日
p.format = []byte("2006年01月02日")
// 2014年04月08日
return p, nil

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

case dateWeekdayComma:
Expand Down
4 changes: 4 additions & 0 deletions parseany_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ var testInputs = []dateTest{
{in: "3 February 2013", out: "2013-02-03 00:00:00 +0000 UTC"},
// Chinese 2014年04月18日
{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年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
{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"},
Expand Down