Skip to content

feat: add Character and Year converters (#1017) - #1087

Open
BigDataDZ wants to merge 5 commits into
apache:mainfrom
BigDataDZ:feat/character-year-converters
Open

feat: add Character and Year converters (#1017)#1087
BigDataDZ wants to merge 5 commits into
apache:mainfrom
BigDataDZ:feat/character-year-converters

Conversation

@BigDataDZ

Copy link
Copy Markdown

Purpose of the pull request

Implements two commonly used JDK 8 compatible converters requested by the community task #1017:
java.lang.Character and java.time.Year. Proposal comments:
#1017 (comment) and the amendment below it
(UUID / YearMonth / Instant were proposed by other volunteers in parallel and are left to
them).

Related: #1017

What's changed?

  • CharacterStringConverter (org.apache.fesod.sheet.converters.charconverter): bidirectional
    Character <-> STRING. Reading an empty string yields null; strings longer than one character
    throw (wrapped into ExcelDataConvertException by the framework) instead of being silently
    truncated.
  • YearStringConverter (org.apache.fesod.sheet.converters.year): bidirectional Year <->
    STRING, default format uuuu, honors @DateTimeFormat custom patterns and
    GlobalConfiguration.locale.

Both follow the existing *StringConverter pattern (e.g. LocalTimeStringConverter) and are
registered in DefaultConverterLoader under putAllConverter, putWriteConverter and
putWriteStringConverter, so they work on read, xlsx write and CSV write alike.

Each converter ships with JUnit 5 unit tests (11 tests total: type keys, round-trips, default and
custom formats, and error cases).

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.

Signed-off-by: BigDataDZ <76271875+BigDataDZ@users.noreply.github.com>
Signed-off-by: BigDataDZ <76271875+BigDataDZ@users.noreply.github.com>
Comment thread fesod-sheet/src/main/java/org/apache/fesod/sheet/util/DateUtils.java Outdated
Signed-off-by: BigDataDZ <76271875+BigDataDZ@users.noreply.github.com>
@BigDataDZ

Copy link
Copy Markdown
Author

Done in 254a11e — renamed to DateUtils.defaultYearFormat, following the sibling fields
defaultDateFormat / defaultLocalDateFormat, and parseYear / format(Year, ...) now fall
back to it when no explicit format is given, so it works as a global default just like the other
two. Tests re-run green (11/11 targeted, 927/927 full suite).

@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor

It is recommended to add tests for the following scenarios to cover the complete behavior of YearStringConverter / DateUtils:

  • DateUtils#parseYear() / format(Year)
  • Locale's impact on formatting(format = "G y",Locale.CHINA -> "公元 2026",Locale.US -> "AD 2026")

Signed-off-by: BigDataDZ <76271875+BigDataDZ@users.noreply.github.com>
@BigDataDZ

Copy link
Copy Markdown
Author

Added in faf2207, covering both layers:

  1. DateUtilsTest — direct coverage for DateUtils#parseYear / #format(Year, ...):
    default yyyy parse and format (with null and explicit locales), plus a custom pattern
    (uu).
  2. Locale coverageformat(Year.of(2026), "G y", Locale.CHINA)公元 2026 and
    Locale.USAD 2026, mirrored through the converter in
    YearStringConverterTest#convertToExcelDataRespectsLocaleForEraPatterns (a
    GlobalConfiguration with Locale.CHINA / Locale.US and a @DateTimeFormat pattern of
    G y).

Also adjusted the existing custom-format test: the previous MM/yyyy pattern is invalid for a
bare Year (no MonthOfYear field — UnsupportedTemporalTypeException), replaced with
'Y'yyyyY2026.

Targeted tests 79/79, full fesod-sheet suite 933/933 green.

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.

2 participants