Title: id(didit): count_periods Week branch panics at calendar boundaries — unchecked NaiveDate arithmetic (residual of #7766) · Issue #7771 · developing-today/code · GitHub
Open Graph Title: id(didit): count_periods Week branch panics at calendar boundaries — unchecked NaiveDate arithmetic (residual of #7766) · Issue #7771 · developing-today/code
X Title: id(didit): count_periods Week branch panics at calendar boundaries — unchecked NaiveDate arithmetic (residual of #7766) · Issue #7771 · developing-today/code
Description: Problem count_periods in pkgs/id/src/didit/eval.rs (lines 395–402 on main b64288a567) computes the Period::Week branch with unchecked chrono date arithmetic: let monday = today - Duration::days(i64::from(today.weekday().num_days_from_mon...
Open Graph Description: Problem count_periods in pkgs/id/src/didit/eval.rs (lines 395–402 on main b64288a567) computes the Period::Week branch with unchecked chrono date arithmetic: let monday = today - Duration::days(i64...
X Description: Problem count_periods in pkgs/id/src/didit/eval.rs (lines 395–402 on main b64288a567) computes the Period::Week branch with unchecked chrono date arithmetic: let monday = today - Duration::days(i64...
Opengraph URL: https://github.com/developing-today/code/issues/7771
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"id(didit): count_periods Week branch panics at calendar boundaries — unchecked NaiveDate arithmetic (residual of #7766)","articleBody":"## Problem\n\n`count_periods` in `pkgs/id/src/didit/eval.rs` (lines 395–402 on main `b64288a567`) computes the `Period::Week` branch with unchecked `chrono` date arithmetic:\n\n```rust\nlet monday = today - Duration::days(i64::from(today.weekday().num_days_from_monday()));\nlet start = midnight(tz, monday)?;\nlet end = midnight(tz, monday + Duration::days(7))?;\nlet previous_start = midnight(tz, monday - Duration::days(7))?;\n```\n\n`NaiveDate + Duration` / `NaiveDate - Duration` **panic** on overflow (chrono implements them as `checked_add_signed(...).expect(\"`NaiveDate + TimeDelta` overflowed\")`). For a `now` in the first or last week of the representable calendar, `monday + 7 days`, `monday - 7 days`, or the Monday offset subtraction itself runs off the end of `NaiveDate`'s range and the evaluator panics — in debug *and* release builds.\n\nThis is the residual door of #7766. That fix converted the `Period::Custom` branch to checked arithmetic with the comment that \"the Day/Week branches get [OutOfRange] from the calendar\" — true for `Day`, which uses `succ_opt()`/`pred_opt()` (eval.rs:388–394), but not for `Week`, which uses the panicking operators. `evaluate` is documented as a pure function that \"can be replayed for any past instant\" (eval.rs module docs / `didit/mod.rs`), so a calendar-boundary `now` must answer `EvalError::OutOfRange`, never panic.\n\nThe same unchecked-operator pattern survives once more in the same file: `resolve_local` (eval.rs:573) computes `naive + Duration::hours(1)` when a local time falls in a DST gap; `NaiveDateTime + Duration` panics the same way at the top of the representable range. Audit it in the same pass (a checked add that falls through to the existing UTC fallback is sufficient).\n\n## Evidence (verified this run, laptop, main `b64288a567`)\n\nProbe `~/git/fleet/probe-didit-week-overflow` (laptop): the Week/Day branches and their helpers copied verbatim from `eval.rs` (file md5 `592058f89673b9202523c586c80b36fc`), built against chrono 0.4.45 (the version in `pkgs/id/Cargo.lock`), run in **release** mode:\n\n```\nNaiveDate::MAX=+262142-12-31 weekday=Mon max_now=8210266833600\nNaiveDate::MIN=-262143-01-01 weekday=Thu min_now=-8334601185600\ncontrol week ordinary: Ok(((1699833600, 1700438400), (1699228800, 1699833600)))\ncontrol day ordinary: Ok(((1699920000, 1700006400), (1699833600, 1699920000)))\nweek now=MAX-date noon: PANIC\nday now=MAX-date noon: Err(OutOfRange)\nweek now=MIN-date noon: PANIC\nday now=MIN-date noon: Err(OutOfRange)\n```\n\nSame instants, same function: `Day` returns `OutOfRange`, `Week` panics at both calendar ends. Ordinary-input controls pass for both branches.\n\n## Why it matters\n\n- A panic in the pure evaluator aborts whatever projection/app pass called `evaluate` — the exact failure mode #7766 fixed for `Custom`, one branch over.\n- The #7766 fix comment now actively misdocuments the Week branch as calendar-guarded, so the residual is likely to survive future audits that trust the comment.\n\n## Acceptance criteria\n\n- [ ] `count_periods` `Period::Week` uses checked date arithmetic (`checked_add_signed` / `checked_sub_signed` or `succ_opt`-style stepping) and returns `EvalError::OutOfRange` when the week's Monday, its +7d end, or its −7d previous start is unrepresentable.\n- [ ] `resolve_local`'s `+ Duration::hours(1)` shift is checked or otherwise panic-free at the representable boundary.\n- [ ] Regression test mirroring `custom_period_extreme_anchor_is_out_of_range_not_a_panic_or_wrapped_window`: a Week-period expectation evaluated at a `now` on `NaiveDate::MAX` and on `NaiveDate::MIN` returns `Err(EvalError::OutOfRange)` (test fails — panics — pre-fix); an ordinary Week expectation still evaluates.\n- [ ] The #7766 comment in the `Custom` branch is corrected if it still claims the Week branch is calendar-guarded.\n- [ ] `cargo test` for the `didit` module passes.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-11-08T17:48:26Z","url":"https://github.com/developing-today/code/issues/7771"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a043fe41-98d5-98e5-21e7-74b9e4b4c0f5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A32C:197E15:40D3C8:5A09D5:6B073408 |
| html-safe-nonce | 4d0f22711b7d1d49f54f1c7fa293d7dd3eb7d6d37c5d513b0ef0c40a0d4f5c51 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzJDOjE5N0UxNTo0MEQzQzg6NUEwOUQ1OjZCMDczNDA4IiwidmlzaXRvcl9pZCI6IjUzMjg3MjcyNDExNzIzOTkxMTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a0e4c2b6238e0f9aecc0e6c53926f9ff73fd7289a1f16cd3392967e2cc061581 |
| hovercard-subject-tag | issue:6273789189 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/7771/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eefcbdc2eee34e01451d2d0d43d92d2c41e4d21613b96f27b7ba8d3c7262d6a1/developing-today/code/issues/7771 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eefcbdc2eee34e01451d2d0d43d92d2c41e4d21613b96f27b7ba8d3c7262d6a1/developing-today/code/issues/7771 |
| og:image:alt | Problem count_periods in pkgs/id/src/didit/eval.rs (lines 395–402 on main b64288a567) computes the Period::Week branch with unchecked chrono date arithmetic: let monday = today - Duration::days(i64... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2a60952cad7efb2604ea85e500208f51c1ec1943aa260ac605c13eb46a1ed83b |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 345c27626db08417fdfc84278a4415ae9a48d8f3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width