From 9a37c326fa4122e9fc4f564e722c6c7818d4102f Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Mon, 4 Sep 2023 15:49:13 +0600 Subject: [PATCH] fix: detect time with 1904 datesystem --- src/types/cell.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/types/cell.rs b/src/types/cell.rs index 55f3d7b..fa01f5b 100644 --- a/src/types/cell.rs +++ b/src/types/cell.rs @@ -3,6 +3,9 @@ use std::convert::From; use calamine::DataType; use pyo3::prelude::*; +/// https://learn.microsoft.com/en-us/office/troubleshoot/excel/1900-and-1904-date-system +static EXCEL_1900_1904_DIFF: f64 = 1462.0; + #[derive(Debug)] pub enum CellValue { Int(i64), @@ -39,7 +42,9 @@ impl From<&DataType> for CellValue { DataType::Float(v) => CellValue::Float(v.to_owned()), DataType::String(v) => CellValue::String(String::from(v)), DataType::DateTime(v) => { - if v < &1.0 { + // FIXME: need to fix after fixing in calamine + if v < &1.0 || (*v - EXCEL_1900_1904_DIFF < 1.0 && *v - EXCEL_1900_1904_DIFF > 0.0) + { value.as_time().map(CellValue::Time) } else if *v == (*v as u64) as f64 { value.as_date().map(CellValue::Date)