Repository navigation
feat: add java.sql.Timestamp converters - #1019
SyedIshmumAhnaf wants to merge 3 commits into
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.
|
Updated the test to use a locale-sensitive MMMM format with Locale.US, including January for both parsing and formatting. Thanks for catching that. |
|
The newly added files in this PR are implemented from scratch and are not derived from Alibaba's EasyExcel. Therefore, no EasyExcel-related license header is required for these files. Please refer to: https://github.com/apache/fesod/blob/main/fesod-sheet/src/main/java/org/apache/fesod/sheet/FesodSheet.java |
|
Please resolve the conflicts from |
|
Hi @SyedIshmumAhnaf — checking in on this one. nkuprins asked for a rebase a month ago and it has been quiet since, so I wanted to ask before assuming anything. Are you still planning to carry it forward? If you don't have the bandwidth for it right now, I'd be happy to pick it up — I'd rebase the three converters on current main, keep the implementation and tests, adjust to the current testkit conventions where needed, and reference this PR and #1017 in the description so your work stays credited. Either way, just let me know. |
|
Hi @Mikkey-f, sorry for being awol. I've been dealing with some things lately which has kept me off from GitHub and contributing. I hope to get back soon to the picture however I would be more than happy for you to continue working on this. Primarily because I am still working some things out and not sure of the timeline by when I might get my hands on this. If you have any questions regarding the existing work, please feel free to tag me and I'll try my very best to respond at the earliest. |
|
Hi @SyedIshmumAhnaf — thanks for the kind words and for handing this over, and no worries at all; these things take the time they take. I'll carry this forward from here. So you know what to expect: your commits will come along with your authorship preserved, brought up to date with Nothing needed from you in the meantime — take care of things on your side first. |
|
Carried forward as #1220 — your commits are preserved with your authorship, plus one adaptation commit to bring them up to date with |
Carry-forward of apache#1019 (original implementation by Syed Ishmum Ahnaf): - Resolve the 1904 windowing flag through the shared DateUtils.isDate1904 helper, like the rest of the date converter family. Reading DateTimeFormatProperty#getUse1904windowing() directly broke on the null DEFAULT preserved by apache#1042 and threw a NullPointerException whenever @DateTimeFormat was present without an explicit use1904windowing value. - Drop the EasyExcel derived license header from the four new files; they are written from scratch, so the plain ASF header applies. - Align with current conventions: Class<?> supportJavaTypeKey, single-line javadoc, and tests moved to the mirrored converters.timestamp package with qualified assertions, the thread-local cache teardown used by the sibling suites, a loader family test and an XLSX/XLS/CSV round trip.
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