calamine icon indicating copy to clipboard operation
calamine copied to clipboard

"dates" feature is not accurate enough, maybe

Open usagi opened this issue 3 years ago • 0 comments

The dates feature is not accurate enough.

Actual:

  1. Make the xlsx file with the value 2021-10-15 19:00:00 of DateTime typed.
  2. Read the value using as_date() with features=["dates"]
  3. The result is "2021-10-15 18:59:59.999999761".

Expected:

  • The result is "2021-10-15 19:00:00".

Guessing:

  • Maybe, this constant is not accurate enough:
    • https://github.com/tafia/calamine/blob/master/src/datatype.rs#L127

FYI:

I was tested in the below code, and it was taken the correct result.

pub fn to_naive_from_excel_datetime(v: f64) -> NaiveDateTime
{
 let excel_epoch = NaiveDate::from_ymd(1899, 12, 30).and_hms(0, 0, 0);
 let h = v * 24f64;
 let m = h * 60f64;
 let s = m * 60f64;
 let ms = s * 1e+3f64;
 let excel_duration = Duration::milliseconds(ms as i64);
 excel_epoch + excel_duration
}

But, I know this implementation has an overheads and you don't like the explainly implements maybe. Therefore, I didn't PR and just write the issue only.

usagi avatar Jan 23 '22 16:01 usagi