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: 2024-07-15 02:37 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. ***
Comment 3 QA Administrators 2024-07-14 03:13:55 UTC Comment hidden (obsolete)
Comment 4 Philippe Lévi 2024-07-15 02:37:30 UTC
Hi!

Sorry, but still same unexpected results !

Version: 24.2.5.2 (X86_64) / LibreOffice Community
Build ID: bffef4ea93e59bebbeaf7f431bb02b1a39ee8a59
CPU threads: 2; OS: Windows 10.0 Build 19045; UI render: Skia/Vulkan; VCL: win
Locale: en-US (es_ES); UI: en-US
Calc: CL threaded

good luck,
Philippe