{"record":{"id":"d540308e43895698","repo":"databendlabs/databend","slug":"epoch-date-is-valid","errorCode":null,"errorMessage":"epoch date is valid","messagePattern":"epoch date is valid","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/query/expression/src/types/date.rs","lineNumber":50,"sourceCode":"use super::number::SimpleDomain;\nuse crate::ColumnBuilder;\nuse crate::ScalarRef;\nuse crate::property::Domain;\nuse crate::values::Column;\nuse crate::values::Scalar;\n\npub const DATE_FORMAT: &str = \"%Y-%m-%d\";\n/// SQL DATE bounds, represented as days since 1970-01-01.\n/// Calendar inputs and computed DATE values both use years 0001..=9999.\n/// 0001-01-01\npub const DATE_MIN: i32 = -719_162;\n/// 9999-12-31\npub const DATE_MAX: i32 = 2_932_896;\n\n/// Converts internal epoch days. SQL inputs must pass `check_date` first.\npub fn date_from_days(days: impl AsPrimitive<i64>) -> NaiveDate {\n    NaiveDate::from_ymd_opt(1970, 1, 1)\n        .expect(\"epoch date is valid\")\n        .checked_add_signed(TimeDelta::days(days.as_()))\n        .expect(\"date day count is inside the chrono civil range\")\n}\n\n/// Preserve the legacy conversion policy: either bound overflow maps to DATE_MIN.\n#[inline]\npub fn clamp_date(days: i64) -> i32 {\n    if (DATE_MIN as i64..=DATE_MAX as i64).contains(&days) {\n        days as i32\n    } else {\n        DATE_MIN\n    }\n}\n\n/// Validate the SQL DATE range without silently changing the value.\n#[inline]\npub fn check_date(days: i64) -> Result<i32, String> {\n    if (i64::from(DATE_MIN)..=i64::from(DATE_MAX)).contains(&days) {","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/expression/src/types/date.rs#L32-L68","documentation":"date_from_days converts internal epoch-day integers to a chrono NaiveDate. The first expect — 'epoch date is valid' — builds the fixed base date 1970-01-01. This can only panic if chrono itself fails to construct the epoch date, which is impossible with a valid chrono build; it exists so the Option from from_ymd_opt is explicitly handled. In practice it is an unreachable internal invariant.","triggerScenarios":"Effectively never triggered by callers; would only fire if the chrono crate were broken or the constant 1970/1/1 were out of chrono's supported range (it is not).","commonSituations":"Not user-reachable; seen only when debugging chrono version mismatches or when refactoring the constants to an invalid date.","solutions":["No caller action needed; treat a panic here as a chrono/dependency bug.","If refactoring, keep the base date within chrono's civil range (years 0..=9999 for NaiveDate construction bounds)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Not required; this panic is unreachable. Validate SQL inputs instead:\ncheck_date(days)?;\nlet d = date_from_days(days);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["No guard needed; treat a panic here as a chrono dependency bug and file an issue."],"tags":["panic","date","unreachable"],"backgroundTag":"internal-invariant-violation","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}