Skip to content

[Bug] Default date converters silently normalize invalid calendar dates #1157

Description

@Aias00

Fesod version

Current main at 5a9a16b.

Description

Default string-to-date conversion is lenient. Invalid calendar dates are silently changed into different valid dates instead of failing conversion.

Location

  • fesod-sheet/src/main/java/org/apache/fesod/sheet/util/DateUtils.java:378-395
  • fesod-sheet/src/main/java/org/apache/fesod/sheet/util/DateUtils.java:398-411

SimpleDateFormat keeps its default lenient behavior. DateTimeFormatter.ofPattern uses SMART resolver behavior unless made strict.

Reproduction

DateUtils.parseDate("2024-02-31");
// formats back as 2024-03-02

DateUtils.parseLocalDate("2024-02-31", null, Locale.US);
// returns 2024-02-29

A valid control value such as 2024-02-29 remains unchanged.

Expected behavior

Invalid calendar dates should raise a conversion error. Importing malformed spreadsheet text must not silently change the represented date.

Suggested fix

Disable lenient SimpleDateFormat parsing and use strict resolver semantics for java.time parsing. Account for yyyy versus uuuu when making existing patterns strict, and add converter-level regression tests for invalid month-end and leap-day values.

Related existing work

#1116/#1117 cover negative Excel serial dates. #1040 covers locale handling. Neither covers invalid string dates being normalized.

Are you willing to submit a PR?

Yes.

Activity

  1. BigDataDZ commented on Oct 4, 2026

    @BigDataDZ
    Contributor

    I would like to work on this. Plan: make the SimpleDateFormat-based parsing non-lenient and switch the java.time parsing to ResolverStyle.STRICT (rewriting year-of-era y to u where patterns have no era field), then add converter-level regression tests for invalid month-end and leap-day strings like 2024-02-31 / 2023-02-29 on both the legacy Date and java.time paths.

  2. bengbengbalabalabeng commented on Oct 7, 2026

    @bengbengbalabalabeng
    Contributor

    I would like to work on this. Plan: make the SimpleDateFormat-based parsing non-lenient and switch the java.time parsing to ResolverStyle.STRICT (rewriting year-of-era y to u where patterns have no era field), then add converter-level regression tests for invalid month-end and leap-day strings like 2024-02-31 / 2023-02-29 on both the legacy Date and java.time paths.

    Thank you for your interest. There is already a corresponding fix PR (#1167) for this issue. If you'd like, you're also welcome to review it or add further comments to the discussion here.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions