Bug 144678 - Functions MONTHS and YEARS give wrong results for pre-1582-10-15 dates when used with last argument set to 1
Summary: Functions MONTHS and YEARS give wrong results for pre-1582-10-15 dates when u...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
3.4.0 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: implementationError
Depends on:
Blocks: Calc-Function
  Show dependency treegraph
 
Reported: 2021-09-23 09:49 UTC by Mike Kaganski
Modified: 2022-07-14 19:05 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2021-09-23 09:49:23 UTC
Consider the following spreadsheet formulas:

=MONTHS("1599-12-22";"1599-12-23";1)
=MONTHS("1599-12-31";"1600-01-01";1)
=YEARS("1599-12-22";"1599-12-23";1)
=YEARS("1599-12-31";"1600-01-01";1)

They return 0, 1, 0, and 1, respectively, as one would expect.

Now consider these:

=MONTHS("1499-12-22";"1499-12-23";1)
=MONTHS("1499-12-31";"1500-01-01";1)
=YEARS("1499-12-22";"1499-12-23";1)
=YEARS("1499-12-31";"1500-01-01";1)

They return 1, 0, 1, 0, respectively - which is completely unexpected.
The problem is, that the former set of formulas is after 1582-10-15, which is when Gregorian calendar was introduced, and the latter set is before that date; the dates sent to the functions in the latter set get converted to serial dates as Julian dates, but MONTHS and YEARS use proleptic Gregorian to determine the result when calculating with calendar months/years.

In OOo 3.2 and LO 3.3.0.4, the latter set resulted in #VALUE!; while LO 3.4.0.1 already produces the values described above. Not a regression though, rather implementation error?
Comment 1 Xisco Faulí 2021-09-29 09:57:07 UTC
Moving to NEW
Comment 2 raal 2022-07-14 19:05:47 UTC
*** Bug 149040 has been marked as a duplicate of this bug. ***