From bda9288ffee552b55eed9dbf02e1204957bd4513 Mon Sep 17 00:00:00 2001 From: Winfried Donkers Date: Thu, 19 Jul 2018 12:05:14 +0200 Subject: tdf#118800 fix rounding error in Calc function HOUR, MINUTE, SECOND. Change-Id: I7a875b172493112b66fca8f70d2061371a05486c Reviewed-on: https://gerrit.libreoffice.org/57721 Tested-by: Jenkins Reviewed-by: Eike Rathke (cherry picked from commit c69e7266916ac1b8917477fb4eccdb9098da5792) Reviewed-on: https://gerrit.libreoffice.org/57728 --- sc/qa/unit/data/functions/date_time/fods/hour.fods | 31 ++++++++++++++++------ .../unit/data/functions/date_time/fods/minute.fods | 26 ++++++++++++++++-- .../unit/data/functions/date_time/fods/second.fods | 26 ++++++++++++++++-- sc/source/core/tool/interpr2.cxx | 6 ++--- 4 files changed, 74 insertions(+), 15 deletions(-) diff --git a/sc/qa/unit/data/functions/date_time/fods/hour.fods b/sc/qa/unit/data/functions/date_time/fods/hour.fods index 847632a9750a..bb5abc52ab4e 100644 --- a/sc/qa/unit/data/functions/date_time/fods/hour.fods +++ b/sc/qa/unit/data/functions/date_time/fods/hour.fods @@ -154,8 +154,8 @@ Function basISODateTime(dVal#) basISODateTime = format(year(dt),"0000")&"-"& format(Month(dt),"00")&"-"& format(day(dt),"00")&" "& format(Hour(dt),"00")&":"& format(Minute(dt),"00")&":"& format(Second(dt),"00") End Function - - + + @@ -1755,11 +1755,26 @@ End Function - - - - - + + 10 + + + 10 + + + TRUE + + + =HOUR(J10) + + + tdf11880 + + + + 10:59:59.60 + + @@ -2432,4 +2447,4 @@ End Function - \ No newline at end of file + diff --git a/sc/qa/unit/data/functions/date_time/fods/minute.fods b/sc/qa/unit/data/functions/date_time/fods/minute.fods index d27ec1ef5031..69fba0187454 100644 --- a/sc/qa/unit/data/functions/date_time/fods/minute.fods +++ b/sc/qa/unit/data/functions/date_time/fods/minute.fods @@ -896,7 +896,29 @@ - + + + 11 + + + 11 + + + TRUE + + + =MINUTE(J9) + + + tdf11880 + + + + 10:11:59.60 + + + + @@ -1105,4 +1127,4 @@ - \ No newline at end of file + diff --git a/sc/qa/unit/data/functions/date_time/fods/second.fods b/sc/qa/unit/data/functions/date_time/fods/second.fods index e6d2b46946e5..8db288ae3ae9 100644 --- a/sc/qa/unit/data/functions/date_time/fods/second.fods +++ b/sc/qa/unit/data/functions/date_time/fods/second.fods @@ -825,7 +825,29 @@ - + + + 12 + + + 12 + + + TRUE + + + =SECOND(J9) + + + tdf11880 + + + + 10:11:12.60 + + + + @@ -1034,4 +1056,4 @@ - \ No newline at end of file + diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index 45cefa1d0423..debe3509eb44 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -146,7 +146,7 @@ void ScInterpreter::ScGetMin() { double fTime = GetDouble(); fTime -= ::rtl::math::approxFloor(fTime); // date part absent - long nVal = static_cast(::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR+0.5)) % ::tools::Time::secondPerHour; + long nVal = static_cast(::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR)) % ::tools::Time::secondPerHour; PushDouble( static_cast(nVal / ::tools::Time::secondPerMinute) ); } @@ -154,7 +154,7 @@ void ScInterpreter::ScGetSec() { double fTime = GetDouble(); fTime -= ::rtl::math::approxFloor(fTime); // date part absent - long nVal = static_cast(::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR+0.5)) % ::tools::Time::secondPerMinute; + long nVal = static_cast(::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR)) % ::tools::Time::secondPerMinute; PushDouble( static_cast(nVal) ); } @@ -162,7 +162,7 @@ void ScInterpreter::ScGetHour() { double fTime = GetDouble(); fTime -= ::rtl::math::approxFloor(fTime); // date part absent - long nVal = static_cast(::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR+0.5)) / ::tools::Time::secondPerHour; + long nVal = static_cast(::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR)) / ::tools::Time::secondPerHour; PushDouble(static_cast(nVal)); } -- cgit v1.2.3