From 6fd41d626b709dcf52cbc0fb8955e7ffc81900dc Mon Sep 17 00:00:00 2001 From: nihilist-narwhal <240798405+nihilist-narwhal@users.noreply.github.com> Date: Sat, 10 Oct 2026 01:04:08 -0500 Subject: [PATCH] Typed dates before 1900 stay text 7/4/1776 was entered as 7/4/3676 and DATEVALUE("12/31/1899") gave 693962: the text parser built dates with DATE()'s rule that adds 1900 to years below 1900. Excel keeps such entries as text, and DATEVALUE gives #VALUE!. --- crates/core/src/parse.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/core/src/parse.rs b/crates/core/src/parse.rs index 7169ae5..94bb0a9 100644 --- a/crates/core/src/parse.rs +++ b/crates/core/src/parse.rs @@ -263,7 +263,8 @@ fn parse_date(t: &str, sys: DateSystem) -> Option<(f64, &'static str)> { } fn valid_ymd(sys: DateSystem, y: i64, m: i64, d: i64) -> Option { - if !(1..=12).contains(&m) || d < 1 { + // Dates before 1900 stay text (`DATE()` would add 1900 to such a year). + if !(1..=12).contains(&m) || d < 1 || y < 1900 { return None; } let max = crate::date::days_in_month_in(sys, y as i32, m as u32) as i64; @@ -352,6 +353,11 @@ mod tests { assert_eq!(p("7-Oct-2026").value, Value::Number(46302.0)); assert_eq!(p("Oct 7, 2026").value, Value::Number(46302.0)); assert_eq!(p("2/30/2026").value, Value::text("2/30/2026")); + assert_eq!(p("7/4/1776").value, Value::text("7/4/1776")); + assert_eq!(p("1776-07-04").value, Value::text("1776-07-04")); + assert_eq!(p("4-Jul-1776").value, Value::text("4-Jul-1776")); + assert_eq!(p("12/31/1899").value, Value::text("12/31/1899")); + assert_eq!(p("1/1/1900").value, Value::Number(1.0)); assert_eq!(p("12:00").value, Value::Number(0.5)); assert_eq!(p("6:00 PM").value, Value::Number(0.75)); assert_eq!(p("12:00 AM").value, Value::Number(0.0));