adds support for DD.MM.YYYY

This commit is contained in:
Kamal Galrani 2019-09-12 14:21:15 +05:30
parent 9fa48d1ba7
commit 21e4c6c573

View File

@ -299,6 +299,20 @@ iterRunes:
p.set(0, "2006") p.set(0, "2006")
} else { } else {
p.stateDate = dateDigitDash p.stateDate = dateDigitDash
p.ambiguousMD = true
if p.preferMonthFirst {
if p.molen == 0 {
p.molen = i
p.setMonth()
p.dayi = i + 1
}
} else {
if p.daylen == 0 {
p.daylen = i
p.setDay()
p.moi = i + 1
}
}
} }
case '/': case '/':
// 03/31/2005 // 03/31/2005
@ -336,10 +350,19 @@ iterRunes:
p.setYear() p.setYear()
} else { } else {
p.ambiguousMD = true p.ambiguousMD = true
p.moi = 0 if p.preferMonthFirst {
p.molen = i if p.molen == 0 {
p.setMonth() p.molen = i
p.dayi = i + 1 p.setMonth()
p.dayi = i + 1
}
} else {
if p.daylen == 0 {
p.daylen = i
p.setDay()
p.moi = i + 1
}
}
} }
case ' ': case ' ':
@ -416,8 +439,40 @@ iterRunes:
p.stateDate = dateDigitDashAlpha p.stateDate = dateDigitDashAlpha
p.moi = i p.moi = i
} else { } else {
return nil, unknownErr(datestr) 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
}
} else {
if p.molen == 0 {
p.molen = i - p.moi
p.setMonth()
p.yeari = i + 1
}
}
}
}
case dateDigitDashAlpha: case dateDigitDashAlpha:
// 13-Feb-03 // 13-Feb-03
// 28-Feb-03 // 28-Feb-03
@ -967,6 +1022,7 @@ iterRunes:
break iterRunes break iterRunes
} }
} }
p.coalesceDate(i) p.coalesceDate(i)
if p.stateTime == timeStart { if p.stateTime == timeStart {
// increment first one, since the i++ occurs at end of loop // increment first one, since the i++ occurs at end of loop
@ -1692,6 +1748,9 @@ iterRunes:
case dateAlphaWsAlphaYearmaybe: case dateAlphaWsAlphaYearmaybe:
return p, nil return p, nil
case dateDigitDash:
return p, nil
case dateDigitSlash: case dateDigitSlash:
// 3/1/2014 // 3/1/2014
// 10/13/2014 // 10/13/2014