Bug 158215 - Calc Function DAYS doesnt return the number of Days as **integer**
Summary: Calc Function DAYS doesnt return the number of Days as **integer**
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Documentation (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-14 20:07 UTC by Werner Tietz
Modified: 2023-11-15 13:21 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 Werner Tietz 2023-11-14 20:07:15 UTC
Description:
The Help about DAYS  states: it returns the whole Days without Decimal-fraction.

See also: 
https://forum.openoffice.org/en/forum/viewtopic.php?p=542967#p542967

Steps to Reproduce:
1. Insert Function

=DAYS(NOW();DATE(2023;11;1))
 


Actual Results:
 It returns 13.8744083253332

Expected Results:
2. It should return 13



Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 7.6.2.1 (AARCH64) / LibreOffice Community
Build ID: 56f7684011345957bbf33a7ee678afaf4d2ba333
CPU threads: 4; OS: Linux 6.1; UI render: default; VCL: gtk3
Locale: de-DE (de_DE.UTF-8); UI: en-US
Flatpak
Calc: threaded
Comment 1 Werner Tietz 2023-11-14 20:31:07 UTC
additional:

the odf-standard is not exactly clear about whole number or Fraction:
http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.html#DAYS

Can somebody prove the behaviour in Excel?
Comment 2 m_a_riosv 2023-11-14 22:12:07 UTC
It is explained in the wiki
https://wiki.documentfoundation.org/Documentation/Calc_Functions/DAYS
"
Details specific to DAYS function

The formula for this function is DAYS = Date2 – Date1, subtracting the two date-time serial numbers.

This function is not identical to Microsoft Excel’s DAYS function, which does not take account of any time components of the dates.
"
Comment 3 Werner Tietz 2023-11-15 05:41:29 UTC
It may be explained in the wiki, but NOT in the Help about DAYS!
Comment 4 Mike Kaganski 2023-11-15 06:37:15 UTC
It is indeed a problem of documentation. Setting the component accordingly. The help needs to mention something like

"Calculates the difference between two date values *(including fraction of a day when arguments include time parts)*", or the like.

Indeed, the standard is already explicit and exactly clear - it tells "If StartDate and EndDate are Numbers, this is EndDate – StartDate", which provides the exact answer how the result is obtained (no truncation / rounding of arguments and/or result involved).
Comment 5 Mike Kaganski 2023-11-15 07:03:42 UTC
(In reply to Mike Kaganski from comment #4)
> "Calculates the difference between two date values *(including fraction of a
> day when arguments include time parts)*", or the like.

Or better, explicitly express the difference between numeric arguments (that are used unchanged, and provide fractional result), and textual arguments (that are handled using DATEVALUE, and this truncate).

Werner Tietz: please consider a new report regarding introduction of a *new* function, say, DAYS.EXCEL - which would be compatible with what Excel does; usable in import/export (thus improving interoperability); and provide a more useful and consistent behavior.
Comment 6 Werner Tietz 2023-11-15 09:02:43 UTC
(In reply to Mike Kaganski from comment #5)
> Werner Tietz: please consider a new report regarding introduction of a *new* 
> function, say, DAYS.EXCEL - which would be compatible with what Excel does; 
> usable in import/export (thus improving interoperability); and provide a more 
> useful and consistent behavior.


I don't think I want that, we already have more than enough functions in various flavors.

My point here is not Excel compatibility, but that:

1. from a function with called "DAYS" I would expect returning the whole days and not also decimal places!
Simply because of the behavior of similar functions: MONTHS | YEARS 


2. if I also want the decimal places, I simply and pragmatically use

=LaterDateTime - EarlierDateTime
Comment 7 Mike Kaganski 2023-11-15 10:54:51 UTC
(In reply to Werner Tietz from comment #6)

INO, you are right in your expectations; the function as it is defined doesn't make much sense.

Let's ask Regina's opinion on possibility to radically change the function's definition here. Maybe I exaggerate the problems?
Comment 8 Regina Henschel 2023-11-15 12:21:06 UTC
I think, there is a problem in the specification. The parameters of the DAYS function have the pseudo type DateParam (4.11.3.). That has
"A DateParam is a value that is either a Number (interpreted as a serial number; 4.3.3)..."

Section 4.3.3 is the data type Date. And that has
"Date is represented by an integer value."

But the implicit conversion to DateParam (6.3.15) has
"If the expected type is the pseudotype DateParam, then if value is of type:
    • Number, return it."
That does not include any rounding or truncating to integer.


Does someone has Gnumeric to test the result there?
Comment 9 Mike Kaganski 2023-11-15 13:21:28 UTC
(In reply to Regina Henschel from comment #8)
> Does someone has Gnumeric to test the result there?

In Gnumeric v.1.12.46:

  =days(now(),"2024-01-01")

returns -47, so it is truncating.