Skip to content

ODS import: durations with zero years and months are read - #4372

Open
Hamza0101 wants to merge 1 commit into
storytold:mainfrom
Hamza0101:fix/ods-duration-zero-calendar-fields
Open

Hamza0101 wants to merge 1 commit into
storytold:mainfrom
Hamza0101:fix/ods-duration-zero-calendar-fields

Conversation

@Hamza0101

@Hamza0101 Hamza0101 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4358

What was wrong

parse_duration in crates/xlsx/src/ods.rs reads an ODS office:time-value, which ODF defines as an XML Schema duration. It read days and the time part, but not years or months. A duration that spells out zero years or months (P0Y0M1DT3H, the same length as P1DT3H) became text, and stayed text in an XLSX save, with the generic "unsupported values" warning.

The issue notes that Excel rejects the padded spelling too. So this is about reading the format as its standard defines it, for files from other producers, rather than about matching Excel. Only values that were text before change; every duration GridCraft already read reads the same.

What changed

  • A zero count of years or months (0Y, 0M, 00Y) at the start of the date part is read past.
  • A non-zero count (P1Y, P0Y1M) still keeps the value as text. Years and months have no fixed length in days, which is why they were refused, and that reason still holds.
  • They must come first and in order (Y, then M, before D and T); P0M0Y1D stays text.

QA report

Main vs branch, end to end (gridcraft-cli, an ODS file)

dur.ods is a minimal ODS package I assembled. One row holds the issue's five pairs as time cells, then P1Y and P0Y1M, then the number 42 as a float control. Each build converted it with run --in dur.ods --out out.xlsx, and I evaluated =IF(ISNUMBER(X1),ROUND(X1*24,4)&"h","text:"&X1) on each cell of the .xlsx. main is a gridcraft-cli built from origin/main (abcfc191); the branch is this PR (4ab70c0e).

Pair from the issue main this PR
P1DT3H / P0Y0M1DT3H 27h / text 27h / 27h
PT3H / P0MT3H 3h / text 3h / 3h
-PT2H / -P0YT2H −2h / text −2h / −2h
PT0S / P0Y0M0D 0h / text 0h / 0h
P1DT2H3M4.5S / P0Y0M1DT2H3M4.5S 26.0513h / text 26.0513h / 26.0513h
P1Y, P0Y1M (non-zero years or months) text, text text, text
float 42 (control) 1008h 1008h

Both builds still warn about unsupported values, because P1Y and P0Y1M are still text.

Test

tests::ods_tests::ods_durations_read_zero_years_and_months covers:

  • each of the issue's five pairs, read as the same number (P0Y0M1DT3H is 1.125);
  • P1Y, P0Y1M, P0M0Y1D (out of order), P0Y0MT (an empty time part) and P0YX, all kept as text;
  • P00Y, read as zero.

The existing ODS tests, including P1M and PT2M1H staying text, still pass.

Negative control

With the year and month step skipped (on top of 4ab70c0e, then restored with git checkout), the test fails at the first pair: left Number(1.125), right Text("P0Y0M1DT3H").

Gate (macOS arm64)

Step Result
cargo fmt --all -- --check clean
cargo clippy -p gridcraft-xlsx --all-targets -- -D warnings clean
cargo test -p gridcraft-xlsx -p gridcraft-engine 1004 (+1 ignored) + 120 + 7 + 375 passed, 0 failed

Not covered

  • Excel parity: Excel rejects these spellings, per the issue. If GridCraft should match Excel on ODS durations instead of the XML Schema definition, this PR shouldn't land; I'm flagging it for that decision.
  • Durations with real years or months stay text, as before.
  • Overlap: ODS import: a date at 24:00:00 is the next midnight #4371, hour-24 dates, edits parse_date in the same file, a different function. The two tests sit in different places.
  • cargo xtask ci: I didn't run the full cargo xtask ci (wasm, layers, the other crates).

