Skip to content

feat: add java.time.LocalTime converters - #1032

Merged
delei merged 7 commits into
apache:mainfrom
leehaut:hotfix/lance-common-2
Aug 24, 2026
Merged

feat: add java.time.LocalTime converters#1032
delei merged 7 commits into
apache:mainfrom
leehaut:hotfix/lance-common-2

Conversation

@leehaut

@leehaut leehaut commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Purpose of the pull request

Related: #1017

Add first-class converter support for java.time.LocalTime, following the existing LocalDate / LocalDateTime pattern.

What's changed?

Excel has no native time-only cell type. This PR treats LocalTime as the time-of-day counterpart of LocalDate:

  • Writing preserves the wall-clock time, attaches DateUtils.EPOCH (1970-01-01) as the date component, and applies HH:mm:ss so Excel shows time only.
  • Reading drops any date component with toLocalTime(). An Excel-native fraction (0.5 = 12:00:00) and a full datetime serial that happens to be 12:00:00 both become LocalTime.of(12, 0, 0).

Converter family under org.apache.fesod.sheet.converters.localtime:

  • LocalTimeDateConverter — default write path (DATE cell, format HH:mm:ss)
  • LocalTimeNumberConverter — bidirectional Excel numeric serial, including use1904windowing
  • LocalTimeStringConverter — bidirectional STRING cell; default HH:mm:ss, also auto-detects HH:mm, respects @DateTimeFormat and Locale

DateUtils additions (mirroring parseLocalDate / format(LocalDate)):

  • DEFAULT_LOCAL_TIME_FORMAT / TIME_FORMAT_8 / TIME_FORMAT_5
  • parseLocalTime(...) / format(LocalTime, ...) / switchTimeFormat(...) / getLocalTime(...)

Registration in DefaultConverterLoader matches LocalDateTime:

  • Number and String converters in initAllConverter()
  • Date converter as the default write converter
  • String converter for string-formatted writes

Scope is limited to java.time.LocalTime (JDK 8). Converter lookup is keyed by the declared Java class, so existing Date converters do not cover LocalTime fields.

Signed-off-by: lance <leehaut@gmail.com>
@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor

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

@leehaut

leehaut commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

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

Thanks for the catch. Removed the EasyExcel-derived license header from the newly added LocalTime converter files; they now keep the Apache 2.0 header only, consistent with FesodSheet.java.

Signed-off-by: lance <leehaut@gmail.com>
@delei
delei requested a lite review from Copilot August 23, 2026 08:18
Copilot stopped reviewing on behalf of delei due to an error August 23, 2026 08:39
@delei
delei requested a lite review from Copilot and removed request for Copilot August 23, 2026 10:18

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 java.time.LocalTime conversion support for Excel date, numeric, and string cells.

Changes:

  • Adds LocalTime parsing, formatting, and serial utilities.
  • Adds and registers date, number, and string converters.
  • Expands test models and converter round-trip coverage.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Summary
fesod-sheet/src/test/java/org/apache/fesod/sheet/util/TestUtil.java Adds shared LocalTime test fixtures.
fesod-sheet/src/test/java/org/apache/fesod/sheet/util/DateUtilsTest.java Tests LocalTime utility behavior.
fesod-sheet/src/test/java/org/apache/fesod/sheet/testkit/models/ConverterBaseData.java Adds LocalTime test-model data.
fesod-sheet/src/test/java/org/apache/fesod/sheet/testkit/builders/TestDataBuilderTest.java Verifies LocalTime fixture population.
fesod-sheet/src/test/java/org/apache/fesod/sheet/testkit/builders/TestDataBuilder.java Populates LocalTime test data.
fesod-sheet/src/test/java/org/apache/fesod/sheet/converters/localtime/LocalTimeStringConverterTest.java Tests string conversion and formats.
fesod-sheet/src/test/java/org/apache/fesod/sheet/converters/localtime/LocalTimeNumberConverterTest.java Tests numeric conversion and windowing.
fesod-sheet/src/test/java/org/apache/fesod/sheet/converters/localtime/LocalTimeDateConverterTest.java Tests date-cell conversion.
fesod-sheet/src/test/java/org/apache/fesod/sheet/converters/DefaultConverterLoaderTest.java Verifies converter registration.
fesod-sheet/src/test/java/org/apache/fesod/sheet/converter/ConverterDataTest.java Covers converter format round trips.
fesod-sheet/src/main/java/org/apache/fesod/sheet/util/DateUtils.java Adds LocalTime utilities and formats.
fesod-sheet/src/main/java/org/apache/fesod/sheet/converters/localtime/LocalTimeStringConverter.java Implements string conversion.
fesod-sheet/src/main/java/org/apache/fesod/sheet/converters/localtime/LocalTimeNumberConverter.java Implements numeric serial conversion.
fesod-sheet/src/main/java/org/apache/fesod/sheet/converters/localtime/LocalTimeDateConverter.java Implements date-cell conversion; empty @DateTimeFormat.value() should be normalized to use the HH:mm:ss default.
fesod-sheet/src/main/java/org/apache/fesod/sheet/converters/DefaultConverterLoader.java Registers the LocalTime converter family.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

leehaut and others added 2 commits August 23, 2026 18:43
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: lance <li6151770@126.com>
Comment thread fesod-sheet/src/test/java/org/apache/fesod/sheet/util/DateUtilsTest.java Outdated

@bengbengbalabalabeng bengbengbalabalabeng 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.

LGTM.

@delei
delei merged commit 239c416 into apache:main Aug 24, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants