Bug 144359 - LibreOffice allows entry of wrong dates for format
Summary: LibreOffice allows entry of wrong dates for format
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
7.1.5.2 release
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-07 16:06 UTC by Edward Redondo
Modified: 2022-05-03 11:08 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Calc showing date entry error that was allowed (164.54 KB, image/jpeg)
2021-09-07 16:06 UTC, Edward Redondo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Edward Redondo 2021-09-07 16:06:12 UTC
Created attachment 174862 [details]
Calc showing date entry error that was allowed

LibreOffice allows entry of dates in wrong format. Example "09/081/2021", of course the "081" is a typo. When a user enters a date in the wrong format LibreOffice should no allow it and an error dialog should pop up showing the error. For the above error the dialog should say "081 wrong day format." Please consider implementing this on future update.
Comment 1 Mike Kaganski 2021-09-07 16:29:07 UTC
Calc does *not* filter the entry based on cell format string. When your input data does not match any numeric format, it is simply considered a text. This is the correct behavior, and should not change.

To filter input, there is a dedicated "validity" function [1], and you may set your cells values to match some criteria, like being between some date range (which would make sure that the input was numeric).

Closing NOTABUG.

[1] https://help.libreoffice.org/latest/en-US/text/scalc/guide/validity.html?DbPAR=CALC
Comment 2 Mike Kaganski 2021-09-07 16:31:57 UTC
An alternative option for someone who want to check if their entry is correct may be using conditional formatting [1] (e.g., marking cells not matching the condition red), or using value highlighting [2].

[1] https://help.libreoffice.org/latest/en-US/text/scalc/guide/cellstyle_conditional.html?DbPAR=CALC
[2] https://help.libreoffice.org/latest/en-US/text/scalc/01/03080000.html?DbPAR=CALC
Comment 3 Edward Redondo 2021-09-08 15:52:28 UTC
(In reply to Mike Kaganski from comment #1)
> Calc does *not* filter the entry based on cell format string. When your
> input data does not match any numeric format, it is simply considered a
> text. This is the correct behavior, and should not change.
> 
> To filter input, there is a dedicated "validity" function [1], and you may
> set your cells values to match some criteria, like being between some date
> range (which would make sure that the input was numeric).
> 
> Closing NOTABUG.
> 
> [1]
> https://help.libreoffice.org/latest/en-US/text/scalc/guide/validity.
> html?DbPAR=CALC

"This is the correct behavior, and should not change." You HAVE to be kidding?!
Incorrect data being allowed IS a problem, and at the very lest should prompt a warning.
Comment 4 [REDACTED] 2021-09-08 16:11:19 UTC
(In reply to Edward Redondo from comment #3)

> 
> "This is the correct behavior, and should not change." You HAVE to be
> kidding?!
> Incorrect data being allowed IS a problem, and at the very lest should
> prompt a warning.

"09/081/2021" is a valid text string an not incorrect data. Imagine you are a manufacturer and you spare parts are numbered this way. What bug report will you write if you
- every time you enter such value getting a warning that your part number (text) is an invalid date  --or--
- you get it turned into a date without notice

You have been explained that formatting a cell is not an *input* filter and that there is a functionality called "data validity" (Data -> Validity), which allows to create a customized validity check of data entered into cells.
Comment 5 Mike Kaganski 2021-09-08 17:01:13 UTC
In other words:

You need to understand, that cell format is *not* intended to define "what values a cell may contain"; it is *only* to define "what procedure to use when show the *existing* content of the cell on screen/on paper".

I.e., when you type characters in a cell, the format string does *NOT* (and is not designed to!) affect what you *may* enter into the cell (i.e., it is not a filter). *Any* cell in a spreadsheet, however formatted, may contain any data - it may be numeric, or textual; it may be a calculated formula returning text, or number, or error.

The formatting of a cell does participate in conversion of your typed text to the cell content. But its part is just to be a *hint* to the program what to attempt, not a filter: i.e., a date format of the active cell might give a hint in which order the date parts (year/month/day) might go in the input string. But if the hint derived from the format does not match the input, the *correct* behavior of the program is to fallback to the most reliable result: accept the typed characters not as some converted number (which dates are), but as plain text. There is *NO* "invalid" text: just anything that you may type is a valid text string, and must be accepted as a valid cell content.

What you are talking about is *validation* of input; and as Uwe and I informed you, there is a dedicated tool for *validation*. What you suggest is using a wrong tool for the task: you try to use cell format for the validation task, for which there is Validity.
Comment 6 Edward Redondo 2021-09-09 15:38:28 UTC
Then another suggestion: Have formatting work like Spell-Checking, mark or highlight entries that do not match the cell (Calc) or text (Word) format?

My typo "9/081/2021" typo in a date-formatted cell would have the "081" in red telling me that is a wrong entry for the date format. Is that doable?
Comment 7 Mike Kaganski 2021-09-09 16:29:02 UTC
(In reply to Edward Redondo from comment #6)
> My typo "9/081/2021" typo in a date-formatted cell would have the "081" in
> red telling me that is a wrong entry for the date format. Is that doable?

No.

1. Format string does not limit the ways that you may *enter* the valid date. E.g., defining a date format like MM/DD/YY, you may enter "aug 1" (in a cell with en-US number format), and get it converted to a date; or you may enter "2021-09-09", and also get it converted. Or you may enter 10%, and the entry will get recognized. Or 1 2/3. And so on. All these will get recognized as a valid *number* (using different rules built into the program string parser), and will end up as valid numbers in the cell.

2. More importantly: each number format string may consist of *four* parts: for positive numbers; negative numbers; zero; and text. If you omit any part, it is *not* considered "absent", but a default value is implicitly used for the respective part. So your partial format string MM/DD/YYYY in reality is equal to something like "MM/DD/YYYY;MM/DD/YYYY;MM/DD/YYYY;@", where the last fourth part tells "show text as it was entered". So any text is *valid* from the format point of view. And there is no way to make it invalid. Any data *matches* any format string. And format string *has no idea* why the program decided that this cell is a text.

But you may use custom format string like e.g. "MM/DD/YYYY;MM/DD/YYYY;MM/DD/YYYY;[red]@", which would mark red all texts, regardless of the reason why it is text. You may learn more about format strings in help: https://help.libreoffice.org/latest/en-US/text/shared/01/05020301.html?&DbPAR=CALC
Comment 8 Edward Redondo 2021-09-10 16:07:07 UTC
Thanks to all who replied.