Summary by CodeRabbit

  • Bug Fixes
    • ODS spreadsheets now correctly read durations that include zero-valued year or month components, including durations representing zero.
    • Durations with nonzero year or month components remain unsupported and are preserved as text. Malformed year or month components are also not interpreted as durations.

XML Schema writes a duration with or without zero-valued years and months (P0Y0M1DT3H is P1DT3H), but the importer only read days and time, so the padded spelling became text. A zero count of years or months is now read past; a nonzero one still keeps the value as text, since years and months have no fixed length in days. Fixes storytold#4358.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The ODS duration parser now accepts zero-valued year and month components before parsing days and time. Nonzero year or month components remain unsupported. Tests cover equivalent duration forms, including negative and fractional durations.

Changes: ODS duration parsing

Layer / File(s) Summary
Accept zero-valued calendar components
crates/xlsx/src/ods.rs, crates/xlsx/src/tests/ods_tests.rs
The parser consumes zero-valued year and month components and continues parsing the duration. Tests cover equivalent forms, malformed and nonzero components, and P00Y.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: dylanmtaylor

Merge Risk: Minimal · up to 4ab70

ODS durations written with explicit zero years or months now import as numbers instead of text, matching their unpadded forms. Durations with nonzero years or months stay text. The change is small and tested, and I found no merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "ODS import: durations with zero years and months are read" matches the main change. The PR makes parse_duration in crates/xlsx/src/ods.rs accept zero-valued year and month components, and a…
Linked Issues check Passed Issue #4358 requires ODS office:time-value durations with zero-valued years or months to parse as their unpadded equivalents. Nonzero year or month units are out of scope. The diff to `parse_duratio…
Out of Scope Changes check Passed The whole-PR diff changes only parse_duration in crates/xlsx/src/ods.rs, plus a test in crates/xlsx/src/tests/ods_tests.rs per the change summary. The new logic directly implements the zero year…
Full details: Title check

Explanation

The title "ODS import: durations with zero years and months are read" matches the main change. The PR makes parse_duration in crates/xlsx/src/ods.rs accept zero-valued year and month components, and adds a test for that behavior. The title names the file format, the affected value type, and the specific case. It does not mention that nonzero year or month values still stay as text, but that limit is a detail, not the main change.

Full details: Linked Issues check

Explanation

Issue #4358 requires ODS office:time-value durations with zero-valued years or months to parse as their unpadded equivalents. Nonzero year or month units are out of scope. The diff to parse_duration in crates/xlsx/src/ods.rs (merge base abcfc191 to head 4ab70c0e) adds a loop over ['Y', 'M'] in the date part before T. For each unit, it reads the digits before the unit. If all digits are zero, it skips the field. If any digit is nonzero, it returns None, which keeps the value as text. Trace checks: P0Y0M1DT3H reduces to P1DT3H; P0MT3H reduces to PT3H; P0Y0M0D reduces to P0D; P0M0Y1D fails the digit check on Y and stays text; P1M stays text; PT2M1H is not matched because its M lies after T. This covers the five equivalent pairs in #4358 (zero, 3 hours, negative, fractional seconds, and days with zero years and months). The author reports an automated test, ods_durations_read_zero_years_and_months, and a negative control. I did not run the test. Those results are author-reported.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff changes only parse_duration in crates/xlsx/src/ods.rs, plus a test in crates/xlsx/src/tests/ods_tests.rs per the change summary. The new logic directly implements the zero year and month requirement of #4358. The test supports that requirement. No unrelated change is visible. The PR description says parse_date in the same file is changed by #4371. That change is not part of this diff and is not assessed here.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between abcfc19 and 4ab70c0.

Files selected for processing: 2

  • crates/xlsx/src/ods.rs
  • crates/xlsx/src/tests/ods_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

This branch has not been deployed

No deployments
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.

ODS import converts durations with zero calendar fields into text

1 participant