Repository navigation
fix(core): parse unambiguous day-first dates (31/12/2026) instead of leaving them as text - #1132
saadkhantareen wants to merge 1 commit into
Conversation
…leaving them as text
|
Thanks for picking up #1071. I checked this against #447 (regional formats), which rewrites the same branch of
In Excel the order comes from the regional format, and a date that doesn't fit it stays text (for example this thread, where |
|
@quantmind-br Thank you for the careful check against #447 — you are right on both points. The mixed-order column is the decisive one: with a fallback, I am closing this PR in favour of #447. Happy to help there instead — if a reviewer or tester for the regional formats would be useful (in particular the date-parsing cases from #1071), please let me know and I will pick it up. |
|
Thanks, that's generous. A review or a test pass on #447 would help, since it hasn't had one yet. For the #1071 cases: build |
Fixes #1071
Summary
Typed and pasted dates were only parsed month-first (the en-US order), so an unambiguous day-first date such as
31/12/2026stayed plain text — even though the first field cannot be a month, and the workbook's number-format inference (OpenXML/ECMA-376) likewise only produces a date when the value is a valid calendar date.Day-first is now tried as a fallback: only when the month-first interpretation fails
valid_ymdvalidation. Ambiguous dates keep the existing month-first reading (e.g.8/6/2026still parses as August 6), and strings that are not valid calendar dates in either order (e.g.31/4/2026) still stay text.Changes
crates/core/src/parse.rs— after the existing month-first attempts inparse_date_like, try the same layouts with the first two fields swapped, each result still checked byvalid_ymd; covered layouts:D/M/YYYY,D/M/YY, andD/Mwith the session year.unambiguous_day_first_datescovering31/12/2026,13/6/2026, the leap day29/2/2024, and25/12(session year), plus the guard cases: impossible dates stay text and ambiguous dates keep the month-first reading.Tests
cargo test -p gridcraft-core— 22 passed, 0 failed, including the new test.cargo fmt -p gridcraft-core -- --check— clean.