Skip to content

A month or a year stored at its own precision can be truncated, so "2024-03" truncated to a month is 2024-03-01 instead of no value - #1407

Open
rudycelekli wants to merge 2 commits into
deeplethe:devfrom
rudycelekli:fix/coarse-date-trunc
Open

rudycelekli wants to merge 2 commits into
deeplethe:devfrom
rudycelekli:fix/coarse-date-trunc

Conversation

@rudycelekli

Copy link
Copy Markdown
Contributor

Why

Date attributes keep the precision that was written: a month is 2024-03, a year is 2024. date_trunc only parsed a full YYYY-MM-DD or an offset timestamp, so truncating either of those values produced no result. A rule that floors a month-precision date to its month, or a year-precision date to its year, dropped the fact.

What changes

YYYY-MM and YYYY parse as that month and that year. Truncation still cannot invent a finer part: a month truncated to a day, or a year truncated to a month, stays absent. Offset timestamps are unchanged, and a timestamp without an offset is still rejected.

How it was checked

In calendar_truncation_uses_utc_and_rejects_ambiguous_or_invalid_dates:

  • month truncation of 2024-03 is 2024-03-01
  • year truncation of 2024-03 is 2024-01-01
  • year truncation of 2024 is 2024-01-01

On the original function the month case fails with left: None. With the change, cargo test -p utopia-reason --lib passes (108). cargo fmt -p utopia-reason and cargo clippy -p utopia-reason --all-targets -- -D warnings pass.

Before review

  • Every commit is signed off (git commit -s)
  • cargo fmt, cargo clippy and cargo test pass for the touched crate

@WaylandYang WaylandYang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, the bug is real: normalize_attr_value stores 2024-03 and 2024, and date_trunc gives no value for them today. Two things: please update ADR 0036's list of accepted date inputs (it still names only an ISO calendar date or an RFC 3339 timestamp), and require four ASCII digits for the year form so +202 or -123 aren't read as years.

…024-03" truncated to a month is 2024-03-01 instead of no value

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
…036 lists the month and year forms it accepts

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
@rudycelekli
rudycelekli force-pushed the fix/coarse-date-trunc branch from cc2da48 to b074125 Compare November 5, 2026 03:15
@rudycelekli

Copy link
Copy Markdown
Contributor Author

ADR 0036 now lists the month (2024-03) and four-digit year (2024) inputs and says a value cannot be truncated finer than it states; the bare-year form now requires four ASCII digits, with "+202" and "-123" added as no-value cases in calendar_truncation_uses_utc_and_rejects_ambiguous_or_invalid_dates. Rebased on dev.

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.

2 participants