summaryrefslogtreecommitdiff
path: root/sc/source/core/tool/interpr2.cxx
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2018-08-28 13:46:37 +0200
committerEike Rathke <erack@redhat.com>2018-08-28 16:23:46 +0200
commit7f3c6efd859050c8f376b6820710e91fa9077ac4 (patch)
tree7b177de4a02917fcc4558794361fe076efdd5dad /sc/source/core/tool/interpr2.cxx
parentb57ed76361da672697eccd219b09bd358a967e0d (diff)
Move lcl_getHourMinuteSecond() to tools::Time::GetClock()
Also add fFractionOfSecond and nFractionDecimals to obtain the remaining fraction of second. In preparation to use this in the number formatter and other places that obtain the wall clock time particles, which likely so far use bad rounding as well. Change-Id: I4fbea4165c560646438b06c340756c97dafa7c78 Reviewed-on: https://gerrit.libreoffice.org/59700 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'sc/source/core/tool/interpr2.cxx')
-rw-r--r--sc/source/core/tool/interpr2.cxx56
1 files changed, 9 insertions, 47 deletions
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 92bd4ebd1aae..6adc434a3864 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -142,65 +142,27 @@ void ScInterpreter::ScGetDay()
PushDouble(static_cast<double>(aDate.GetDay()));
}
-/* TODO: move this to tools::Time so also SvNumberFormatter and everything else
- * can use it and all display the same values. */
-static void lcl_getHourMinuteSecond( double fTimeInDays, sal_Int32& nHour, sal_Int32& nMinute, sal_Int32& nSecond )
-{
- const double fTime = fTimeInDays - rtl::math::approxFloor(fTimeInDays); // date part absent
-
- // If 0 then full day (or no day), shortcut.
- // If < 0 then approxFloor() effectively returned the ceiling (note this
- // also holds for negative fTimeInDays values) because of a near identical
- // value, shortcut this to a full day as well.
- // If >= 1.0 (actually == 1.0) then fTimeInDays is a negative small value
- // not significant for a representable time and approxFloor() returned -1,
- // shortcut to 0:0:0, otherwise it would become 24:0:0.
- if (fTime <= 0.0 || fTime >= 1.0)
- {
- nHour = nMinute = nSecond = 0;
- return;
- }
-
- // In seconds, including milli and nano.
- const double fRawSeconds = fTime * DATE_TIME_FACTOR;
-
- // Round to nanoseconds, which is the highest resolution this could be
- // influenced by.
- double fSeconds = rtl::math::round( fRawSeconds, 9);
-
- // If this ended up as a full day the original value was very very close
- // but not quite. Take that.
- if (fSeconds >= tools::Time::secondPerDay)
- fSeconds = fRawSeconds;
-
- // Now do not round values (specifically not up), but truncate to the next
- // magnitude, so 23:59:59.99 is still 23:59:59 and not 24:00:00 (or even
- // 00:00:00 which Excel does).
- nHour = fSeconds / tools::Time::secondPerHour;
- fSeconds -= nHour * tools::Time::secondPerHour;
- nMinute = fSeconds / tools::Time::secondPerMinute;
- fSeconds -= nMinute * tools::Time::secondPerMinute;
- nSecond = fSeconds;
-}
-
void ScInterpreter::ScGetMin()
{
- sal_Int32 nHour, nMinute, nSecond;
- lcl_getHourMinuteSecond( GetDouble(), nHour, nMinute, nSecond);
+ sal_uInt16 nHour, nMinute, nSecond;
+ double fFractionOfSecond;
+ tools::Time::GetClock( GetDouble(), nHour, nMinute, nSecond, fFractionOfSecond, 0);
PushDouble( nMinute);
}
void ScInterpreter::ScGetSec()
{
- sal_Int32 nHour, nMinute, nSecond;
- lcl_getHourMinuteSecond( GetDouble(), nHour, nMinute, nSecond);
+ sal_uInt16 nHour, nMinute, nSecond;
+ double fFractionOfSecond;
+ tools::Time::GetClock( GetDouble(), nHour, nMinute, nSecond, fFractionOfSecond, 0);
PushDouble( nSecond);
}
void ScInterpreter::ScGetHour()
{
- sal_Int32 nHour, nMinute, nSecond;
- lcl_getHourMinuteSecond( GetDouble(), nHour, nMinute, nSecond);
+ sal_uInt16 nHour, nMinute, nSecond;
+ double fFractionOfSecond;
+ tools::Time::GetClock( GetDouble(), nHour, nMinute, nSecond, fFractionOfSecond, 0);
PushDouble( nHour);
}