Bug 114011 - DATEADD() LOBasic function displays year incorrectly
Summary: DATEADD() LOBasic function displays year incorrectly
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
6.0.0.0.alpha1+
Hardware: All All
: medium normal
Assignee: Eike Rathke
URL:
Whiteboard: target:6.0.0 target:5.4.4 target:7.3.0
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-23 14:31 UTC by Alex Thurgood
Modified: 2021-07-14 16:16 UTC (History)
0 users

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 Alex Thurgood 2017-11-23 14:31:15 UTC
Description:
It was reported on the German M-L that the help is incorrect when describing how to enter the string for the date. Indeed, it does seem wrong, or rather incomplete, but that is tangential to what is to follow:

1) Open a Writer document
2) Create a new macro module in the document with the following :


Sub example_dateadd
MsgBox DateAdd("m", 1, 31012004) &" - "& DateAdd("M", 1, 31012005)
End Sub

Try and execute the macro.


Using the above:

- if use double quote characters around the date string, I get various error messages, such as "unsuported type", or "unsupported operation" depending on which way I type the string separators (dots or slashes);

- if I use as in the above example, i.e. no quotes around what is essentially an integer, I get a MsgBox that displays "31/01/32767 - 31/01/32767" which is obviously incorrect.


This latter behaviour is the one being reported here.


Steps to Reproduce:
See above description

Actual Results:  
See above

Expected Results:
Correct display of the year.


Reproducible: Always


User Profile Reset: No



Additional Info:


User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:57.0) Gecko/20100101 Firefox/57.0
Comment 1 Eike Rathke 2017-11-23 14:48:03 UTC
First, DateAdd() expects a Date or date serial number, so what you pass as integer is the number of days since the null-date (1899-12-30). Nevertheless the calculation seems wrong. Investigating.
Comment 2 Commit Notification 2017-11-23 17:45:45 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=db080dad6c9ad9930e26aeb70638d7146afa279a

tdf#114011 limit/truncate date, not only year

It will be available in 6.0.0.

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

Affected users are encouraged to test the fix and report feedback.
Comment 3 Eike Rathke 2017-11-23 19:29:15 UTC
DateAdd() not accepting a (locale dependent) string ("01/31/2004" or "31.01.2004" or always ISO "2004-01-31") IMHO is also wrong.
Comment 4 Eike Rathke 2017-11-23 20:37:19 UTC
Actually it does accept the string, but adding one month to 2004-01-31 does not work, apparently because it would result in 2004-02-31 that is not a valid date. Not sure what is expected there, truncate to 2004-02-29? Would need to compare with VBA. Let's mark this fixed for the original problem.
Comment 5 Commit Notification 2017-11-24 16:19:52 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "libreoffice-5-4":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=8be272b6642611e152ddc8e13f8570d2e673e0b4&h=libreoffice-5-4

tdf#114011 limit/truncate date, not only year

It will be available in 5.4.4.

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

Affected users are encouraged to test the fix and report feedback.
Comment 6 Commit Notification 2021-07-14 16:16:46 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "master":

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

tdf#114011: basic_macros: Add unittest

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