Skip to content

Commit

Permalink
Merge pull request #35 from dimastbk/fix-time1904
Browse files Browse the repository at this point in the history
fix: detect time with 1904 datesystem
  • Loading branch information
dimastbk authored Sep 4, 2023
2 parents d9c03b7 + 9a37c32 commit b83050b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/types/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b83050b

Please sign in to comment.