pjfanning opened a new pull request, #1593: URL: https://github.com/apache/poi/pull/1593
Two places where `DataFormatter` disagrees with Excel for single-section date/time formats. Both were found while checking #1592 against Excel with `=TEXT(value, format)` in a 1900-date-system workbook; this PR is independent of #1592 and touches different files. | Format | Value | Excel | Trunk | This PR | | --- | --- | --- | --- | --- | | `hh:mmm` | 2025-08-04 22:21:15 | `22:Aug` | `22:021` | `22:Aug` | | `hh:mmmmm` | 2025-08-04 22:21:15 | `22:A` | `22:00021` | `22:A` | | `mmm:ss` | 2025-08-04 22:21:15 | `Aug:15` | `021:15` | `Aug:15` | | `mmmmm:ss` | 2025-08-04 22:21:15 | `A:15` | `00021:15` | `A:15` | | `h:mm` | 1:59:59.7 | `2:00` | `1:59` | `2:00` | | `[h]:mm` | 1:59:59.7 | `2:00` | `1:59` | `2:00` | ## Changes - **Month names next to a time (`DataFormatter`).** Three or more `m` are always the month name or its initial. Only `m` and `mm` can be the minutes straight after the hours or before the seconds. - **Rounding to the second (`ExcelStyleDateFormatter`).** A value is rounded to the nearest second whenever the format shows a time (hours, minutes or seconds, elapsed or not) and no fraction of a second. Trunk did this only when the format showed seconds. ## Unchanged - Hours and minutes are not rounded up otherwise: `h:mm` and `[h]:mm` on 1:30:45 stay `1:30`, `[h]` on 1.6 hours stays `1`. Excel agrees. - Formats with a fraction of a second (`h:mm:ss.0`) and formats without a time (`yyyy-mm-dd`) are not rounded. ## Behaviour change to be aware of A time within half a second of the next minute now shows that minute in formats without seconds, and can roll over to the next hour or day (`yyyy-mm-dd hh:mm` on 23:59:59.7 shows `00:00` of the next day). The rollover case follows from the rule above and from what `hh:mm:ss` already does; it was not checked in Excel separately. ## Testing Run locally on Java 17: `TestDataFormatter`, `TestExcelStyleDateFormatter`, `TestHSSFDataFormatter`, `TestDateUtil`, `TestText` and `org.apache.poi.ss.format.*` in poi, and `org.apache.poi.ss.tests.format.*` and `TestXSSFDataFormat` in poi-ooxml. All pass. The rest of the suite is left to CI. 🤖 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]
