feat: add java.sql.Timestamp converters - #1019
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-class converter support for java.sql.Timestamp in fesod-sheet, aligning with the existing temporal converter family and registering the converters in the default loader alongside unit coverage.
Changes:
- Introduces
TimestampDateConverter,TimestampNumberConverter, andTimestampStringConverter. - Registers the new converters in
DefaultConverterLoaderfor read + default write behavior. - Adds
TimestampConverterTestto validate key registration and basic read/write conversions (number/string/date) including 1904 windowing.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| fesod-sheet/src/test/java/org/apache/fesod/sheet/converter/TimestampConverterTest.java | Adds unit coverage for timestamp converters and default loader registration. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/converters/timestamp/TimestampStringConverter.java | Implements Timestamp ↔ STRING conversion using DateUtils formatting/parsing. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/converters/timestamp/TimestampNumberConverter.java | Implements Timestamp ↔ Excel numeric date conversion with 1904 windowing support. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/converters/timestamp/TimestampDateConverter.java | Implements default write conversion to DATE with appropriate cell format. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/converters/DefaultConverterLoader.java | Wires the new timestamp converters into the default converter registry. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @Override | ||
| public WriteCellData<?> convertToExcelData( | ||
| Timestamp value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { | ||
| if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { | ||
| return new WriteCellData<>( | ||
| BigDecimal.valueOf(DateUtil.getExcelDate(value, globalConfiguration.getUse1904windowing()))); | ||
| } else { | ||
| return new WriteCellData<>(BigDecimal.valueOf(DateUtil.getExcelDate( | ||
| value, contentProperty.getDateTimeFormatProperty().getUse1904windowing()))); | ||
| } | ||
| } |
| public WriteCellData<?> convertToExcelData( | ||
| Timestamp value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) | ||
| throws Exception { | ||
| WriteCellData<?> cellData = new WriteCellData<>(value); |
| contentProperty.setDateTimeFormatProperty(dateTimeFormatProperty); | ||
|
|
||
| GlobalConfiguration globalConfiguration = new GlobalConfiguration(); | ||
| globalConfiguration.setLocale(Locale.US); |
There was a problem hiding this comment.
The test still passes even if you remove the 129 line or replace it with Locale.JAPANESE or new Locale("th", "TH").
To actually check the locale, consider using a different format.
For example, "dd MMMM yyyy HH:mm:ss"="01 January 2020 01:01:01",
which now fails for Locale.GERMAN etc.
Purpose of the pull request
Related: #1017
Add first-class converter support for
java.sql.Timestamp, following the existing temporal converter patterns in Apache Fesod.What's changed?
TimestampDateConverteras the default write converter forTimestamp.TimestampNumberConverterfor Excel numeric date conversion, includinguse1904windowinghandling.TimestampStringConverterusing the existingDateUtilsparsing/formatting behavior and@DateTimeFormatsupport.DefaultConverterLoaderusing the same read/write structure asLocalDateTime.TimestampConverterTestcovering:The change is intentionally scoped to
java.sql.Timestampand does not modify the converter lookup mechanism or other converter types.Verification:
./mvnw spotless:check./mvnw -pl fesod-sheet -Dmaven.test.skip=false -Dtest=TimestampConverterTest,ConverterTest,ConverterDataTest,CustomConverterTest testChecklist