{"record":{"id":"4870858f66211fdf","repo":"nautechsystems/nautilus_trader","slug":"failed-to-parse-iso-8601-string-date-string","errorCode":null,"errorMessage":"Failed to parse ISO 8601 string '{date_string}': {e}","messagePattern":"Failed to parse ISO 8601 string '(.+?)': (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/core/src/datetime.rs","lineNumber":454,"sourceCode":"///\n/// - `date_string`: The ISO 8601 formatted date string to parse\n///\n/// # Returns\n///\n/// Returns `Ok(UnixNanos)` if the string is successfully parsed, or an error if the format\n/// is invalid or the timestamp is out of range.\n///\n/// # Errors\n///\n/// Returns an error if:\n/// - The string format is not a valid ISO 8601 format\n/// - The timestamp is out of range for `UnixNanos`\n/// - The date/time values are invalid\n#[inline]\npub fn iso8601_to_unix_nanos(date_string: &str) -> anyhow::Result<UnixNanos> {\n    date_string\n        .parse::<UnixNanos>()\n        .map_err(|e| anyhow::anyhow!(\"Failed to parse ISO 8601 string '{date_string}': {e}\"))\n}\n\n/// Converts a UNIX nanoseconds timestamp to an ISO 8601 (RFC 3339) format string\n/// with millisecond precision.\n///\n/// All [`UnixNanos`] values are representable by this formatter.\n#[inline]\n#[must_use]\npub fn unix_nanos_to_iso8601_millis(unix_nanos: UnixNanos) -> String {\n    let parts = split_unix_nanos(unix_nanos);\n\n    let mut out = String::with_capacity(24);\n    push_iso8601_prefix(\n        &mut out,\n        parts.year,\n        parts.month,\n        parts.day,\n        parts.hour,","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/core/src/datetime.rs#L436-L472","documentation":"iso8601_to_unix_nanos delegates to `str::parse::<UnixNanos>`, and when parsing fails it wraps the underlying parse error with the offending string. It means the input string was not recognized as a valid ISO 8601 / RFC 3339 timestamp (or was out of range for UnixNanos). The library throws it because a free-form string cannot be safely converted to a nanosecond UNIX timestamp without strict validation.","triggerScenarios":"Calling iso8601_to_unix_nanos (or iso_to_unix_nanos) with a malformed string: missing timezone (e.g. \"2024-01-01 00:00:00\" without offset), wrong separator (space instead of 'T' when required), fractional precision beyond supported format, empty string, or a timestamp outside the u64-nanosecond range (pre-1970 dates).","commonSituations":"Feeding user-supplied or config-file datetimes straight in; log timestamps in non-RFC3339 formats; Python callers passing datetime.strftime output without timezone; data from exchanges using \"YYYYMMDD\" or epoch-millis strings; negative/pre-epoch dates that overflow UnixNanos (u64).","solutions":["Validate and normalize the string to RFC 3339 before calling, e.g. ensure a 'T' separator and a 'Z'/offset suffix.","Print the inner parse error (it is included in the message) to see exactly which part of the format jiff rejected.","If the value is a plain epoch number, parse it as an integer and construct UnixNanos directly instead of ISO parsing.","For pre-1970 timestamps, switch to a signed representation at the call site; UnixNanos is u64 and cannot hold them."],"exampleFix":"// before\nlet ns = iso8601_to_unix_nanos(\"2024-01-01 00:00:00\")?; // no offset -> parse error\n// after\nlet ns = iso8601_to_unix_nanos(\"2024-01-01T00:00:00Z\")?;","handlingStrategy":"validation","validationCode":"// Rust: validate RFC 3339 shape before calling\nfn is_rfc3339(s: &str) -> bool {\n    s.len() >= 20 && s.as_bytes()[10] == b'T' && (s.ends_with('Z') || s.contains('+') || s.contains('-'))\n}\nif !is_rfc3339(date_string) { /* normalize or reject */ }","typeGuard":null,"tryCatchPattern":"match iso8601_to_unix_nanos(s) {\n    Ok(ns) => ns,\n    Err(e) => { log::warn!(\"bad timestamp {s}: {e}\"); return Err(e); }\n}","preventionTips":["Always emit timestamps as RFC 3339 with explicit UTC offset ('Z').","Never pass pre-1970 dates into UnixNanos-based APIs.","Log the raw string alongside the error for quick diagnosis."],"tags":["datetime","parsing","iso8601","rust"],"backgroundTag":"invalid-date-format","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"}