Bug 166268 - Problem with date functions in LO Calc 25.2 on Mac - apparent issue with base date
Summary: Problem with date functions in LO Calc 25.2 on Mac - apparent issue with base...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
24.2.0.0 alpha0+
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Mateusz Wlazłowski
URL:
Whiteboard: target:25.8.0 target:25.2.4 target:24...
Keywords: bibisected, bisected, regression
Depends on:
Blocks:
 
Reported: 2025-04-20 18:31 UTC by Thomas Maeder
Modified: 2025-05-01 04:32 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
Affected LO Calc file (44.69 KB, application/vnd.oasis.opendocument.spreadsheet)
2025-04-20 18:35 UTC, Thomas Maeder
Details
01) Basedate preference = 1904-01-01 (25.85 KB, image/png)
2025-04-20 18:37 UTC, Thomas Maeder
Details
02) Wrong date breakdown using YEAR-MONTH-DAY functions (66.41 KB, image/png)
2025-04-20 18:38 UTC, Thomas Maeder
Details
03) Calculation correct upon entry of another date (43.46 KB, image/png)
2025-04-20 18:40 UTC, Thomas Maeder
Details
04) Force complete recalculation of worksheet (41.53 KB, image/png)
2025-04-20 18:41 UTC, Thomas Maeder
Details
05) Calculations with wrong base date after recalculation of sheet (48.28 KB, image/png)
2025-04-20 18:42 UTC, Thomas Maeder
Details
06) Copy-paste of some data - now both good & bad in same file! (109.47 KB, image/png)
2025-04-20 18:43 UTC, Thomas Maeder
Details
07) Base date set to 1899-12-31 (25.10 KB, image/png)
2025-04-20 18:44 UTC, Thomas Maeder
Details
08) Confirm workaround - all OK in this mode (104.92 KB, image/png)
2025-04-20 18:44 UTC, Thomas Maeder
Details
09) Base date set again to 1904-01-01 to check bug persistence (14.86 KB, image/png)
2025-04-20 18:47 UTC, Thomas Maeder
Details
10) After setting back the base date to 1904-01-01, again split bad/good behaviour (93.29 KB, image/png)
2025-04-20 18:52 UTC, Thomas Maeder
Details
11) Dates displayed as serial numbers - 1 entered & recalculated (83.46 KB, image/png)
2025-04-20 18:59 UTC, Thomas Maeder
Details
Screeshot at opening the file without any modification. (72.33 KB, image/png)
2025-04-21 08:41 UTC, m_a_riosv
Details
Screens with 1899-12-30 (67.06 KB, image/png)
2025-04-21 10:06 UTC, m_a_riosv
Details
After setting the base date to 1899-12-31, before forcing recalculation. (301.47 KB, image/png)
2025-04-21 10:48 UTC, Thomas Maeder
Details
Now forcing recalculation. (298.51 KB, image/png)
2025-04-21 10:49 UTC, Thomas Maeder
Details
After forcing recalculation in 1899-12-31 mode. (179.10 KB, image/png)
2025-04-21 10:51 UTC, Thomas Maeder
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Maeder 2025-04-20 18:31:34 UTC
Description:
Topic: EDITING / FILESAVE (?)
In some cases / some files, the LO Calc date functions YEAR, MONTH and DAY behave erratically with respect to the base date: when the setting is 1904-01-01, they mostly work correctly, but sometimes assume the default 1899-12-31 setting.
(The dates are always displayed correctly, according to the base date setting.)

Steps to Reproduce:
Not always reproducible - some files OK, some obviously wrong.
See attachments: affected file & screenshots of the steps below.
1) Date preference = 1904-01-01.
2) Year-Month-Day calculations in file are false, with a 4-year-1-day error.
3) Upon entry of another value, the corresponding calculated year-month-day is OK.
4) Force recalculate of whole file.
5) After recalculation, the previously correct entered line is again false.

Actual Results:
When calculating the whole file, the date functions obviously sometimes apply the 1899-12-31 system, although the preference is set for 1904-01-01.
Strangely, however, they work correctly when entering data!
Also, the displayed dates are always correct in the 1904 system.

Expected Results:
The date functions (YEAR, MONTH, DAY) should reliably apply the selected base date upon recalculating the file, as they do when entering data (step 3), instead of behaving somewhat erratically.


Reproducible: Sometimes


User Profile Reset: Yes

Additional Info:
- See affected attached file ""LO Calc date base problem.ods" + screenshots.
- The problem is confirmed in safe mode - this is not a user profile issue.
- Not all files are affected.
- The first time I saw the problem was with 25.2.1.2. Same with 25.2.2.2.
- There is a workaround: setting the base date preference to 1899-12-31.
6) Strangely, recopying the problematic data & formulae elsewhere (copy-paste) in the worksheet generates a working data set - now, upon recalculating, columns B-D still behave badly, but the copied data & formulae in column I-L work properly!
7-8) Upon setting the base date to 1899-12-31, all works fine.
9-10) Upon returning the base date to 1904-01-01, again bad (A-D) / good (I-L).
Regression:
- The problem lies with the base date, it is not just some "wrong calculation".
- The facts that a) some cells are affected and some not in the same file, b) that calculation is always correct upon entry, but not upon recalculation of the spreadsheet, and c) there sometimes is an obvious conflict between the displayed date and the year-month-day breakdown using the date functions, point to some sort of local storage issue / erratic behaviour in the date functions rather than a global problem. An analysis of the file could be helpful in this regard.
Comment 1 Thomas Maeder 2025-04-20 18:35:29 UTC
Created attachment 200418 [details]
Affected LO Calc file

The affected spreadsheet (see screenshots for the steps in the description).
Comment 2 Thomas Maeder 2025-04-20 18:37:11 UTC
Created attachment 200419 [details]
01) Basedate preference = 1904-01-01
Comment 3 Thomas Maeder 2025-04-20 18:38:14 UTC
Created attachment 200420 [details]
02) Wrong date breakdown using YEAR-MONTH-DAY functions
Comment 4 Thomas Maeder 2025-04-20 18:40:13 UTC
Created attachment 200421 [details]
03) Calculation correct upon entry of another date
Comment 5 Thomas Maeder 2025-04-20 18:41:03 UTC
Created attachment 200422 [details]
04) Force complete recalculation of worksheet
Comment 6 Thomas Maeder 2025-04-20 18:42:03 UTC
Created attachment 200423 [details]
05) Calculations with wrong base date after recalculation of sheet
Comment 7 Thomas Maeder 2025-04-20 18:43:00 UTC
Created attachment 200424 [details]
06) Copy-paste of some data - now both good & bad in same file!
Comment 8 Thomas Maeder 2025-04-20 18:44:06 UTC
Created attachment 200425 [details]
07) Base date set to 1899-12-31
Comment 9 Thomas Maeder 2025-04-20 18:44:41 UTC
Created attachment 200426 [details]
08) Confirm workaround - all OK in this mode
Comment 10 Thomas Maeder 2025-04-20 18:47:12 UTC
Created attachment 200427 [details]
09) Base date set again to 1904-01-01 to check bug persistence
Comment 11 Thomas Maeder 2025-04-20 18:52:05 UTC
Created attachment 200428 [details]
10) After setting back the base date to 1904-01-01, again split bad/good behaviour

The persistence of the bug upon toggling the base date between 1904-01-01 and 1899-12-31 and the coexistence of correct and incorrect calculations in the same file hint at some sort of subtle file corruption (not the data itself - see next screenshot, but the way it is handled).
Comment 12 Thomas Maeder 2025-04-20 18:59:00 UTC
Created attachment 200429 [details]
11) Dates displayed as serial numbers - 1 entered & recalculated

Here, the display is set to number format (still with 1904-01-01 base date), to confirm that the underlying data is the same.
Also, 1 is entered in the top row. As in step 3, the initial result is correct in both places (1904-01-02). The screenshot shows the status after forced recalculation of the worksheet, with 1899-12-31 displayed incorrectly in the left part, as in step 5.
Comment 13 m_a_riosv 2025-04-20 19:51:53 UTC
Ok, a lot of images, but not a sample file that shows the issue.

