Skip to content

Commit b83050b

Browse files
authored
Merge pull request #35 from dimastbk/fix-time1904
fix: detect time with 1904 datesystem
2 parents d9c03b7 + 9a37c32 commit b83050b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/types/cell.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ use std::convert::From;
33
use calamine::DataType;
44
use pyo3::prelude::*;
55

6+
/// https://learn.microsoft.com/en-us/office/troubleshoot/excel/1900-and-1904-date-system
7+
static EXCEL_1900_1904_DIFF: f64 = 1462.0;
8+
69
#[derive(Debug)]
710
pub enum CellValue {
811
Int(i64),
@@ -39,7 +42,9 @@ impl From<&DataType> for CellValue {
3942
DataType::Float(v) => CellValue::Float(v.to_owned()),
4043
DataType::String(v) => CellValue::String(String::from(v)),
4144
DataType::DateTime(v) => {
42-
if v < &1.0 {
45+
// FIXME: need to fix after fixing in calamine
46+
if v < &1.0 || (*v - EXCEL_1900_1904_DIFF < 1.0 && *v - EXCEL_1900_1904_DIFF > 0.0)
47+
{
4348
value.as_time().map(CellValue::Time)
4449
} else if *v == (*v as u64) as f64 {
4550
value.as_date().map(CellValue::Date)

0 commit comments

Comments
 (0)