{"record":{"id":"68d2912b1be63984","repo":"nautechsystems/nautilus_trader","slug":"valid-week-start","errorCode":null,"errorMessage":"valid week start","messagePattern":"valid week start","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/model/src/data/bar.rs","lineNumber":243,"sourceCode":"            find_closest_smaller_time(now, origin_offset, SignedDuration::from_millis(step))\n        }\n        BarAggregation::Second => {\n            find_closest_smaller_time(now, origin_offset, SignedDuration::from_secs(step))\n        }\n        BarAggregation::Minute => {\n            find_closest_smaller_time(now, origin_offset, SignedDuration::from_mins(step))\n        }\n        BarAggregation::Hour => {\n            find_closest_smaller_time(now, origin_offset, SignedDuration::from_hours(step))\n        }\n        BarAggregation::Day => find_closest_smaller_time(now, origin_offset, duration_days(step)),\n        BarAggregation::Week => {\n            let now_civil = Offset::UTC.to_datetime(now);\n            let days_from_monday = i64::from(now_civil.weekday().to_monday_zero_offset());\n            let week_start_date = now_civil\n                .date()\n                .checked_sub(jiff::Span::new().days(days_from_monday))\n                .expect(\"valid week start\");\n            let mut start_time = Offset::UTC\n                .to_timestamp(week_start_date.at(0, 0, 0, 0))\n                .expect(\"valid UTC week start\");\n            start_time += origin_offset;\n\n            if now < start_time {\n                start_time -=\n                    duration_days(step.checked_mul(7).expect(\"`step` overflows i64 days\"));\n            }\n\n            start_time\n        }\n        BarAggregation::Month => {\n            // Set to the first day of the year\n            let now_civil = Offset::UTC.to_datetime(now);\n            let mut start_time = Offset::UTC\n                .to_timestamp(\n                    Date::new(now_civil.year(), 1, 1)","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/data/bar.rs#L225-L261","documentation":"In `get_time_bar_start` (crates/model/src/data/bar.rs:243), the Week branch computes the start of the ISO week by subtracting `days_from_monday` days from the current UTC date with jiff's `checked_sub`. The expect panics if that date arithmetic fails — practically only if the subtraction underflows jiff's supported date range (years roughly -9999..9999), which cannot occur for real timestamps.","triggerScenarios":"Effectively unreachable for valid Unix timestamps; would require `now` to be a timestamp whose UTC civil date is at/near jiff's minimum supported date so subtracting up to 6 days underflows.","commonSituations":"Corrupted or synthetic clock values near the extreme low end of representable time; otherwise never hit in production.","solutions":["No action needed for real timestamps; if you construct `now` yourself, ensure it is a normal UnixTimestamp.","If seen, inspect the timestamp passed into get_time_bar_start for corruption.","Upgrade jiff / nautilus_model if this arises from a library version bug."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// rust\nfn timestamp_in_reasonable_range(now: UnixNanos) -> bool {\n    let (secs, _) = (now.as_u64() / 1_000_000_000, ());\n    secs > 0 && secs < 253_402_300_799 // 9999-12-31\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure clock sources produce real Unix timestamps, not sentinel/corrupted values.","This guard is defensive; no caller action normally required."],"tags":["rust","panic","date-arithmetic","jiff","defensive"],"backgroundTag":"internal-invariant-violation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}