{"record":{"id":"288b1ebe77392aa8","repo":"quickwit-oss/quickwit","slug":"failed-to-parse-date-time","errorCode":null,"errorMessage":"Failed to parse date time: {}","messagePattern":"Failed to parse date time: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-query/src/elastic_query_dsl/range_query.rs","lineNumber":133,"sourceCode":"            upper_bound: match (lt, lte) {\n                (Some(_lt), Some(_lte)) => {\n                    anyhow::bail!(\"both lt and lte are set\")\n                }\n                (Some(lt), None) => Bound::Excluded(lt),\n                (None, Some(lte)) => Bound::Included(lte),\n                (None, None) => Bound::Unbounded,\n            },\n        };\n        let ast: QueryAst = range_query_ast.into();\n        Ok(ast.boost(boost))\n    }\n}\n\nfn parse_and_convert(literal: JsonLiteral, parser: &StrptimeParser) -> anyhow::Result<JsonLiteral> {\n    if let JsonLiteral::String(date_time_str) = literal {\n        let parsed_date_time = parser\n            .parse_date_time(&date_time_str)\n            .map_err(|reason| anyhow::anyhow!(\"Failed to parse date time: {}\", reason))?;\n        let parsed_date_time_rfc3339 = parsed_date_time.format(&Rfc3339)?;\n        Ok(JsonLiteral::String(parsed_date_time_rfc3339))\n    } else {\n        Ok(literal)\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use std::ops::Bound;\n\n    use super::{RangeQuery as ElasticRangeQuery, RangeQueryParams as ElasticRangeQueryParams};\n    use crate::JsonLiteral;\n    use crate::elastic_query_dsl::ConvertibleToQueryAst;\n    use crate::query_ast::{QueryAst, RangeQuery};\n\n    #[test]\n    fn test_date_range_query_with_format() {","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-query/src/elastic_query_dsl/range_query.rs#L115-L151","documentation":"parse_and_convert takes a string date literal from a range query and parses it with the configured StrptimeParser, converting the result to RFC3339. This error is raised when the date-time string does not match the expected format — the inner reason carries the parser's explanation of where parsing failed.","triggerScenarios":"A range query provides gt/gte/lt/le values as strings that don't conform to the declared format — e.g. \"01/02/2024\" against format \"yyyy-MM-dd\", or \"now-1d\" style expressions with a strict strptime format.","commonSituations":"Users passing Elasticsearch date math (now-1h/d) or locale-formatted dates to range queries; timezone-naive strings against a format expecting offsets; wrong field ordering in the date string.","solutions":["Format the date literal to match the query's declared format exactly (e.g. \"2024-01-02 15:04:05\" for \"yyyy-MM-dd HH:mm:ss\")","Use RFC3339 (\"2024-01-02T15:04:05Z\") and drop the custom format","Replace date-math expressions (now-1d) with computed absolute timestamps","Include the timezone offset in the string if the format expects one"],"exampleFix":"// before\n{\"range\": {\"ts\": {\"gte\": \"now-1d\", \"format\": \"yyyy-MM-dd HH:mm:ss\"}}}\n// after\n{\"range\": {\"ts\": {\"gte\": \"2026-09-07 00:00:00\", \"format\": \"yyyy-MM-dd HH:mm:ss\"}}}","handlingStrategy":"validation","validationCode":"function isValidDate(s, fmt) {\n  try { parseWithStrptime(s, fmt); return true; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"match convert_to_query_ast(json, ...) {\n    Err(e) if e.to_string().contains(\"Failed to parse date time\") => { /* surface user-facing message with expected format */ }\n    Err(e) => return Err(e),\n    Ok(ast) => ast,\n}","preventionTips":["Format date literals to match the declared format exactly","Use RFC3339 with explicit timezone offsets","Resolve date-math (now-1d) client-side before sending"],"tags":["query-dsl","date-parsing","strptime","elasticsearch-compat"],"backgroundTag":"invalid-date-format","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}