{"record":{"id":"261d6ab4933f7c40","repo":"pola-rs/polars","slug":"timezone-tz-is-invalid-or-not-supported","errorCode":null,"errorMessage":"Timezone {tz} is invalid or not supported","messagePattern":"Timezone (.+?) is invalid or not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-json/src/json/write/serialize.rs","lineNumber":476,"sourceCode":"\n            materialize_serializer(f, array.iter(), offset, take)\n        },\n        #[cfg(feature = \"timezones\")]\n        _ => match parse_offset_tz(tz) {\n            Ok(parsed_tz) => {\n                let f = move |x: Option<&i64>, buf: &mut Vec<u8>| {\n                    if let Some(x) = x {\n                        let dt_str = timestamp_to_datetime(*x, time_unit, &parsed_tz).to_rfc3339();\n                        write!(buf, \"\\\"{dt_str}\\\"\").unwrap();\n                    } else {\n                        buf.extend_from_slice(b\"null\")\n                    }\n                };\n\n                materialize_serializer(f, array.iter(), offset, take)\n            },\n            _ => {\n                panic!(\"Timezone {tz} is invalid or not supported\");\n            },\n        },\n        #[cfg(not(feature = \"timezones\"))]\n        _ => {\n            panic!(\"Invalid Offset format (must be [-]00:00) or timezones feature not active\");\n        },\n    }\n}\n\npub fn new_serializer<'a>(\n    array: &'a dyn Array,\n    offset: usize,\n    take: usize,\n) -> Box<dyn JsonSerializer<Item = [u8]> + 'a + Send + Sync> {\n    match array.dtype().to_storage() {\n        ArrowDataType::Boolean => {\n            boolean_serializer(array.as_any().downcast_ref().unwrap(), offset, take)\n        },","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-json/src/json/write/serialize.rs#L458-L494","documentation":"When serializing timestamps with a timezone, timestamp_tz_serializer looks up the fixed offset for the timezone string; with the 'timezones' feature enabled, an unrecognized/invalid tz (not a fixed offset like +02:00 and not a valid IANA zone) reaches a panic arm reading 'Timezone {tz} is invalid or not supported'.","triggerScenarios":"Calling new_serializer on a Timestamp array whose TimeUnit has a timezone string that is neither a valid fixed offset nor a known IANA timezone, on builds with feature = \"timezones\" — e.g. via JSON writing of a timestamp column with a misspelled tz like 'UTC+2' or 'America'.","commonSituations":"Timezone strings produced by another system in non-IANA format ('UTC+02:00', 'GMT-5'); truncated tz names; locale-specific zone aliases; writing JSON from data read with a bad tz configured.","solutions":["Use a valid fixed offset format '[-]HH:MM' (e.g. '+02:00') or a proper IANA name (e.g. 'Europe/Amsterdam').","Validate the tz with chrono-tz / polars timezone utilities before serializing.","Cast the column to a naive timestamp or UTC before JSON output if the original tz is not needed.","Fix the producer that wrote the malformed timezone into the metadata."],"exampleFix":"// before\n\"timezone\": \"UTC+2\"\n// after\n\"timezone\": \"+02:00\"  // or \"Etc/GMT-2\"","handlingStrategy":"validation","validationCode":"fn tz_is_supported(tz: &str) -> bool {\n    // fixed offset [-]HH:MM\n    let bytes = tz.as_bytes();\n    let fixed = tz.len() == 6 && (bytes[0] == b'+' || bytes[0] == b'-')\n        && tz[1..3].parse::<u8>().map(|h| h < 24).unwrap_or(false)\n        && &tz[3..4] == \":\"\n        && tz[4..6].parse::<u8>().map(|m| m < 60).unwrap_or(false);\n    fixed || chrono_tz::Tz::from_str(tz).is_ok()\n}\nassert!(tz_is_supported(tz), \"unsupported timezone: {tz}\");","typeGuard":"fn parse_tz(tz: &str) -> Option<String> {\n    chrono_tz::Tz::from_str(tz).ok().map(|_| tz.to_string())\n        .or_else(|| validate_fixed_offset(tz))\n}","tryCatchPattern":"// panic arm; validate the timestamp metadata before serializing\nlet tz = timestamp_meta.timezone.as_deref().unwrap_or(\"UTC\");\nassert!(tz_is_supported(tz), \"bad tz {tz}; cast column to UTC first\");","preventionTips":["Store only IANA names ('Europe/Paris') or canonical fixed offsets ('+02:00') in metadata","Normalize producer-side tz formats ('UTC+2', 'GMT-5') on ingestion","Validate timezone strings when constructing timestamp columns, not at write time"],"tags":["timezone","json","serialization","panic"],"backgroundTag":"invalid-argument-format","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"}