feat: support Instant string conversion - #1089
Conversation
9077a24 to
87ce5b2
Compare
|
CI on JDK 8/11 exposed a runtime compatibility difference: |
87ce5b2 to
3b7ae8f
Compare
| @Override | ||
| public Instant convertToJavaData( | ||
| ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { | ||
| return OffsetDateTime.parse(cellData.getStringValue()).toInstant(); | ||
| } |
There was a problem hiding this comment.
The current implementation of InstantStringConverter has a semantic inconsistency between read and write behavior.
convertToJavaData(...): usesOffsetDateTime.parse(...).toInstant(), which accepts any offset (e.g.,+08:00) and normalizes the value toUTC.convertToExcelData(): always outputsInstant.toString(), which is strictlyUTC.
This means that an Excel value like "2026-09-13T12:12:12+08:00" will be read as "2026-09-13T04:12:12Z", and writing it back will produce a different string. The round‑trip behavior is not symmetric.
Since Instant represents an absolute UTC timestamp, the converter should enforce that the input string is already in UTC. Otherwise the converter silently changes the timestamp.
I suggest adding a validation step in convertToJavaData to reject non‑UTC offsets. This keeps the read/write semantics consistent and avoids unexpected timezone normalization.
There was a problem hiding this comment.
Updated. The read path now parses the offset explicitly and rejects any non-zero offset with DateTimeParseException; Z and +00:00 remain valid UTC inputs, and writes stay canonical Z. I added a regression test for rejecting +08:00. The focused tests, Spotless, and the full package run all pass (924 tests) on commit f0af0eb.
There was a problem hiding this comment.
Suggest using getOffset().equals(ZoneOffset.UTC) ensures that the input is truly UTC (Z or +00:00) and improves readability.
Purpose of the pull request
Related: #1017
Add JDK 8-compatible support for lossless conversion between
java.time.Instantand UTC ISO-8601 Excel string cells.What's changed?
InstantStringConverterusingOffsetDateTimefor UTC-only reads andInstant.toString()for canonical writes.Verification
mvn clean package -B -Dmaven.test.skip=false -pl fesod-common,fesod-shaded,fesod-sheetmvn -pl fesod-sheet -DskipTests spotless:checkResults after syncing current
mainon JDK 21: 924 tests, 0 failures, 0 errors, 0 skipped. The generated Surefire reports include 7 passingInstantStringConverterTestcases and 5 passingDefaultConverterLoaderTestcases.Checklist