[Libreoffice] Class Time and its funny ideas about time

Eike Rathke ooo at erack.de
Thu Aug 11 08:58:08 PDT 2011


Hi Lubos,

On Thursday, 2011-08-11 14:43:28 +0200, Lubos Lunak wrote:

> #include <tools/time.hxx>
> ...
> printf( "%d\n", Time( 25, 0, 0 ).GetHour());
> printf( "%d\n", ( Time( 1, 0, 10 ) - Time( 1, 0, 20 )).GetSec());
> 
> 25
> 10
> 
>  As much as I don't like it, I can possibly see at least some reason for time 
> having 25 hours, but 10 seconds without 20 seconds being 10 seconds (and 
> there is actually explicit code to ensure that)?
> 
>  Does somebody know why the Time class does either of these and how much would 
> break if I fixed these two to be sane?

1) Time can be (mis)used for duration/delta times. While this is fine in
   most cases, it is limited to the internal representation and hence
   overflows at some point which unfortunately not all developers using
   it may have been aware of.

2) Why should GetSec() of a negative delta return a negative amount of
   seconds?

Don't "fix" #1 unless having clarified delta usage in all code and
introduced a DeltaTime or Duration class to replace with.

The probability that something would break if you just "fixed" #2 is
quite high. The only way to make sure is to temporarily make the methods
private, build the entire office and inspect each and every place the
compiler complains about.

  Eike

-- 
 PGP/OpenPGP/GnuPG encrypted mail preferred in all private communication.
 Key ID: 0x293C05FD - 997A 4C60 CE41 0149 0DB3  9E96 2F1A D073 293C 05FD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20110811/e923924a/attachment-0001.pgp>


More information about the LibreOffice mailing list