{"record":{"id":"cb6c99172a220174","repo":"risingwavelabs/risingwave","slug":"can-t-cast-string-to-time-expected-format-is-hh-m","errorCode":null,"errorMessage":"Can't cast string to time (expected format is HH:MM:SS[.D+{up to 6 digits}][Z] or HH:MM)","messagePattern":"Can't cast string to time \\(expected format is HH:MM:SS\\[\\.D\\+(.+?)\\]\\[Z\\] or HH:MM\\)","errorType":"validation","errorClass":"InvalidParamsError","httpStatus":null,"severity":"error","filePath":"src/common/src/types/datetime.rs","lineNumber":261,"sourceCode":"        Time::from_num_seconds_from_midnight_uncheck(secs, nano)\n    }\n}\n\n#[derive(Copy, Clone, Debug, Error)]\nenum ErrorKind {\n    #[error(\"Invalid date: days: {days}\")]\n    Date { days: i32 },\n    #[error(\"Invalid time: secs: {secs}, nanoseconds: {nsecs}\")]\n    Time { secs: u32, nsecs: u32 },\n    #[error(\"Invalid time: {value} {unit} is out of range for a time of day\")]\n    TimeOfDay { value: u64, unit: &'static str },\n    #[error(\"Invalid datetime: seconds: {secs}, nanoseconds: {nsecs}\")]\n    DateTime { secs: i64, nsecs: u32 },\n    #[error(\"Invalid datetime: {value} {unit} is out of range\")]\n    Timestamp { value: i64, unit: &'static str },\n    #[error(\"Can't cast string to date (expected format is YYYY-MM-DD)\")]\n    ParseDate,\n    #[error(\n        \"Can't cast string to time (expected format is HH:MM:SS[.D+{{up to 6 digits}}][Z] or HH:MM)\"\n    )]\n    ParseTime,\n    #[error(\n        \"Can't cast string to timestamp (expected format is YYYY-MM-DD HH:MM:SS[.D+{{up to 9 digits}}] or YYYY-MM-DD HH:MM or YYYY-MM-DD or ISO 8601 format)\"\n    )]\n    ParseTimestamp,\n}\n\n#[derive(Debug, Error)]\n#[error(transparent)]\npub struct InvalidParamsError(#[from] ErrorKind);\n\nimpl InvalidParamsError {\n    pub fn date(days: i32) -> Self {\n        ErrorKind::Date { days }.into()\n    }\n","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/common/src/types/datetime.rs#L243-L279","documentation":"ErrorKind::ParseTime is thrown by Time::from_str when speedate::Time::parse_str rejects the input. Accepted shapes are HH:MM:SS[.fraction up to 6 digits][Z] or HH:MM; anything else (e.g. 12-hour clock with AM/PM, missing colon) fails.","triggerScenarios":"Casting strings like '4:05 PM', '040506', or '25:00' to TIME; a trailing 'Z' is stripped and ignored, but full timezone offsets like '+08:00' are not accepted.","commonSituations":"Ingesting logs that use 12-hour AM/PM times; timezone-suffixed times from ISO sources; data exports with zero-padded-omitted components.","solutions":["Normalize the input to 24-hour HH:MM:SS(.ffffff) format before casting.","Strip timezone suffixes other than 'Z' and convert to the desired clock time beforehand.","Increase fraction precision at the source if more than 6 fractional digits are being sent (only 6 are supported)."],"exampleFix":"// before\nlet t = Time::from_str(\"04:05:06 PM\")?;\n// after\nlet t = Time::from_str(\"16:05:06\")?;","handlingStrategy":"validation","validationCode":"fn is_parseable_time(s: &str) -> bool {\n    let s = s.trim_end_matches('Z');\n    regex::Regex::new(r\"^\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,6})?)?$\").unwrap().is_match(s)\n}","typeGuard":"fn looks_like_time(s: &str) -> bool {\n    let parts: Vec<&str> = s.trim_end_matches('Z').split(':').collect();\n    (2..=3).contains(&parts.len()) && parts.iter().all(|p| !p.is_empty() && p.chars().all(|c| c.is_ascii_digit() || c == '.'))\n}","tryCatchPattern":"let t = Time::from_str(s)\n    .map_err(|e| anyhow!(\"'{s}' is not HH:MM:SS[.ffffff][Z] or HH:MM: {e}\"))?;","preventionTips":["Convert 12-hour AM/PM times to 24-hour before casting.","Strip or convert timezone suffixes; only 'Z' is tolerated.","Limit fractional digits to 6 (microsecond precision)."],"tags":["rust","time","parsing","sql-cast"],"backgroundTag":"invalid-date-format","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}