Bug 157786 - DAY, MONTH, YEAR functions are one day off for date+time before epoch / null-date day
Summary: DAY, MONTH, YEAR functions are one day off for date+time before epoch / null-...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
4.4.7.2 release
Hardware: All All
: medium normal
Assignee: Eike Rathke
URL:
Whiteboard: target:24.2.0 target:7.6.3
Keywords: bibisectNotNeeded, regression
: 157974 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-10-15 15:03 UTC by Regina Henschel
Modified: 2023-10-30 03:58 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
DAY(ISO String) for date before epoche date (24.04 KB, application/vnd.oasis.opendocument.spreadsheet)
2023-10-15 15:03 UTC, Regina Henschel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Regina Henschel 2023-10-15 15:03:44 UTC
Created attachment 190227 [details]
DAY(ISO String) for date before epoche date

Open attached file.
The result for DAY("1899-12-29T15:26:14") should be 29 but is 30.
Comment 1 Regina Henschel 2023-10-15 15:12:09 UTC
The date was correct in LibreOffice 3.5.4.2 
Build ID: 165a79a-7059095-e13bb37-fef39a4-9503d18

The date is wrong in Version: 4.4.7.2
Build ID: f3153a8b245191196a4b6b9abd1d0da16eead600
Locale: en_US
Comment 2 m_a_riosv 2023-10-16 01:16:12 UTC
Reproducible:

Looks as the time part was rounding up. And only fails for:
1899-12-29

Version: 24.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 9eb419b0b0f019f5fbc48ff1a11977e8b041edee
CPU threads: 16; OS: Windows 10.0 Build 22621; UI render: Skia/Vulkan; VCL: win
Locale: es-ES (es_ES); UI: en-US
Calc: CL threaded
Comment 3 Xisco Faulí 2023-10-16 09:21:21 UTC
@Eike, I thought you might be interested in this issue
Comment 4 Eike Rathke 2023-10-16 10:59:35 UTC
Same for =MONTH("1899-11-30T00:00:01") results in 12 instead of 11.
For 1898-12-31T00:00:01 it's day=1, month=1, year=1899.

(In reply to m.a.riosv from comment #2)
> Looks as the time part was rounding up. And only fails for:
> 1899-12-29
No, it fails for all dates before the null-date.
Comment 5 Eike Rathke 2023-10-16 11:54:57 UTC
This is also independent of whether the argument is a string or a date+time value.
Comment 6 Commit Notification 2023-10-16 14:32:18 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/2fa1cdcaeff7d1583aedfcee5b7c802e951b3a86

Resolves: tdf#157786 Use GetFloor32() for date days instead of GetInt32()

It will be available in 24.2.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 7 Eike Rathke 2023-10-16 14:33:29 UTC
Pending review https://gerrit.libreoffice.org/c/core/+/158039 for 7-6
Comment 8 Commit Notification 2023-10-17 06:52:11 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/07a80b8940a16ba1b7fd047865179809bd74a563

tdf#157786: sc_datetime_functions: Add unittest

It will be available in 24.2.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 Commit Notification 2023-10-17 06:56:15 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "libreoffice-7-6":

https://git.libreoffice.org/core/commit/030c77d3e048a5235691db316e614ce3335037fe

Resolves: tdf#157786 Use GetFloor32() for date days instead of GetInt32()

It will be available in 7.6.3.

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 10 Alex G 2023-10-29 20:31:38 UTC
Regression. Confirmed again in Mac Version 7.5.

=DAY(1590-01-06 05:22:00)
expected: 6
actual: 7

=DAY(1990-01-06 05:22:00)
expected: 6
actual: 6


=YEAR() and =MONTH() appear to work correctly but =DAY() adds an extra day in years before 1900.
Comment 11 Mike Kaganski 2023-10-30 03:58:36 UTC
*** Bug 157974 has been marked as a duplicate of this bug. ***