xlstream-eval: adjust DATE() year 0-1899, guard negative and overflow#187
Merged
Conversation
9a1c94a to
7c5ee9c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #144
Problem
DATE(year, month, day)passed the year argument directly toExcelDate::from_ymdwithout Excel's year-adjustment rule. Years 0-1899 produced massive negative serial numbers instead of the correct 1900-adjusted dates. Negative years and years producing serials past 9999-12-31 were also not guarded.Fix
0 <= year < 1900(Excel's documented behavior).#NUM!for negative years (negative serials).#NUM!when the resulting serial exceedsEXCEL_MAX_DATE_SERIAL(2,958,465 = 9999-12-31).Issue description correction
The issue lists
DATE(24,6,15)→ 45458 (2024-06-15). Excel actually returns 8933 (1924-06-15) because the rule is strictlyyear + 1900, not century-guessing. The fix matches Excel's actual behavior, not the issue's third expected value.Changes
crates/xlstream-core/src/lib.rs: addEXCEL_MAX_DATE_SERIALconstant (2,958,465).crates/xlstream-eval/src/builtins/date.rs: year 0-1899 adjustment, negative year#NUM!guard, overflow#NUM!guard.#NUM!errors, and fractional years.Test plan
cargo test -p xlstream-evalpasses (no regressions)make checkpassesCloses #144