pjfanning opened a new pull request, #1296: URL: https://github.com/apache/poi/pull/1296
Found while checking the remaining `MathUtil.safeDoubleToInt` callers after #1288. `DateUtil.isValidExcelDate` only rejected negative serials, so a date-formatted cell holding anything ≥ 2³¹ reached the int conversion in `DateUtil.getJavaCalendar`. Excel's dates end at serial 2958465 (9999-12-31), and it displays a date-formatted cell outside the range as `########`. | | Before | After | |---|---|---| | `DataFormatter.formatCellValue`, `m/d/yyyy` cell = `1E10` | `IllegalArgumentException: Value out of range: 1.0E10` | `10000000000` | | `cell.getDateCellValue()`, value `1E10` | `IllegalArgumentException` | `null` (as for a negative serial) | | `DateUtil.getLocalDateTime(1E10)` | `+3862607-01-01T17:34` (`BigDecimal.intValue` truncation) | `null` | | `DateUtil.getLocalDateTime(1E308)` | `1899-12-31T00:00` | `null` | | `DataFormatter`, `yyyy-mm-dd` cell = `2958466` | `10000-01-01` | `2958466` | | `DataFormatter`, `yyyy-mm-dd` cell = `-1` | `1970-01-01 00:59:59` (raw double as epoch ms) | `-1` | | `DataFormatter`, `[h]:mm:ss` cell = `-1` | `∞:59:59` | `-1` | | `formatRawCellContents(-1, "mm/dd/yyyy")` | `-1.0` | `-1` | - `isValidExcelDate` also requires the serial to be below `MAX_EXCEL_DATE_SERIAL + 1` (the constant from #1290), so `getJavaDate`/`getJavaCalendar`/`getLocalDateTime` return `null` for it and `isCellDateFormatted` is false. The 1904 system's last day is 1462 lower; the check is deliberately the lenient 1900 bound since the method has no windowing parameter. - `DataFormatter.getFormat` returns the General number format for a date pattern with an invalid value, before the format cache. That fixes two things at once: the raw double no longer goes through the date `Format`, and a number format built from a date pattern is no longer cached under that pattern (previously, formatting an invalid value first meant later *valid* dates with the same pattern got the wrong format). The `E+` fix-up in `formatRawCellContents` also applies to the General fallback, so `1E19` renders as `1E+19` on both paths. - The CSV emulation keeps its 255 `#`s for such values (existing `testInvalidDate`; its non-CSV expectation changes from `-1.0` to `-1`). Tests: `TestDateUtil.testDateSerialRange`, `TestDataFormatter.testDateFormatWithValueOutsideExcelsDateRange`; `org.apache.poi.ss.usermodel.*`, `ss.format.*`, `ss.formula.*`, `TestHSSFDataFormatter` and the XSSF cell/formatter/date tests 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]
