nautechsystems/nautilus_trader · info

valid UTC year start

Error message

valid UTC year start

What it means

Right after building Jan 1 midnight, the Month branch converts it to a timestamp: `Offset::UTC.to_timestamp(...).expect("valid UTC year start")` (crates/model/src/data/bar.rs:265). It fails only if that civil datetime lies outside jiff's Timestamp-convertible range — not reachable for real Unix timestamps.

Source

Thrown at crates/model/src/data/bar.rs:265

            start_time += origin_offset;

            if now < start_time {
                start_time -=
                    duration_days(step.checked_mul(7).expect("`step` overflows i64 days"));
            }

            start_time
        }
        BarAggregation::Month => {
            // Set to the first day of the year
            let now_civil = Offset::UTC.to_datetime(now);
            let mut start_time = Offset::UTC
                .to_timestamp(
                    Date::new(now_civil.year(), 1, 1)
                        .expect("valid year start date")
                        .at(0, 0, 0, 0),
                )
                .expect("valid UTC year start");
            start_time += origin_offset;

            if now < start_time {
                start_time =
                    subtract_n_months(start_time, 12).expect("Failed to subtract 12 months");
            }

            let months_step =
                u32::try_from(step).expect("`step` exceeds u32 range for month arithmetic");

            while start_time <= now {
                start_time =
                    add_n_months(start_time, months_step).expect("Failed to add months in loop");
            }

            start_time =
                subtract_n_months(start_time, months_step).expect("Failed to subtract months_step");
            start_time

View on GitHub (pinned to 18893faf8b)

Solutions

  1. No action needed for genuine timestamps.
  2. Check the `now` parameter for corruption if this panic occurs.
  3. Upgrade the crate / file an issue if reproducible on real data.
Defensive patterns

Strategy: type-guard

Validate before calling

// rust
fn timestamp_in_reasonable_range(now: UnixNanos) -> bool {
    let secs = now.as_u64() / 1_000_000_000;
    secs > 0 && secs < 253_402_300_799
}

Prevention

When it happens

Trigger: Practically unreachable; requires the derived Jan-1 midnight to be outside jiff's supported timestamp range.

Common situations: Only from extreme synthetic inputs or a library bug.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/fe59dd3599b159f3. Report an issue: GitHub.