pjfanning opened a new pull request, #1405:
URL: https://github.com/apache/poi/pull/1405

   When a date or time format shows seconds but no fractions of a second, Excel 
rounds to the nearest second. `DataFormatter` truncated the seconds instead.
   
   The Excel evidence is `DateFormatNumberTests.xlsx!Tests!A7`: Excel 
calculated `TEXT(1.0032134017094, "yyyy-mm-dd hh:mm:ss")` as `1904-01-02 
00:04:38`, for a time of 00:04:37.638. This was the last entry in 
`TestDataFormatterAgainstExcel`'s `KNOWN_FAILURES`, and this PR removes it.
   
   ## Changes
   
   - **`ExcelStyleDateFormatter`:** when the pattern shows seconds (`s`, `[s]` 
or `[ss]`) and no fractions of a second, it rounds both the `Date` and the 
elapsed-time value used for `[h]`, `[m]` and `[s]` to the nearest second. 
Rounding the elapsed value as well keeps `[h]` consistent with `mm:ss`, e.g. 
`27:18:09` rather than `27:18:08`. Patterns with fractions of a second 
(`ss.000` etc.) are unchanged.
   - **`CellDateFormatter`** already rounded the seconds for a `Number` when 
the format has no fractions of a second. It now does the same for a `Date`. 
`DataFormatter` passes a `Date` to `CellFormat` for date formats with several 
sections, which is why the concurrency test below still showed truncated 
seconds.
   
   ## Test expectations corrected
   
   These tests asserted truncated seconds, which Excel does not show:
   
   | Test | Value | Exact time | Was | Now (Excel) |
   |---|---|---|---|---|
   | `testElapsedTime` (`[h]:mm:ss`, `[hh]:mm:ss`) | 1.1376 | 27:18:08.64 | 
`27:18:08` | `27:18:09` |
   | `testBug60031` | 42747.412892397523 | 09:54:33.903 | `09:54:33` | 
`09:54:34` |
   | `testDateFormattingWithLocales` (de, zh, ga) | 42747.412892397523 | 
09:54:33.903 | `09:54:33` | `09:54:34` |
   | `doFormatTestSequential` / `doFormatTestConcurrent` | 43551.50990171296 | 
12:14:15.508 | `12:14:15 PM` | `12:14:16 PM` |
   
   Formats without seconds (e.g. `h:mm`) are not changed by this PR. There's no 
Excel-calculated data for how they behave near a minute boundary.
   
   ## Tests
   
   Passing locally:
   - `poi`: `TestDataFormatter`, `TestFractionFormat`, `TestDateUtil`, 
`TestExcelStyleDateFormatter`, `TestHSSFDataFormat`, `TestHSSFDataFormatter`, 
`TestHSSFDateUtil`, `TestBugs`, `TestTime`, `org.apache.poi.ss.format.*`, 
`org.apache.poi.hssf.extractor.*`
   - `poi-ooxml`: `TestDataFormatterAgainstExcel` (544 of 569 now match Excel), 
`TestXSSFDataFormat`, `TestXSSFCell`, `TestXSSFWorkbook`, `TestXSSFWithLocale`, 
`TestSXSSFWorkbook`, `TestXSSFReader`, `TestXSSFBReader`, 
`TestXSSFBSheetParser`, `org.apache.poi.xssf.extractor.*`, 
`org.apache.poi.ss.tests.format.*`
   
   `TestXSSFBugs` passes apart from `stackoverflow23114397`, the font-metric 
width check that also fails locally on trunk.
   
   🤖 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]

Reply via email to