Please attach a sample file, reduce the size as much as possible without private information, 
and paste the information in Menu/Help/About LibreOffice, there is a copy icon.
Comment 14 Thomas Maeder 2025-04-20 20:43:24 UTC
(In reply to m_a_riosv from comment #13)
> Ok, a lot of images, but not a sample file that shows the issue.
> 
> Please attach a sample file, reduce the size as much as possible without
> private information, 
> and paste the information in Menu/Help/About LibreOffice, there is a copy
> icon.

The affected LO Calc sample file is the first attachment, labelled "Affected LO Calc file".
I attached the step-by-step screenshots as a reference, as I'm not sure the bug will be reproducible on all installations - maybe everything will look OK when you open it.
Comment 15 Thomas Maeder 2025-04-20 21:13:13 UTC
Just confirmed the exact same behaviour of the attached file on a fresh install of LO 25.2.2.2 on another machine.
- First report: MacBook Pro, Mid-2015, Mac OS 12.7.6 Monterey
- Confirmed: iMac 18.3, Mid-2017, Mac OS 13.7.5 Ventura
(Exactly same cells with bad and good behaviour on both systems: always correct calculation upon data entry, but return to incorrect values upon forced recalculation of the whole sheet.)
Comment 16 m_a_riosv 2025-04-21 08:41:18 UTC
Created attachment 200431 [details]
Screeshot at opening the file without any modification.

Sorry, I see now.

Looks fine for me at opening.
Version: 25.2.3.1 (X86_64) / LibreOffice Community
Build ID: d8d1af5f77df955194e52baabe19324532ac8e8b
CPU threads: 16; OS: Windows 11 X86_64 (10.0 build 26100); UI render: Skia/Raster; VCL: win
Locale: en-US (es_ES); UI: en-US
Calc: CL threaded
Comment 17 Thomas Maeder 2025-04-21 09:43:04 UTC
(In reply to m_a_riosv from comment #16)
> Created attachment 200431 [details]
> Screeshot at opening the file without any modification.
> 
> Sorry, I see now.
> 
> Looks fine for me at opening.
> Version: 25.2.3.1 (X86_64) / LibreOffice Community
> Build ID: d8d1af5f77df955194e52baabe19324532ac8e8b
> CPU threads: 16; OS: Windows 11 X86_64 (10.0 build 26100); UI render:
> Skia/Raster; VCL: win
> Locale: en-US (es_ES); UI: en-US
> Calc: CL threaded

Good that you could confirm the issue between the different (left & right) parts of the file.
- Is the calculation also correct upon manual entry of another date in column A?
- Does the problem persist / reappear when you force recalculation of the sheet?
- Does the problem also disappear when you set the base date to 1899-12-31?
Comment 18 m_a_riosv 2025-04-21 10:06:36 UTC
Created attachment 200435 [details]
Screens with 1899-12-30

> 
> Good that you could confirm the issue between the different (left & right)
> parts of the file.
> - Is the calculation also correct upon manual entry of another date in
> column A?
Yes
> - Does the problem persist / reappear when you force recalculation of the
> sheet?
No issue
> - Does the problem also disappear when you set the base date to 1899-12-31?
?
Comment 19 Thomas Maeder 2025-04-21 10:48:27 UTC
Created attachment 200437 [details]
After setting the base date to 1899-12-31, before forcing recalculation.

After setting the base date to 1899-12-31, I get the same behaviour: the left side is OK, but the right side is wrong.
Obviously, LO - wrongly - assumes the file must not be recalculated.
Comment 20 Thomas Maeder 2025-04-21 10:49:44 UTC
Created attachment 200438 [details]
Now forcing recalculation.

…I therefore need to force a recalculation to update the results.
Comment 21 Thomas Maeder 2025-04-21 10:51:49 UTC
Created attachment 200439 [details]
After forcing recalculation in 1899-12-31 mode.

In 1899-12-31 mode, after forced recalculation, the results are now all correct (both A-D and I-L).
Comment 22 Mateusz Wlazłowski 2025-04-22 15:30:11 UTC
Can confirm


Version: 25.2.2.2 (X86_64) / LibreOffice Community
Build ID: 7370d4be9e3cf6031a51beef54ff3bda878e3fac
CPU threads: 8; OS: Linux 6.11; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Flatpak
Calc: threaded

Version: 25.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: f355ddcbf2bf037263e336724829b5467b94ef40
CPU threads: 8; OS: Linux 6.11; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: CL threaded
Comment 23 Mateusz Wlazłowski 2025-04-27 15:42:59 UTC
Bibiseted using linux-64-24.8
 b38974391e8d4bf0d450abfaa86bbccbe1022995 is the first bad commit

Related: tdf#160056 do calc NumberFormatting via ScInterpreterContext

author	Caolán McNamara <caolan.mcnamara@collabora.com>	
Fri Mar 22 09:47:47 2024 +0000
committer	Caolán McNamara <caolan.mcnamara@collabora.com>	
Sat Mar 23 01:14:13 2024 +0100


Adding to CC: Caolán McNamara


Proposed patch to fix:

https://gerrit.libreoffice.org/c/core/+/184687
Comment 24 Commit Notification 2025-04-30 15:42:46 UTC
Mateusz Wlazłowski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/234cb2da3598837a60572dc8475bcb7d9503335f

tdf#166268 Initialize the correct null date in ImpSvNumberformatScan

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 25 Commit Notification 2025-04-30 18:34:05 UTC
Mateusz Wlazłowski committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/635c4eb84949a4cc34dadc079a1d65371da39a93

tdf#166268 Initialize the correct null date in ImpSvNumberformatScan

It will be available in 25.2.4.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 26 Commit Notification 2025-04-30 18:34:09 UTC
Mateusz Wlazłowski committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/3f95aa87300152a1fb85815599c9588dc953e302

tdf#166268 Initialize the correct null date in ImpSvNumberformatScan

It will be available in 24.8.8.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 27 Caolán McNamara 2025-04-30 18:34:46 UTC
Thanks Mateusz