{"record":{"id":"830c91ce85a03a93","repo":"pola-rs/polars","slug":"invalid-time","errorCode":null,"errorMessage":"invalid time","messagePattern":"invalid time","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-arrow/src/temporal_conversions.rs","lineNumber":73,"sourceCode":"\n/// converts a `i64` representing a `date64` to [`NaiveDateTime`]\n#[inline]\npub fn date64_to_datetime(v: i64) -> NaiveDateTime {\n    TimeDelta::try_milliseconds(v)\n        .and_then(|delta| unix_epoch().checked_add_signed(delta))\n        .expect(\"invalid or out-of-range datetime\")\n}\n\n/// converts a `i64` representing a `date64` to [`NaiveDate`]\n#[inline]\npub fn date64_to_date(milliseconds: i64) -> NaiveDate {\n    date64_to_datetime(milliseconds).date()\n}\n\n/// converts a `i32` representing a `time32(s)` to [`NaiveTime`]\n#[inline]\npub fn time32s_to_time(v: i32) -> NaiveTime {\n    NaiveTime::from_num_seconds_from_midnight_opt(v as u32, 0).expect(\"invalid time\")\n}\n\n/// converts a `i64` representing a `duration(s)` to [`Duration`]\n#[inline]\npub fn duration_s_to_duration(v: i64) -> Duration {\n    Duration::try_seconds(v).expect(\"out-of-range duration\")\n}\n\n/// converts a `i64` representing a `duration(ms)` to [`Duration`]\n#[inline]\npub fn duration_ms_to_duration(v: i64) -> Duration {\n    Duration::try_milliseconds(v).expect(\"out-of-range in duration conversion\")\n}\n\n/// converts a `i64` representing a `duration(us)` to [`Duration`]\n#[inline]\npub fn duration_us_to_duration(v: i64) -> Duration {\n    Duration::microseconds(v)","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-arrow/src/temporal_conversions.rs#L55-L91","documentation":"`time32s_to_time` converts an i32 `time32(s)` value (seconds since midnight) into a `NaiveTime` using `NaiveTime::from_num_seconds_from_midnight_opt`. If the second count is not a valid time-of-day (negative values cast to u32 wrap to huge numbers), the Option is `None` and the wrapper panics with \"invalid time\".","triggerScenarios":"Calling `time32s_to_time(v)` with `v < 0` (cast `v as u32` wraps) or `v >= 86400`, producing an invalid seconds-since-midnight value.","commonSituations":"Negative sentinel values in time32 columns; data written with a different unit (e.g. total seconds of a duration rather than time-of-day); dirty CSV/parquet imports.","solutions":["Validate `0 <= v < 86_400` before calling the converter.","Use the fallible `NaiveTime::from_num_seconds_from_midnight_opt(v as u32, 0)` directly and handle `None`.","Clean the column of negative/overflow values before conversion."],"exampleFix":"// before\nlet t = time32s_to_time(v); // panics for v<0 or v>=86400\n// after\nif (0..86_400).contains(&v) {\n    let t = time32s_to_time(v);\n} else {\n    return Err(anyhow!(\"invalid time32 seconds: {v}\"));\n}","handlingStrategy":"validation","validationCode":"fn valid_time32s(v: i32) -> bool {\n    (0..86_400).contains(&v)\n}","typeGuard":null,"tryCatchPattern":"if valid_time32s(v) {\n    let t = time32s_to_time(v);\n} else {\n    // reject or null-out the value\n}","preventionTips":["Range-check seconds-since-midnight values (0..86400) on ingest","Treat negative time values as data corruption, not valid input","Distinguish time32 columns from duration columns at schema level"],"tags":["arrow","chrono","time","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}