<html>
    <head>
      <base href="https://bugs.documentfoundation.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:albrecht.mueller@astrail.de" title="Albrecht Müller <albrecht.mueller@astrail.de>"> <span class="fn">Albrecht Müller</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED - FORMATTING - Wrong date substraction in cell's operation"
   href="https://bugs.documentfoundation.org/show_bug.cgi?id=132083">bug 132083</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>RESOLVED
           </td>
           <td>REOPENED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>NOTABUG
           </td>
           <td>---
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED - FORMATTING - Wrong date substraction in cell's operation"
   href="https://bugs.documentfoundation.org/show_bug.cgi?id=132083#c15">Comment # 15</a>
              on <a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED - FORMATTING - Wrong date substraction in cell's operation"
   href="https://bugs.documentfoundation.org/show_bug.cgi?id=132083">bug 132083</a>
              from <span class="vcard"><a class="email" href="mailto:albrecht.mueller@astrail.de" title="Albrecht Müller <albrecht.mueller@astrail.de>"> <span class="fn">Albrecht Müller</span></a>
</span></b>
        <pre>@Mike Kaganski:
If you look at the description of the bug the problem boils down that you
subtract 8 minutes from 18 minutes. A fourth grader should be able to tell you
that this gives 10 minutes. But Calcs actual result is 9. This is clearly
wrong. That is why I think this is a bug.

Especially as it is that simple I would classified this as a major bug.
Therefore I went to great lengths to analyse what went wrong, detected a can of
worms and tried to describe some of them in form of bug reports. The following
is just a summary of my findings:

LibreOffices provides a very simple mechanism for date and time calculations.
You can consider it as just a fancy representation of floating point numbers
which is good enough for many common date or time calculations. It fails as
soon as you have to deal with concepts such as daylight saving times.

Programs that are around for decades show that it is possible to use the
internal representation of date and time values in a way that the average user
will never notice the fact that the representation in general cannot represent
time values exactly. LibreOffice was one of those programs. <a class="bz_bug_link 
          bz_status_UNCONFIRMED "
   title="UNCONFIRMED - Regression: Incompatible changes in date/time arithmetic introduced between Version: 6.0.4.2 (x64) and version 6.2.6.2 (ubuntu)"
   href="show_bug.cgi?id=127334">Bug 127334</a> comment
8 seems to indicate that you understand how this can be achieved. The basic
idea: Use some basic unit of time such as a second or something that is an
integral fraction of a second, e.g. a millisecond. Round any values to the
nearest integral multiples of this basic unit. The rest of the calculations
uses integer multiples of the basic unit only. As these calculation are based
on integer values they are exact and consistent – no additional round off
errors will be introduced. With the right choice of this basic unit the round
off errors of the floating point calculations will almost never accumulate to a
degree that rounding will select the wrong time unit. Therefore a user will
almost never see effects caused by round off errors. I think this is how this
established industry standard works but I never saw a formal specification of
it. No fancy stuff like infinite precision or the like is required, just
careful rounding and integer arithmetic.

I think I could trace the source of the problems to a BrokenDateTimeSpec.
That’s why I gave <a class="bz_bug_link 
          bz_status_UNCONFIRMED "
   title="UNCONFIRMED - Regression: Incompatible changes in date/time arithmetic introduced between Version: 6.0.4.2 (x64) and version 6.2.6.2 (ubuntu)"
   href="show_bug.cgi?id=127334">bug 127334</a> this alias which recently has been removed. Why?

The problem is that this spec does not specify the essential features of the
LibreOffice time calculation mechanism. I did not find any specification that
states what a concept of "wall clock time" or "duration" means. Given the crude
approximation of date and time calculations does it make sense to use the full
power of double floating point precision? If you really want to do this you
have to be specific about the meaning of the number 1: At this level of
precision it matters if you define it as one revolution of the earth or as 24 *
60 * 60 seconds of an atomic clock. What about daylight saving times, time
zones, calendars defined by astronomical observations or depending on future
events you don’t know yet, leap seconds etc.? That is where things start to
become really complicated.

Instead the specification defines some algorithms for the MINUTE, SECOND etc.
functions that are contradictory (e.g. the SECOND function is supposed to
return integer values between 0 and 59, but also to round to the nearest
second. What shall this function return for 59.6 seconds?, see
<a href="http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.html#__RefHeading__1018202_715980110">http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.html#__RefHeading__1018202_715980110</a>
), use inconsistent rounding (the SECONDS function rounds to the next second,
the MINUTE function does not, see
<a href="http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.html#__RefHeading__1018194_715980110">http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.html#__RefHeading__1018194_715980110</a>
) and thus deviate from this established industry standard. I fear the authors
of this specification were not aware of the implications of their work.
Unfortunately I don’t know how to write a bug report against the specification
and I was not able to find someone to fix these problems.

The help information leaves out a lot of essential information. So I simply
don’t know what to expect if I use features like the [HH]:MM or HH:MM format
constructs (see
<a href="https://help.libreoffice.org/6.4/en-US/text/shared/01/05020301.html?&DbPAR=CALC&System=WIN#hd_id3155870">https://help.libreoffice.org/6.4/en-US/text/shared/01/05020301.html?&DbPAR=CALC&System=WIN#hd_id3155870</a>,
where is a reference to the special treatment of wall clock times or
durations?) or the various date and time functions.

These deficiencies leave a lot of room for different interpretations. In the
case at hand LibreOffice contains a pseudo random generator that essentially
uses the round off errors of floating point calculations to decide if it will
return a correct or a wrong value. This typically gives 50% correct values
where the user expects 100%. I think I saw a bug report which reported
essentially the same problem for text tables in Writer. There are other
problems related to these deficiencies, e.g. inconsistent results of date and
time functions.

I reopened this bug. Before you revert this to NOT A BUG again, please answer
the following questions:
- I think there should be pretty good reasons to justify a change that breaks
the billions of spreadsheets you mention in <a href="show_bug.cgi?id=132083#c13">comment #13</a>. The change causes
these spreadsheets to show pseudo random numbers where they used to show
correct results before. What are these reasons? I think an argument as in
<a href="show_bug.cgi?id=132083#c3">comment #3</a> is not sufficient. The intended semantics of some time information
may be something like "about three o'clock". In this case you need duration
time rounding for wall clock times. And we are talking about time frames that
are well below the milliseconds range.
- Do you really want do demonstrate that the quality standards of LibreOffice
are so low that the expected behaviour (definition of NOT A BUG!) of this
program is to produce wrong results where a fourth grader is expected to come
up with the right solutions?</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>