New class tools::Duration

Eike Rathke erack at redhat.com
Mon Jun 19 12:25:16 UTC 2023


Hi,

Commit
https://git.libreoffice.org/core/+/eac63ab120a181a1dff6317ee3d223327080e992%5E!/
introduced class tools::Duration (sal_Int32 days plus tools:Time) with
include/tools/duration.hxx that integrates with class DateTime to
calculate DateTime+Duration. Furthermore it can convert from
"TimeInDays" double values and corrects slight binary floating point
inaccuracies off by a nanosecond and handles Add() and Mult()
operations.

Code that still abuses tools::Time for (limited in capacity, i.e.
sal_uInt16 hours, ~7 years) durations should be considered to be
rewritten using tools::Duration, also code that subtracts two DateTime
values to obtain a double for duration should be converted to a proper
tools::Duration to diminish floating point inaccuracy. The same for code
that subtracts two double values that are known to originate from
DateTime values.

Once done, we could change

    friend double   operator -( const DateTime& rDateTime1, const DateTime& rDateTime2 );

to

    friend tools::Duration operator -( const DateTime& rDateTime1, const DateTime& rDateTime2 );

(you can also use that temporarily to find code places to change).

Happy conversion..

  Eike

-- 
GPG key 0x6A6CD5B765632D3A - 2265 D7F3 A7B0 95CC 3918  630B 6A6C D5B7 6563 2D3A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20230619/19030a15/attachment.sig>


More information about the LibreOffice mailing list