{"record":{"id":"a54ec5f31983bcfa","repo":"nautechsystems/nautilus_trader","slug":"valid-utc-week-start","errorCode":null,"errorMessage":"valid UTC week start","messagePattern":"valid UTC week start","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/model/src/data/bar.rs","lineNumber":246,"sourceCode":"            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)\n                        .expect(\"valid year start date\")\n                        .at(0, 0, 0, 0),\n                )","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/data/bar.rs#L228-L264","documentation":"Immediately after computing the week start date, `get_time_bar_start` converts `week_start_date.at(0,0,0,0)` (midnight UTC) into a timestamp with `Offset::UTC.to_timestamp(...).expect(\"valid UTC week start\")` (crates/model/src/data/bar.rs:246). This fails only if the civil datetime is outside the range convertible to a jiff Timestamp, i.e. dates beyond roughly ±9999 years — not possible for real Unix timestamps.","triggerScenarios":"Practically unreachable for real timestamps; requires the derived week-start midnight datetime to fall outside jiff's Timestamp range.","commonSituations":"Only from synthetic/extreme `now` values or a library-level bug; never in normal operation.","solutions":["No action needed for genuine UnixTimestamp inputs.","If encountered, verify the `now` parameter is a valid UnixTimestamp rather than a corrupted value.","File an issue with the reproducing timestamp if hit on real data."],"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\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Feed genuine UnixNanos values into bar aggregation timers.","Investigate any panic here as a data/clock corruption bug, not a config issue."],"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-14T05:17:10.506Z"}