OpenXLSX icon indicating copy to clipboard operation
OpenXLSX copied to clipboard

Error in XLDateTime

Open dobiega opened this issue 2 years ago • 1 comments

Hi For serial number 43791.583333333299 returned date (at least hour) is not correct returned hour is 13:59:60 but shall be 14:00:00

dobiega avatar Mar 15 '22 09:03 dobiega

/**
 * @details Get the time point as a std::tm object.
 */
std::tm XLDateTime::tm() const
// ...

    // ===== Calculate the number of days.
    result.tm_mday = static_cast<int>(serial);
    serial -= result.tm_mday;
    // fix calculation accuracy <--
    auto tm_sec = static_cast<int>(lround(serial * 24 * 60 * 60));
    serial = tm_sec / (24.0 * 60.0 * 60.0);

    // ===== Calculate the number of hours.
    result.tm_hour = static_cast<int>(serial * 24);
    serial -= (result.tm_hour / 24.0);

// ...

jason-fan avatar Jun 04 '22 01:06 jason-fan