pjfanning opened a new pull request, #1290: URL: https://github.com/apache/poi/pull/1290
`DateUtil.getJavaDate` returns `null` for a negative serial and several date functions dereferenced it; a serial beyond the int range reached `MathUtil.safeDoubleToInt`. Excel's dates run from serial 0 (`1900-01-00`) to 2958465 (`9999-12-31`), and its date functions report anything outside that — argument or result — as `#NUM!`. | Formula | Before | After (Excel) | |---|---|---| | `=DAYS360(0,0)` | `NullPointerException: date must not be null` | `0` | | `=EOMONTH(-1,-1)`, `=NETWORKDAYS(-1,-1)`, `=WORKDAY(-1,-1)`, `=WORKDAY.INTL(-1,-1)` | `NullPointerException` | `#NUM!` | | `=EOMONTH(1E10,0)`, `=EDATE(1E10,0)`, `=NETWORKDAYS(1,1E10)`, `=WORKDAY(1E10,1)`, `=WEEKDAY(1E10)`, `=YEAR(3E9)`, `=YEARFRAC(1E10,1)` | `IllegalArgumentException` | `#NUM!` | | `=DAY(2958466)`, `=WEEKDAY(2958466)`, `=DAYS360(2958466,1)`, `=NETWORKDAYS(1,2958466)` | a year-10000 date | `#NUM!` | | `=EOMONTH(2958465,1)`, `=EDATE(2958465,1)`, `=WORKDAY(2958465,1)` | `2958496` etc. | `#NUM!` (result beyond the last date) | | `=YEARFRAC(-1,1)` | `0.00278` | `#NUM!` | | `=EDATE(-1,0)`, `=DAYS(-1,0)` | `#VALUE!` | `#NUM!` | | `=NETWORKDAYS(NA(),1)` | `#VALUE!` | `#N/A` | - New `DateUtil.MAX_EXCEL_DATE_SERIAL` (`@since 6.0.0`) = 2958465, the 1900-system serial of 9999-12-31. - The ATP `ArgumentsEvaluator.evaluateDateArg` (NETWORKDAYS, WORKDAY, WORKDAY.INTL), `YEARFRAC`, `EDATE`, `EOMONTH`, `WEEKDAY`, the calendar-field functions (DAY/MONTH/YEAR/HOUR/MINUTE/SECOND) and `DAYS`/`DAYS360` check the range; `EDATE`, `EOMONTH`, `WORKDAY` and `WORKDAY.INTL` also check their result. - `DAYS360` no longer round-trips through `DateUtil.getExcelDate(LocalDate)`, which turned day 0 into the `-1` error marker and that into the NPE. - `NETWORKDAYS`/`WORKDAY`/`WORKDAY.INTL` return the `EvaluationException`'s own error instead of mapping every failure to `#VALUE!` (so `#NUM!` and a propagated `#N/A` come through; a non-date string is still `#VALUE!`). One existing expectation changes: `TestEDate` asserted `EDATE(0,-2)` = `-1.0` with a `/* BAD_DATE! */` comment; it now asserts `#NUM!`. Overlaps with #1288 on a couple of lines in `EOMonth`, `EDate` and `CalendarFieldFunction`; whichever merges second gets a trivial rebase. Tests: new `TestDateSerialRange`; `org.apache.poi.ss.formula.*` and `TestDateUtil` pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
