Skip to content

Formula bar: a date cell shows its short date, whatever its format (#3510) - #3523

Open
quantforge-br wants to merge 2 commits into
storytold:mainfrom
quantforge-br:fix/formula-bar-short-date
Open

quantforge-br wants to merge 2 commits into
storytold:mainfrom
quantforge-br:fix/formula-bar-short-date

Conversation

@quantforge-br

@quantforge-br quantforge-br commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3510.

What was wrong

display::edit_text (what the formula bar and the cell editor start from) used the cell's formatted text for a date whenever that text read back as the same number, and an ISO date otherwise. So a date formatted mmmm-yy showed September-26 in the formula bar, and the day could not be seen or edited. d-mmm showed 1-Sep, which only reads back as the right date during the year it was typed in.

What Excel does

The formula bar shows a date the system's way, whatever the cell's format: the short date (built-in format 14, m/d/yyyy in en-US), followed by the time with seconds when there is one (9/1/2026 1:30:00 PM), and the time alone for a value under 1 (9:36:00 AM).

Change

edit_text formats a constant number in a date or time format with m/d/yyyy, m/d/yyyy h:mm:ss AM/PM or h:mm:ss AM/PM. If that text doesn't read back as the same number (fractions of a second, or dates past year 9999 in the 1904 system), it shows the serial as before. Formulas, text and non-date formats are unchanged.

The short date stays m/d/yyyy here. Following the system's regional short date is part of the Region work (#3048 and the PRs stacked on it), which will build on this.

Tests

  • editing_a_date_cell_shows_the_short_date_not_the_cell_format replaces editing_a_date_cell_shows_a_date_not_the_serial. It covers the [Bug Report] [GridCraft] Formula bar shows a date cell's formatted text instead of the date #3510 format ([$-40C]mmmm\-yy;@), mmmm-yy, d-mmm, dddd, mmmm d, yyyy-mm-dd, date with time, a time alone, a duration past one day, fractions of a second, a negative number and General. For each one it checks that committing the editor text unchanged keeps the value. It fails on main (yyyy-mm-dd gives 2026-03-04).
  • A throwaway sweep over every whole day, plus two times of day, from serial 0 to 2958465 in both date systems: every 1900-system value reads back. In the 1904 system, only serials past year 9999 don't read back, and those fall back to the serial.
  • I rendered the formula bar with the offscreen snapshot example for the two cells from the issue (9/1/2026 and 9/1/2026 1:30:00 PM).
  • cargo xtask ci steps run locally: fmt, clippy -D warnings, 3532 tests passed and 0 failed, plus assets, layers, keytips, wasm and parity --check.

Summary by CodeRabbit

  • Bug Fixes
    • Date and time values now appear in a consistent, readable format when edited, regardless of the cell’s number format. Dates use a short date format, and times include seconds.
    • Keeping the displayed date or time unchanged when committing an edit preserves its original numeric value.
    • Values that cannot be safely represented in the editor retain their original input text, helping avoid unintended changes to fractional seconds, negative numbers, and other values.

…ver its format

edit_text started from the cell's formatted text whenever it read back as the same date, so mmmm-yy showed September-26 and d-mmm showed 1-Sep, which reads back as September 1 of the current year. Excel shows the system short date (built-in format 14), the time with seconds when there is one, and the time alone under 1. Text that would not read back (fractions of a second, dates past 9999) still falls back to the serial.
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The date editor now uses fixed time-only, short-date, or short-date-and-time text based on the serial value. It returns that text only when parsing preserves the value; otherwise, it returns the raw input.

Changes: Date editor formatting

Layer / File(s) Summary
Format and validate editor text
crates/engine/src/display.rs, crates/engine/src/tests.rs
edit_text selects a fixed format based on the serial value and checks whether the formatted text round-trips. Tests cover date and time values, durations, fractional seconds, negative values, and ordinary numbers.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • storytold/gridcraft#2869: This issue concerns the fixed en-US short-date format, which this change also uses for date edit text.

Possibly related PRs

Suggested reviewers: eliets2, fredapps

Merge Risk: Minimal · up to fbf7d

Date cells now show a short date in the editor, with a safe fallback to the serial when the text would not round-trip. No actionable merge risk remains.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main change: in the formula bar, a date cell shows its short date instead of its formatted display text, regardless of the cell's number format. The raw summary and objectives bot…
Linked Issues check Passed [#3510] The reported defect is the formula bar and cell editor showing formatted text (September-26) for a date cell. At head, display::edit_text no longer uses format(&cell.value, cell.num_fmt)…
Out of Scope Changes check Passed [#3510] The changed files are crates/engine/src/display.rs and crates/engine/src/tests.rs. Both changes stay within edit_text and its regression test. The display.rs diff replaces the formatte…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title states the main change: in the formula bar, a date cell shows its short date instead of its formatted display text, regardless of the cell's number format. The raw summary and objectives both describe this change to display::edit_text, which returns a short date (m/d/yyyy) for date/time constants, and the linked issue #3510 asks for this exact behavior. The title is specific and matches the changeset, so it passes.

Full details: Linked Issues check

Explanation

[#3510] The reported defect is the formula bar and cell editor showing formatted text (September-26) for a date cell. At head, display::edit_text no longer uses format(&cell.value, cell.num_fmt) for date constants. It formats the value with a fixed system-style code: m/d/yyyy for whole values, m/d/yyyy h:mm:ss AM/PM for values with a time, and h:mm:ss AM/PM for values under 1. It returns that text only when it parses back to the same number within 1e-9. Otherwise it returns the raw serial. The test editing_a_date_cell_shows_the_short_date_not_the_cell_format covers the reported format [$-40C]mmmm\-yy;@ (expected 9/1/2026). It also covers mmmm-yy, d-mmm, and date-times. For each case, it checks that committing the editor text unchanged keeps the stored value. The issue's French-system expected string 01/09/2026 is not produced. The issue lists regional short-date behavior as related limitations (#361 regional settings, #2869 hardcoded format 14, #1233 locale tags). The PR states that this behavior is deferred to the Region work (#3048). Those items are context for this bug, not requirements of it, so the core display objective is met.

Full details: Out of Scope Changes check

Explanation

[#3510] The changed files are crates/engine/src/display.rs and crates/engine/src/tests.rs. Both changes stay within edit_text and its regression test. The display.rs diff replaces the formatted-text and ISO fallback path with the fixed date and time codes plus round-trip check. It also updates the doc comment to describe the new behavior. The time-only, date-time, fractional-second, negative, and General cases exercise the same code path and the same round-trip guard. Formula, text, and non-date format handling is kept, as the diff shows (cell.formula.is_some() || !parsed(code).is_date() still returns the raw input). No unrelated module or behavior change appears in the reviewed diff. The 1904-system sweep and the offscreen snapshot are author-reported. They are not in the repository, so this assessment does not verify them.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

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 c9b6fff and fbf7d9d.

Files selected for processing: 1

  • crates/engine/src/display.rs
Files skipped from review as they are similar to previous changes: 1

  • crates/engine/src/display.rs

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

@eliets2 eliets2 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First-pass review notes (automated; combined from specialist angles: docs and text). Please treat as suggestions and verify before acting.

What the change does: Fixes #3510 by changing display::edit_text so a constant number in a date or time format is shown in the formula bar as the short date m/d/yyyy, with time as m/d/yyyy h:mm:ss AM/PM or time alone as h:mm:ss AM/PM, regardless of the cell's number format, falling back to the serial when that text would not read back as the same number; formulas, text, and non-date formats are unchanged.

Logical units:

  • Change to edit_text formatting and fallback logic in crates/engine/src/display.rs
  • Replacement of editing_a_date_cell_shows_a_date_not_the_serial with editing_a_date_cell_shows_the_short_date_not_the_cell_format covering the formats and edge cases described

Findings:

  • [docs] crates/engine/src/display.rs, edit_text doc comment: says the date is written "the system's way" as built-in format 14, but the code hardcodes the en-US strings m/d/yyyy, m/d/yyyy h:mm:ss AM/PM, and h:mm:ss AM/PM and does not follow the regional short date. Fix: state that the format is hardcoded to en-US m/d/yyyy until the regional-format work lands.
  • [docs] crates/engine/src/display.rs, edit_text doc comment: says the serial is shown only when the text would not read back due to fractions of a second, but the fallback also applies to negative values and to dates that cannot be represented in the short-date text (e.g. past year 9999 in the 1904 system), where raw is returned. Fix: list those fallback cases in the comment so readers do not assume every date/time-formatted value is shown as a date/time.

Overlaps: The description notes following the system's regional short date is part of the Region work (#3048 and the PRs stacked on it), which will build on this change.

Verdict: needs changes — (1) clarify in the edit_text doc comment that the format is hardcoded to en-US, (2) list all fallback cases (negative values and unrepresentable dates, not only fractions of a second) in that comment, (3) no other findings were reported.

@quantforge-br

Copy link
Copy Markdown
Contributor Author

@eliets2 thanks, both points were right; fixed in fbf7d9d. The edit_text doc comment now says the short date is the en-US m/d/yyyy (built-in format 14, with h:mm:ss AM/PM for the time), where Excel takes it from the system's regional settings. It also lists every case that falls back to the serial: a negative number, fractions of a second, and a date the short date can't write (past year 9999 in the 1904 system). Doc only, no code change; the gate still passes (3532 tests).

freemans32 added a commit to freemans32/gridcraft that referenced this pull request Nov 13, 2026

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.

[Bug Report] [GridCraft] Formula bar shows a date cell's formatted text instead of the date

2 participants