Bug 144678

Summary: Functions MONTHS and YEARS give wrong results for pre-1582-10-15 dates when used with last argument set to 1
Product: LibreOffice Reporter: Mike Kaganski <mikekaganski>
Component: CalcAssignee: Not Assigned <libreoffice-bugs>
Status: NEW ---    
Severity: normal CC: 79045_79045, andreas.heinisch, philippe, xiscofauli
Priority: medium Keywords: implementationError
Version: 3.4.0 release   
Hardware: All   
OS: All   
See Also: https://bugs.documentfoundation.org/show_bug.cgi?id=96756
https://bugs.documentfoundation.org/show_bug.cgi?id=144687
https://bugs.documentfoundation.org/show_bug.cgi?id=144692
https://bugs.documentfoundation.org/show_bug.cgi?id=144699
Whiteboard:
Crash report or crash signature: Regression By:
Bug Depends on:    
Bug Blocks: 108827    

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. ***