{"record":{"id":"78f07ebe9f39e175","repo":"nautechsystems/nautilus_trader","slug":"execution-timestamp-time-str-was-before-unix-e","errorCode":null,"errorMessage":"Execution timestamp '{time_str}' was before Unix epoch","messagePattern":"Execution timestamp '(.+?)' was before Unix epoch","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/execution/parse.rs","lineNumber":460,"sourceCode":"            \"Unrecognized execution timezone '{tz_str}' in '{time_str}'. Configure TWS / IB Gateway to emit a standard timezone (e.g. UTC)\"\n        )\n    })?;\n    let ambiguous = zone.to_ambiguous_timestamp(dt);\n    match ambiguous.offset() {\n        AmbiguousOffset::Unambiguous { .. } => Ok(ambiguous.unambiguous()?),\n        // Fall-back fold: take the earliest instant (worst case ~1h skew).\n        AmbiguousOffset::Fold { .. } => Ok(ambiguous.earlier()?),\n        AmbiguousOffset::Gap { .. } => {\n            anyhow::bail!(\"Execution timestamp '{time_str}' is non-existent in timezone '{tz_str}'\")\n        }\n    }\n}\n\nfn datetime_to_unix_nanos(dt: Timestamp, time_str: &str) -> anyhow::Result<UnixNanos> {\n    let nanos: u64 = dt\n        .as_nanosecond()\n        .try_into()\n        .map_err(|_| anyhow::anyhow!(\"Execution timestamp '{time_str}' was before Unix epoch\"))?;\n    Ok(UnixNanos::new(nanos))\n}\n\n#[cfg(test)]\nmod tests {\n    use ibapi::{\n        contracts::Contract,\n        orders::{Action, ExecutionSide, Liquidity, Order, OrderStatusKind},\n    };\n    use nautilus_model::{\n        enums::TrailingOffsetType,\n        identifiers::{Symbol, Venue},\n        instruments::{InstrumentAny, stubs::equity_aapl},\n    };\n    use rust_decimal::Decimal;\n\n    use super::*;\n    use crate::{","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/execution/parse.rs#L442-L478","documentation":"datetime_to_unix_nanos converts a parsed IB timestamp to UnixNanos, which is a u64 count of nanoseconds since the Unix epoch. If the timestamp's nanosecond value is negative (i.e. the datetime predates 1970-01-01), the try_into::<u64> fails and this error is thrown since UnixNanos cannot represent pre-epoch times.","triggerScenarios":"parse_execution_time calls datetime_to_unix_nanos with a Timestamp before 1970-01-01 — e.g. a corrupted or misparsed execution time like \"19691231 23:59:59\" that still happens to match the naive format.","commonSituations":"Corrupt test/paper-trading data; year typos in synthetic fills; timezone localization shifting a near-epoch timestamp across the boundary; upstream system clocks badly misconfigured.","solutions":["Inspect the offending time_str in the error; a pre-epoch execution timestamp indicates corrupted input data that should be fixed at the source.","Validate the parsed year is >= 1970 before conversion and reject such execution records early.","Check machine clock/timezone configuration on the gateway host if timestamps are unexpectedly far in the past."],"exampleFix":"// before\nlet nanos: u64 = dt\n    .as_nanosecond()\n    .try_into()\n    .map_err(|_| anyhow::anyhow!(\"Execution timestamp '{time_str}' was before Unix epoch\"))?;\n// after\nif dt.as_nanosecond() < 0 {\n    anyhow::bail!(\"Execution timestamp '{time_str}' was before Unix epoch\");\n}\nlet nanos: u64 = dt\n    .as_nanosecond()\n    .try_into()\n    .map_err(|_| anyhow::anyhow!(\"Execution timestamp '{time_str}' was before Unix epoch\"))?;","handlingStrategy":"validation","validationCode":"// Rust: reject pre-epoch timestamps before conversion\nfn is_post_epoch(dt: &Timestamp) -> bool {\n    dt.as_nanosecond() >= 0\n}","typeGuard":"fn epoch_safe_nanos(dt: Timestamp) -> Option<u64> {\n    u64::try_from(dt.as_nanosecond()).ok()\n}","tryCatchPattern":"match u64::try_from(dt.as_nanosecond()) {\n    Ok(nanos) => Ok(UnixNanos::new(nanos)),\n    Err(_) => {\n        tracing::error!(\"Execution timestamp '{time_str}' predates Unix epoch; skipping record\");\n        return Ok(());\n    }\n}","preventionTips":["Sanity-check parsed execution years (>= 1970, not far future) before conversion","Fix corrupted source data rather than widening UnixNanos to signed","Verify gateway host clock and timezone configuration"],"tags":["timestamp","unix-epoch","validation","interactive-brokers","rust"],"backgroundTag":"value-out-of-range","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"}