Bug 70551 - WEEKS() function uses ISO weeknum and is not locale-dependent, which is not explained in the Help
Summary: WEEKS() function uses ISO weeknum and is not locale-dependent, which is not e...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Documentation (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: Other All
: medium normal
Assignee: Rafael Lima
URL:
Whiteboard: target:7.4.0
Keywords:
: 106516 (view as bug list)
Depends on:
Blocks: Calc-Function
  Show dependency treegraph
 
Reported: 2013-10-16 22:15 UTC by John Smith
Modified: 2022-04-06 13:14 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments
Spreadsheet illustrating the problem described. (61.61 KB, application/vnd.oasis.opendocument.spreadsheet)
2013-10-16 22:15 UTC, John Smith
Details

Note You need to log in before you can comment on or make changes to this bug.
Description John Smith 2013-10-16 22:15:27 UTC
Created attachment 87761 [details]
Spreadsheet illustrating the problem described.

Problem description: An incorrect result is returned for some dates entered into this function

Steps to reproduce:
1. Open Calc
2. Enter data, such as 1st April 2011, 1st May 2011 and number 1, into cells A1, A2 and A3 respectively
3. in cell 4 enter the function, using the Function Wizard, of WEEKS(A1,A2,A3)

Current behavior:
It returns the result 4
Expected behavior:
It should return the result 5. The two dates appear in weeks which are 5 weeks apart.


Computer is set to US-locale.
              
Operating System: Windows XP
Version: 4.1.1.2 release
Comment 1 Tomaz Vajngerl 2013-10-17 07:07:31 UTC
I guess this is a problem with first day of the week. In this case if the first day is Monday then there are 4 weeks, if it is Sunday then 5. As the locale you have is US-locale then the first day should be Sunday so I guess this is a locale related bug.
Comment 2 John Smith 2013-10-17 09:41:30 UTC
Changing the computer to UK locale also gives same result.
Comment 3 GerardF 2013-10-17 13:07:54 UTC
Yes. It seems that WEEKS use the ISO weeknum (Monday as 1st day of the week).

As the WEEKS function is not defined in OASIS specification, i don't know what is the expected result... and i don't think the result should be locale dependant.
Comment 4 John Smith 2013-10-17 16:53:53 UTC
It's difficult to assign a cause without knowing the internal workings of the function. Another explanation could be that it calculates up to, but does not include, the End date, that would fit the results. As I say, without knowing the internals ...
Comment 5 Cor Nouws 2013-10-31 20:50:27 UTC
Hi,

I change the summary ... OK like this?
Also I assume that this is already the case since the ages of OOo..
Comment 6 John Smith 2013-11-03 15:35:29 UTC
(In reply to comment #5)
> Hi,
> 
> I change the summary ... OK like this?
> Also I assume that this is already the case since the ages of OOo..

Does this mean you have actually determined the cause to be the ISO weeknum, rather than suspecting that it is the cause? As I point out, not including the final date also would explain it.
Comment 7 QA Administrators 2015-04-19 03:22:49 UTC Comment hidden (obsolete)
Comment 8 QA Administrators 2016-09-20 09:24:20 UTC Comment hidden (obsolete)
Comment 9 Cor Nouws 2017-03-12 21:17:04 UTC
*** Bug 106516 has been marked as a duplicate of this bug. ***
Comment 10 QA Administrators 2018-07-24 02:37:48 UTC Comment hidden (obsolete)
Comment 11 QA Administrators 2020-07-24 03:46:19 UTC Comment hidden (obsolete)
Comment 12 Rafael Lima 2022-01-10 19:03:18 UTC
As of LO 7.4, indeed the WEEKS function is not locale dependent. It uses NullDate as reference regardless of the locale [1].

The NullDate in LibreOffice is Dec 30 1899 [2].

[1] https://opengrok.libreoffice.org/xref/core/scaddins/source/datefunc/datefunc.cxx?r=5e5138db#465
[2] https://opengrok.libreoffice.org/xref/core/offapi/com/sun/star/util/NumberFormatSettings.idl?r=2b383d19

To check the NullDate, run:

Sub GetNullDate
    Dim aDate as Variant
    aDate = Thiscomponent.NullDate
    MsgBox aDate.Day & "/" & aDate.Month & "/" & aDate.Year
End Sub
Comment 13 Rafael Lima 2022-01-12 13:05:26 UTC
Proposed patch available for review at:
https://gerrit.libreoffice.org/c/help/+/128331
Comment 14 Commit Notification 2022-01-13 11:29:19 UTC
Rafael Lima committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/help/commit/3cb9f803eae6a60ae6bc8ca35ccd74126f14a871

tdf#70551 Improve description of the WEEKS add-in function