https://bugs.documentfoundation.org/show_bug.cgi?id=145587

            Bug ID: 145587
           Summary: WEEKS spreadsheet add-in function needs optimizations
           Product: LibreOffice
           Version: Inherited From OOo
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Keywords: difficultyBeginner, easyHack, skillCpp
          Severity: normal
          Priority: medium
         Component: Calc
          Assignee: [email protected]
          Reporter: [email protected]

WEEKS [1] is implemented in ScaDateAddIn::getDiffWeeks [2]. It does a lot of
unnecessary calculations:

0. In mode 0, it operates on the simple date difference. It is absolutely not
required to increment the two passed date by null date before getting the
difference in this mode, especially since the null date needs expensive
calculations (accessing XPropertySet using UNO calls; calling DateToDays; using
exception handling).
1. In mode 1, it calculates the ISO week difference; and for that, it considers
not only the relevant fact that ISO weeks start on Monday (which is trivially
calculated), but also unnecessarily the week number in start date's year, which
is not that trivial: it calls DaysToDay and DateToDays (and also cheaper, but
still unnecessary, run-time modulo-7 divisions of that resulting value).
2. It is also possible to optimize DateToDays, that is called not only in
getDiffWeeks, to treat the default null date value specially, like is done in
Date::GetAsNormalizedDays() [3]. Or maybe even make the module depend on tools,
and use existing functions from tools right there, to dedulpicate/optimize
things.

The fix should consider bug 145578. If this easy hack is resolved prior to bug
145578, it should fix that bug as part of it. If it is resolved after bug
145578, it must make sure to keep it working properly, i.e. for all dates,
including before and after the date chosen as a reference point to calculate
week starts (e.g., 0001-01-01), it must ensure that
WEEKS(date1;date2;1)+WEEKS(date2;date1;1)=0.

[1]
https://help.libreoffice.org/latest/en-US/text/scalc/01/04060111.html?DbPAR=CALC#bm_id3149048
[2]
https://git.libreoffice.org/core/+/6680e51716e383c68bb1ec9cc0a05d698d3b6a3d/scaddins/source/datefunc/datefunc.cxx#493
[3]
https://git.libreoffice.org/core/+/6680e51716e383c68bb1ec9cc0a05d698d3b6a3d/tools/source/datetime/tdate.cxx#136

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to