leehaut commented on issue #1017:
URL: https://github.com/apache/fesod/issues/1017#issuecomment-5376900750

   I'd like to work on `java.time.LocalTime` converter support.
   
   Fesod already has `LocalDate` / `LocalDateTime` converters, and 
`WriteCellData` already maps `java.sql.Time` via 
`toLocalTime().atDate(DateUtils.EPOCH)`. A dedicated `LocalTime` converter 
family would close that gap for time-of-day fields (DB `TIME` columns, business 
hours, schedules) without requiring users to fall back to `String` or 
`LocalDateTime`.
   
   ### 1. Proposed Converter Family 
(`org.apache.fesod.sheet.converters.localtime`)
   
   Following the existing `LocalDate` / `LocalDateTime` pattern:
   
   - **`LocalTimeDateConverter`** (Write -> Excel `DATE` cell):
     - Emits `WriteCellData(value.atDate(DateUtils.EPOCH))` with default format 
`HH:mm:ss`.
     - Reuses the same epoch-date convention already used for `java.sql.Time` 
in `WriteCellData` / `CsvCell`.
   - **`LocalTimeNumberConverter`** (Bidirectional Excel `NUMBER` serial):
     - **Read**: `DateUtils.getLocalDateTime(serial, 
use1904windowing).toLocalTime()`, so both Excel-native time fractions (`0.5` = 
`12:00:00`) and full datetime serials round-trip to the same wall-clock time.
     - **Write**: `DateUtil.getExcelDate(value.atDate(DateUtils.EPOCH), 
use1904)`, consistent with the DATE write path.
   - **`LocalTimeStringConverter`** (Bidirectional Excel `STRING` cell):
     - **Read / Write**: parse and format with `@DateTimeFormat` if present, 
otherwise `HH:mm:ss` (and `HH:mm` when the input has no seconds).
     - Respect the configured `Locale`.
   
   Small `DateUtils` additions will be needed (mirroring `parseLocalDate` / 
`format(LocalDate)`):
   
   - `defaultLocalTimeFormat = "HH:mm:ss"`
   - `parseLocalTime(...)` / `format(LocalTime, ...)`
   - time-only pattern detection for `HH:mm:ss` / `HH:mm` (current 
`switchDateFormat` only covers date/datetime lengths)
   
   ### 2. Time-only Semantics
   
   - Excel has no native time-only cell type. Time is stored as a datetime 
serial (or a day fraction) and displayed via number format.
   - **Writing**: preserve the wall-clock time and attach `DateUtils.EPOCH` 
(`1970-01-01`) as the date component, then apply `HH:mm:ss` so Excel shows time 
only.
   - **Reading**: drop any date component with `toLocalTime()`. A numeric cell 
of `0.5` and a datetime serial that happens to be `12:00:00` both become 
`LocalTime.of(12, 0, 0)`.
   - This is the time-only counterpart of `LocalDate` (which keeps the date and 
zeros the time).
   
   ### 3. Registration & Test Coverage
   
   - Register `LocalTimeNumberConverter` and `LocalTimeStringConverter` in 
`DefaultConverterLoader.initAllConverter()`.
   - Register `LocalTimeDateConverter` and `LocalTimeStringConverter` in 
`DefaultConverterLoader.initDefaultWriteConverter()`.
   - Add a dedicated `LocalTimeConverterTest` under 
`org.apache.fesod.sheet.converter`, covering converter keys, DATE/NUMBER/STRING 
read-write, `@DateTimeFormat`, `use1904windowing`, and the date-dropping 
behavior.
   - Add round-trip coverage in `ConverterDataTest` where appropriate.
   - Validate loader immutability still holds in `DefaultConverterLoaderTest`.
   
   Scope is limited to `java.time.LocalTime` (JDK 8). `java.sql.Time` can be a 
follow-up if useful; converter lookup is keyed by the declared Java class, so 
existing `Date` converters do not cover `LocalTime` fields.
   
   If this direction looks good, I’d be happy to take it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to