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

fix problem with date format 02.01.2006 #133

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
26 changes: 21 additions & 5 deletions parseany.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,20 @@ iterRunes:
p.setYear()
} else {
p.ambiguousMD = true
p.moi = 0
p.molen = i
p.setMonth()
p.dayi = i + 1
if p.preferMonthFirst {
if p.molen == 0 {
// 03.31.2005
p.molen = i
p.setMonth()
p.dayi = i + 1
}
} else {
if p.daylen == 0 {
p.daylen = i
p.setDay()
p.moi = i + 1
}
}
}

case ' ':
Expand Down Expand Up @@ -726,9 +736,15 @@ iterRunes:
p.yeari = i + 1
p.setDay()
p.stateDate = dateDigitDotDot
} else if p.dayi == 0 && p.yearlen == 0 {
// 23.07.2002
p.molen = i - p.moi
p.yeari = i + 1
p.setMonth()
p.stateDate = dateDigitDotDot
} else {
// 2018.09.30
//p.molen = 2
// p.molen = 2
p.molen = i - p.moi
p.dayi = i + 1
p.setMonth()
Expand Down
5 changes: 4 additions & 1 deletion parseany_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ var testInputs = []dateTest{
{in: "03.31.2014", out: "2014-03-31 00:00:00 +0000 UTC"},
// mm.dd.yy
{in: "08.21.71", out: "1971-08-21 00:00:00 +0000 UTC"},
// dd.mm.yyyy
{in: "23.07.1938", out: "1938-07-23 00:00:00 +0000 UTC"},
{in: "23/07/1938", out: "1938-07-23 00:00:00 +0000 UTC"},
// yyyymmdd and similar
{in: "2014", out: "2014-01-01 00:00:00 +0000 UTC"},
{in: "20140601", out: "2014-06-01 00:00:00 +0000 UTC"},
Expand Down Expand Up @@ -450,7 +453,7 @@ func TestParse(t *testing.T) {
panic("whoops")
}
} else {
ts = MustParse(th.in)
ts = MustParse(th.in, RetryAmbiguousDateWithSwap(true))
got := fmt.Sprintf("%v", ts.In(time.UTC))
assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in)
if th.out != got {
Expand Down