Bug 164239 - Inconsistent Interpretation of Year-Month-Day like strings in Calc
Summary: Inconsistent Interpretation of Year-Month-Day like strings in Calc
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
3.6 all versions
Hardware: All All
: medium normal
Assignee: Eike Rathke
URL:
Whiteboard: target:25.8.0 target:25.2.0.0.beta2 t...
Keywords:
Depends on:
Blocks:
 
Reported: 2024-12-08 11:50 UTC by gplhust955
Modified: 2024-12-11 11:16 UTC (History)
3 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 gplhust955 2024-12-08 11:50:07 UTC
Description:
When Calc encounters strings look like Year-Month-Day, the interpretation varies unexpectedly. If the year value falls between 1 and 12, Calc interprets the string as Text. However, Calc correctly interprets the string as a Date when the year value is either 0 or any number between 13 and the maximum supported year.

However, when a cell is pre-formatted as YYYY-MM-DD, year values between 1 and 12 are correctly interpreted as dates.

The issue appears more complex than initially reported in https://bugs.documentfoundation.org/show_bug.cgi?id=164227, raising two important questions: 

1. The examples demonstrate that the preset cell format affects how entered strings are interpreted into Calc's internal types and values. Is this behavior intentional or is it a bug?

2. When a cell's format is set to "General" and a string is entered, does Calc:
- interpret it deterministically (always the same way), or
- interpret it conditionally based on the environment (e.g., the types of surrounding cells)?

Steps to Reproduce:
1. Enter "12-1-1" in one cell
2. Enter "13-1-1" in another cell
3. Set the format as YYYY-MM-DD first, enter "12-1-1" 

Actual Results:
1. Text
2. Date
3. Date

Expected Results:
1. Date
2. Date
3. Date


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 24.8.3.2 (AARCH64) / LibreOffice Community
Build ID: 48a6bac9e7e268aeb4c3483fcf825c94556d9f92
CPU threads: 8; OS: macOS 15.0; UI render: Skia/Metal; VCL: osx
Locale: en-US (en_CN.UTF-8); UI: en-US
Calc: threaded
Comment 1 Buovjaga 2024-12-08 12:01:35 UTC
A missing step is:
Select all the cells first, right-click - Format Cells - Language: English (USA).

I confirm, but let's ask developers later.

Version: 25.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: c91edf5e57a7441fbac399c7a44f26a57878e5be
CPU threads: 8; OS: Linux 6.12; UI render: default; VCL: kf6 (cairo+wayland)
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
Calc: CL threaded
Comment 2 m_a_riosv 2024-12-08 21:55:51 UTC
What is in Menu>Tools>Options/Languages and Locales>Date acceptance pattern?
Comment 3 gplhust955 2024-12-09 03:09:16 UTC
(In reply to m_a_riosv from comment #2)
> What is in Menu>Tools>Options/Languages and Locales>Date acceptance pattern?

The Date acceptance pattern is set to the default value: 'M/D/Y;M/D'.I have not made any changes.
Comment 4 Buovjaga 2024-12-09 07:20:02 UTC
(In reply to gplhust955 from comment #3)
> (In reply to m_a_riosv from comment #2)
> > What is in Menu>Tools>Options/Languages and Locales>Date acceptance pattern?
> 
> The Date acceptance pattern is set to the default value: 'M/D/Y;M/D'.I have
> not made any changes.

Good point. Adding the pattern Y-M-D makes step 1 lead to a date. So let's close this report?
Comment 5 gplhust955 2024-12-09 08:32:07 UTC
(In reply to Buovjaga from comment #4)
> (In reply to gplhust955 from comment #3)
> > (In reply to m_a_riosv from comment #2)
> > > What is in Menu>Tools>Options/Languages and Locales>Date acceptance pattern?
> > 
> > The Date acceptance pattern is set to the default value: 'M/D/Y;M/D'.I have
> > not made any changes.
> 
> Good point. Adding the pattern Y-M-D makes step 1 lead to a date. So let's
> close this report?


Adding the pattern Y-M-D seems to work. However, it is only a workaround. I wonder if we should also focus on identifying the root cause of the issue and addressing the two additional questions raised.
Comment 6 Buovjaga 2024-12-09 08:59:53 UTC
(In reply to gplhust955 from comment #5)
> (In reply to Buovjaga from comment #4)
> > (In reply to gplhust955 from comment #3)
> > > (In reply to m_a_riosv from comment #2)
> > > > What is in Menu>Tools>Options/Languages and Locales>Date acceptance pattern?
> > > 
> > > The Date acceptance pattern is set to the default value: 'M/D/Y;M/D'.I have
> > > not made any changes.
> > 
> > Good point. Adding the pattern Y-M-D makes step 1 lead to a date. So let's
> > close this report?
> 
> 
> Adding the pattern Y-M-D seems to work. However, it is only a workaround. I
> wonder if we should also focus on identifying the root cause of the issue
> and addressing the two additional questions raised.

Eike: what do you think? I see there is also a related bug 164227.
Comment 7 Eike Rathke 2024-12-09 16:21:13 UTC
Bug 164227 is unrelated, except that both are about date acceptance.

12-1-1 in a locale with MDY order like en-US is treated as slightly ambiguous if the date acceptance patterns were not matched, as the 12 could be a month number. Hence the result is text instead of date. In a locale with DMY order it could be day numbers 1..31.

However, we maybe could tighten that condition and say that if the input does not match any date acceptance pattern then we can force an ISO date.


> 1. The examples demonstrate that the preset cell format affects how entered strings are interpreted into Calc's internal types and values. Is this behavior intentional or is it a bug?
Not a bug, it's intentional as users want to be able to input/overwrite a date in the same format it is displayed.


> 2. When a cell's format is set to "General" and a string is entered, does Calc:
> - interpret it deterministically (always the same way), or
> - interpret it conditionally based on the environment (e.g., the types of surrounding cells)?
Surrounding cells don't matter.
Comment 8 Commit Notification 2024-12-09 19:35:21 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/47b4b1633a08dd4c97d66feabe8cd3290074dc0f

Resolves: tdf#164239 Can force Y-M-D to ISO 8601 if no date acceptance pattern

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 9 Eike Rathke 2024-12-09 19:37:24 UTC
Pending review https://gerrit.libreoffice.org/c/core/+/178174 for 24-8
Comment 10 Commit Notification 2024-12-09 22:20:02 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/4fabbc6b6d461472fa2f30a46c2a79f4d8a24b73

Resolves: tdf#164239 Can force Y-M-D to ISO 8601 if no date acceptance pattern

It will be available in 25.2.0.0.beta2.

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 11 Commit Notification 2024-12-10 03:22:57 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/224c0bb32232a29d08611365d25be1c340032bc8

Resolves: tdf#164239 Can force Y-M-D to ISO 8601 if no date acceptance pattern

It will be available in 24.8.5.

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 12 Commit Notification 2024-12-11 11:16:30 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "libreoffice-24-8-4":

https://git.libreoffice.org/core/commit/dd57ef3aee60b24fecbb990a3fc2fc51ce30c9e4

Resolves: tdf#164239 Can force Y-M-D to ISO 8601 if no date acceptance pattern

It will be available in 24.8.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.