Skip to content

[Bug] Date format with fractional seconds and AM/PM is read as a raw serial #1118

Description

@nkuprins

Search before asking

  • I searched in the issues and found nothing similar.

Fesod version

main

JDK version

any

Operating system

Linux

Steps To Reproduce

File file = new File("ampm.xlsx");

DataFormatData dataFormat = new DataFormatData();
dataFormat.setFormat("hh:mm:ss.000 AM/PM");

WriteCellData<BigDecimal> cell = new WriteCellData<>(new BigDecimal("42000.75"));
cell.getOrCreateStyle().setDataFormatData(dataFormat);

FesodSheet.write(file)
        .head(Collections.singletonList(Collections.singletonList("time")))
        .sheet()
        .doWrite(Collections.singletonList(Collections.singletonList(cell)));

System.out.println(FesodSheet.read(file).sheet().doReadSync());

Current Behavior

[{0=hh:mm:ss42000.750 AM/PM}]

A format containing both fractional seconds and an AM/PM marker is not recognised as a date, so DataFormatter.format takes the number branch: numPattern matches the 000, and createNumberFormat builds a DecimalFormat("hh:mm:ss.000 AM/PM"), which leaves the pattern letters as literal text around the raw serial.

Affected formats include hh:mm:ss.000 AM/PM, h:mm:ss.0 AM/PM, mm:ss.0 AM/PM and m/d/yy h:mm:ss.000 AM/PM. Without the AM/PM part (hh:mm:ss.000) or without the fractional seconds (hh:mm:ss AM/PM) detection works, so only the combination is affected.

Expected Behavior

[{0=06:00:00.000 PM}]

Anything else?

Found while writing the tests in #1110.

fesod: "^[\\[\\]yYmMdDhHsS\\-T/\u5e74\u6708\u65e5,. :\"\\\\]+0*[ampAMP/]*$"
POI:    "^[\\[\\]yYmMdDhHsS\\-T/\u5e74\u6708\u65e5,. :\"\\\\]+0* ?[ampAMP/]*$"

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions