Skip to content

feat: add java.sql.Timestamp converters - #1019

Open
SyedIshmumAhnaf wants to merge 2 commits into
apache:mainfrom
SyedIshmumAhnaf:feat/timestamp-converters
Open

feat: add java.sql.Timestamp converters#1019
SyedIshmumAhnaf wants to merge 2 commits into
apache:mainfrom
SyedIshmumAhnaf:feat/timestamp-converters

Conversation

@SyedIshmumAhnaf

Copy link
Copy Markdown

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?

  • Added TimestampDateConverter as the default write converter for Timestamp.
  • Added TimestampNumberConverter for Excel numeric date conversion, including use1904windowing handling.
  • Added TimestampStringConverter using the existing DateUtils parsing/formatting behavior and @DateTimeFormat support.
  • Registered the new converters in DefaultConverterLoader using the same read/write structure as LocalDateTime.
  • Added TimestampConverterTest covering:
    • converter support keys
    • number read/write behavior
    • 1904 date windowing
    • string parsing/formatting
    • custom date-time format handling
    • date write behavior
    • default converter registration

The change is intentionally scoped to java.sql.Timestamp and 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 test
    • 68 tests passed
  • CI-equivalent module build with tests enabled passed successfully.

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

@delei delei added the PR: first-time contributor first-time contributor label Aug 18, 2026
@delei
delei requested a lite review from Copilot August 18, 2026 00:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and TimestampStringConverter.
  • Registers the new converters in DefaultConverterLoader for read + default write behavior.
  • Adds TimestampConverterTest to 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 TimestampSTRING 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.

Comment on lines +69 to +79
@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);

@nkuprins nkuprins Aug 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: first-time contributor first-time contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants