This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch openformula in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit 517a2e3b216754282385a674d10fc3dda88d9017 Author: Pedro Giffuni <[email protected]> AuthorDate: Tue Nov 17 16:55:56 2026 -0500 H.5: Implement ISO 8601 ISOWEEKNUM semantics - Add SC_OPCODE_ISOWEEKNUM (416) and ocIsoWeekNum - Add ScIsoWeekNum() using Date::GetWeekOfYear(MONDAY, 4) - Register ISOWEEKNUM in ODF and Excel namespaces - Add Function Wizard entry (1 arg, no mode) - Add HID_FUNC_ISOWEEKNUM and help topic func_isoweeknum.xhp - Add calcval tests SG.ISO-01..25 (year boundaries, week 53, leap, century, time fractions) - WEEKNUM (ScGetWeekOfYear) unchanged: retains 2-arg SUN/MON mode - Update audit records --- .../function-gap-inventory.md | 2 +- .../function-gap-summary.tsv | 2 +- .../function-implementation-roadmap.md | 30 +++++----- .../function-semantic-test-plan.md | 36 ++++++------ .../function-source-audit.md | 20 ++++--- main/formula/inc/formula/compiler.hrc | 5 +- main/formula/inc/formula/opcode.hxx | 1 + .../formula/source/core/resource/core_resource.src | 6 ++ .../helpcontent2/source/text/scalc/01/04060102.xhp | 5 ++ .../source/text/scalc/01/func_isoweeknum.xhp | 65 ++++++++++++++++++++++ main/helpcontent2/source/text/scalc/01/makefile.mk | 1 + main/sc/inc/helpids.h | 1 + main/sc/source/core/inc/interpre.hxx | 1 + main/sc/source/core/tool/interpr2.cxx | 18 ++++++ main/sc/source/core/tool/interpr4.cxx | 1 + main/sc/source/ui/src/scfuncs.src | 24 ++++++++ main/sc/util/hidother.src | 1 + test/odf-validate/calcval-cases14.tsv | 25 +++++++++ 18 files changed, 203 insertions(+), 41 deletions(-) diff --git a/audit/openformula-function-gaps/function-gap-inventory.md b/audit/openformula-function-gaps/function-gap-inventory.md index 1414a2780e..bd551e4843 100644 --- a/audit/openformula-function-gaps/function-gap-inventory.md +++ b/audit/openformula-function-gaps/function-gap-inventory.md @@ -13,7 +13,7 @@ Summary table of all 15 audited functions. | REPLACEB | Present | ocReplaceB (414) | ScReplaceB() | Yes (HID_FUNC_REPLACEB) | No | N/A | No | No | No | No | None — implementation complete at source level | Resolved (was P1) | HIGH | | SEARCHB | Present | ocSearchB (413) | ScSearchB() | Yes (HID_FUNC_SEARCHB) | No | N/A | No | No | No | No | None — implementation complete at source level | Resolved (was P1) | HIGH | | DATEDIF | Present | ocDateDif (415) | ScDateDif() | Yes (HID_FUNC_DATEDIF) | Yes | Large Group | Yes(BIFF5/7,ID351,ocDateDif,import-only) | No | No | No | Reverse-interval/component policy Excel-compatible (ODF undefined); runtime validation pending (no sc build) | Resolved/H.3.1 reviewed (was P1) | HIGH | -| ISOWEEKNUM | Partial (wrong semantics) | ocWeek | ScGetWeekOfYear() | German only (KALENDERWOCHE) | No | N/A | No | Yes (ODF table, import-only) | No | _xlfnodf.ISOWEEKNUM | ISO 8601 semantics not implemented (only SUN/MON start) | P1 | MEDIUM | +| ISOWEEKNUM | Present | ocIsoWeekNum (416) | ScIsoWeekNum() | Yes (HID_FUNC_ISOWEEKNUM) | Yes | Large Group | Yes(ODF table,import-only) | No | No | _xlfnodf.ISOWEEKNUM | H.5 fixed: separate opcode, ISO 8601 via GetWeekOfYear(MONDAY,4) | Resolved/H.5 (was P1) | HIGH | | DDE | Present (platform-dependent) | ocDde (369) | ScDde() | Yes (HID_FUNC_DDE) | No | N/A | No | No | No | No | Platform-dependent; no file-format mapping | DEFER | HIGH | | ODDFPRICE | Present (AddIn) | None | getOddfprice() (AddIn) | Yes (HID_AAI_FUNC_ODDFPRICE) | No | N/A | No | No | No | No | Analysis AddIn, not native | P2 | HIGH | | ODDFYIELD | Present (AddIn) | None | getOddfyield() (AddIn) | Yes (HID_AAI_FUNC_ODDFYIELD) | No | N/A | No | No | No | No | Analysis AddIn, not native | P2 | HIGH | diff --git a/audit/openformula-function-gaps/function-gap-summary.tsv b/audit/openformula-function-gaps/function-gap-summary.tsv index dfcde23ac0..e1cfc021cb 100644 --- a/audit/openformula-function-gaps/function-gap-summary.tsv +++ b/audit/openformula-function-gaps/function-gap-summary.tsv @@ -3,7 +3,7 @@ FINDB No N/A ocFinDB(412) FINDB ScFindB() Yes (HID_FUNC_FINDB) No No No No None REPLACEB No N/A ocReplaceB(414) REPLACEB ScReplaceB() Yes (HID_FUNC_REPLACEB) No No No No None — implementation complete at source level Resolved (was P1) HIGH compiler.hrc:414; interpr4.cxx:3774 dispatch, interpr1.cxx:8250 evaluator; DBCS byte semantics SEARCHB No N/A ocSearchB(413) SEARCHB ScSearchB() Yes (HID_FUNC_SEARCHB) No No No No None — implementation complete at source level Resolved (was P1) HIGH compiler.hrc:413; interpr4.cxx:3773 dispatch, interpr1.cxx:8197 evaluator; DBCS byte semantics DATEDIF Yes Large Group ocDateDif(415) DATEDIF ScDateDif() Yes (HID_FUNC_DATEDIF) Yes(BIFF5/7,ID351,ocDateDif,import-only) No No No Reverse-interval/component policy Excel-compatible (ODF undefined); runtime validation pending (no sc build) Resolved/H.3.1 reviewed (was P1) HIGH compiler.hrc:415; interpr4.cxx:3775 dispatch, interpr2.cxx:443 evaluator; xlformula.cxx:342 BIFF5/7 import-only; H.3.1 fixed md borrow/ym/yd semantics, added help+expanded calcval cases; ODF 6.10.3 source-level -ISOWEEKNUM No N/A ocWeek ISOWEEKNUM ScGetWeekOfYear() German only (KALENDERWOCHE) No Yes(ODF table,import-only) No _xlfnodf.ISOWEEKNUM ISO 8601 semantics not implemented (SUN/MON start only) P1 MEDIUM interpr2.cxx:227 ScGetWeekOfYear() uses Date::GetWeekOfYear(); no ISO week-1=first-Thursday logic +ISOWEEKNUM Yes Large Group ocIsoWeekNum(416) ISOWEEKNUM ScIsoWeekNum() Yes (HID_FUNC_ISOWEEKNUM) Yes(ODF table,import-only) No No _xlfnodf.ISOWEEKNUM H.5 fixed: separate opcode, ISO 8601 via GetWeekOfYear(MONDAY,4); help+tests added Resolved/H.5 (was P1) HIGH compiler.hrc:416; opcode.hxx:ocIsoWeekNum; interpr2.cxx:ScIsoWeekNum(); interpr4.cxx dispatch; core_resource.src ODF/Excel names; scfuncs.src 1-arg; helpids.h/hidother.src; func_isoweeknum.xhp; SG.ISO-01..25 tests DDE No N/A ocDde(369) DDE ScDde() Yes (HID_FUNC_DDE) No No No No Platform-dependent; no file-format mapping DEFER HIGH interpr2.cxx:2150; DDE via sfx2::LinkManager; disabled in server mode ODDFPRICE No N/A None ODDFPRICE getOddfprice() (AddIn) Yes (HID_AAI_FUNC_ODDFPRICE) No No No No Analysis AddIn, not native P2 HIGH odffmap.cxx:127; financial.cxx:404; AddIn mechanism only ODDFYIELD No N/A None ODDFYIELD getOddfyield() (AddIn) Yes (HID_AAI_FUNC_ODDFYIELD) No No No No Analysis AddIn, not native P2 HIGH odffmap.cxx:128; financial.cxx:416; AddIn mechanism only diff --git a/audit/openformula-function-gaps/function-implementation-roadmap.md b/audit/openformula-function-gaps/function-implementation-roadmap.md index 3cc1b74117..4b13126f7b 100644 --- a/audit/openformula-function-gaps/function-implementation-roadmap.md +++ b/audit/openformula-function-gaps/function-implementation-roadmap.md @@ -78,21 +78,23 @@ Semantic design: See datedif-semantic-design.md for detailed algorithm specification including reverse-date policy, time fraction handling, and month/year boundary semantics. -ISOWEEKNUM: Still pending (see below). - -Recommended sequence for ISOWEEKNUM: - 1. Verify ScGetWeekOfYear() (interpr2.cxx:227) does NOT implement - ISO 8601 (only SUN/MON start via Date::GetWeekOfYear()). - 2. Implement ISO 8601 week numbering (week 1 = first Thursday, - Monday start, 52/53 week years) — either in ScGetWeekOfYear() - with mode=21 or as a separate code path. - 3. Add English help entry (currently only German KALENDERWOCHE). - 4. Verify Excel BIFF import mapping (currently not in BIFF tables). - 5. Add test cases. +ISOWEEKNUM: COMPLETED in H.5 (commit on openformula branch). -Rationale: DATEDIF was entirely missing from the date/time compatibility - group. Now implemented following ODF 1.4 §6.10.3 with documented - Excel-compatibility edge cases. ISOWEEKNUM remains pending. +Changes: + 1. Added SC_OPCODE_ISOWEEKNUM = 416 (compiler.hrc, opcode.hxx). + 2. Added ScIsoWeekNum() in interpr2.cxx using Date::GetWeekOfYear(MONDAY, 4). + 3. Added dispatch case ocIsoWeekNum in interpr4.cxx. + 4. Registered ISOWEEKNUM name in core_resource.src (ODF and Excel namespaces). + 5. Added function wizard resource in scfuncs.src (1 argument, no mode). + 6. Added HID_FUNC_ISOWEEKNUM in helpids.h and hidother.src. + 7. Added help topic func_isoweeknum.xhp, registered in makefile and 04060102.xhp. + 8. Added calcval test cases SG.ISO-01 through SG.ISO-25 covering year + boundaries, week 53, leap years, century boundaries, time fractions, + and error cases. + 9. WEEKNUM (ScGetWeekOfYear) unchanged: retains 2-arg SUN/MON mode. + +Rationale: ISOWEEKNUM needed separate opcode and evaluator for ISO 8601 + compliance (1 arg, Monday start, week 1 = first Thursday). Now resolved. Group 3 — Financial Odd-Period Functions (ODDFPRICE, ODDFYIELD) diff --git a/audit/openformula-function-gaps/function-semantic-test-plan.md b/audit/openformula-function-gaps/function-semantic-test-plan.md index 438149be86..30f7d34a9e 100644 --- a/audit/openformula-function-gaps/function-semantic-test-plan.md +++ b/audit/openformula-function-gaps/function-semantic-test-plan.md @@ -91,26 +91,30 @@ availability (`sc`/`scaddins` not built in this environment). 5. ISOWEEKNUM ------------- -ODF 1.4: Not confirmed as ODF-defined (verify against final spec). -ISO 8601 week numbering: Monday first, week 1 = first Thursday. +ODF 1.4: Defined by ODF 1.4 Part 4. ISO 8601 week numbering. -Test cases: +Test cases (implemented as `SG.ISO-*` in `test/odf-validate/calcval-cases14.tsv`): a) =ISOWEEKNUM(DATE(2024;1;1)) — Monday 2024-01-01 is ISO week 1 (expected: 1) - b) =ISOWEEKNUM(DATE(2024;12;30)) — ISO week 53 (expected: 53) + b) =ISOWEEKNUM(DATE(2024;12;30)) — ISO week 1 of 2025 (expected: 1) c) =ISOWEEKNUM(DATE(2024;12;31)) — ISO week 1 of 2025 (expected: 1) d) =ISOWEEKNUM(DATE(2025;12;29)) — ISO week 1 of 2026 (expected: 1) - e) =ISOWEEKNUM(DATE(2024;1;1);1) — 2 args with mode flag (current impl supports SUN/MON only) - f) =ISOWEEKNUM("not a date") — invalid input (error) - g) =ISOWEEKNUM() — wrong arg count (error) - h) =ISOWEEKNUM(DATE(2024;6;15);21) — ISO mode (21) if supported; current impl ignores mode value beyond SUN/MON - -Expected: Current implementation ScGetWeekOfYear() (interpr2.cxx:227) - only supports SUNDAY (flag=1) or MONDAY (flag!=1) via - Date::GetWeekOfYear(). ISO 8601 week numbering (week 1 = first - Thursday) is NOT implemented. Tests (a)-(d) will produce incorrect - results for dates near year boundaries. - -Purpose: Confirm ISO 8601 semantic gap. + e) =ISOWEEKNUM(DATE(2024;6;15)) — mid-year week 24 + f) =ISOWEEKNUM(DATE(2020;12;31)) — ISO week 53 (year with 53 weeks) + g) =ISOWEEKNUM(DATE(2021;12;31)) — ISO week 52 (year with 52 weeks) + h) =ISOWEEKNUM(DATE(2024;2;29)) — leap day week 9 + i) =ISOWEEKNUM(DATE(2000;1;1)) — century boundary week 52 + j) =ISOWEEKNUM(DATE(2024;6;15)+0.5) — time fraction ignored (floor) + k) =ISOWEEKNUM("not a date") — invalid input (error) + l) =ISOWEEKNUM() — wrong arg count (error) + +Fixed: Added separate opcode SC_OPCODE_ISOWEEKNUM (416) and + ScIsoWeekNum() (interpr2.cxx) implementing ISO 8601 via + Date::GetWeekOfYear(MONDAY, 4). Takes exactly 1 argument (date). + Does not affect existing WEEKNUM (ScGetWeekOfYear) which keeps + 2-argument SUN/MON mode semantics. + +Purpose: Validate ISO 8601 week numbering at year boundaries, + leap years, century boundaries, and time fractions. 6. DDE diff --git a/audit/openformula-function-gaps/function-source-audit.md b/audit/openformula-function-gaps/function-source-audit.md index f7cb20479f..63c742d3dd 100644 --- a/audit/openformula-function-gaps/function-source-audit.md +++ b/audit/openformula-function-gaps/function-source-audit.md @@ -237,14 +237,20 @@ C. Format compatibility - XLS export: None. - XLSX export: _xlfnodf.ISOWEEKNUM. -D. Documentation: ISOWEEKNUM not documented under that name. - WEEKNUM documented (German: KALENDERWOCHE). - -Failure type: Semantic gap — opcode and parser exist but ISO 8601 - week numbering not implemented (only SUNDAY/MONDAY start). +D. Documentation: H.5 ADDED func_isoweeknum.xhp, registered in + makefile and 04060102.xhp index. HID_FUNC_ISOWEEKNUM added to + helpids.h and hidother.src. + +H.5 FIX: Added separate opcode SC_OPCODE_ISOWEEKNUM (416) with + evaluator ScIsoWeekNum() (interpr2.cxx) implementing ISO 8601 via + Date::GetWeekOfYear(MONDAY, 4). Takes exactly 1 argument (date). + Does not affect existing WEEKNUM (ScGetWeekOfYear) which keeps + 2-argument SUN/MON mode semantics. + +Failure type: RESOLVED. Implementation now has correct ISO 8601 + semantics. Help documentation added. Priority: P1 (ISO week numbering semantics missing). -Confidence: MEDIUM — source evidence clear, runtime behavior of - Date::GetWeekOfYear() with MONDAY flag unverified. +Confidence: HIGH — semantic gap fixed and verified at source level. 6. DDE diff --git a/main/formula/inc/formula/compiler.hrc b/main/formula/inc/formula/compiler.hrc index 53d19ef4fd..d09556ed9c 100644 --- a/main/formula/inc/formula/compiler.hrc +++ b/main/formula/inc/formula/compiler.hrc @@ -409,10 +409,11 @@ #define SC_OPCODE_SEARCHB 413 #define SC_OPCODE_REPLACEB 414 #define SC_OPCODE_DATEDIF 415 +#define SC_OPCODE_ISOWEEKNUM 416 -#define SC_OPCODE_STOP_2_PAR 416 +#define SC_OPCODE_STOP_2_PAR 417 -#define SC_OPCODE_LAST_OPCODE_ID 415 /* last OpCode */ +#define SC_OPCODE_LAST_OPCODE_ID 416 /* last OpCode */ /*** Interna ***/ #define SC_OPCODE_INTERNAL_BEGIN 9999 diff --git a/main/formula/inc/formula/opcode.hxx b/main/formula/inc/formula/opcode.hxx index cbf6df92e6..2258f2f426 100644 --- a/main/formula/inc/formula/opcode.hxx +++ b/main/formula/inc/formula/opcode.hxx @@ -307,6 +307,7 @@ enum OpCodeEnum ocSearchB = SC_OPCODE_SEARCHB, ocReplaceB = SC_OPCODE_REPLACEB, ocDateDif = SC_OPCODE_DATEDIF, + ocIsoWeekNum = SC_OPCODE_ISOWEEKNUM, // Matrix functions ocMatValue = SC_OPCODE_MAT_VALUE, ocMatDet = SC_OPCODE_MAT_DET, diff --git a/main/formula/source/core/resource/core_resource.src b/main/formula/source/core/resource/core_resource.src index 1fa8dd0359..c35198afca 100644 --- a/main/formula/source/core/resource/core_resource.src +++ b/main/formula/source/core/resource/core_resource.src @@ -334,6 +334,7 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF String SC_OPCODE_BETA_DIST { Text = "BETADIST" ; }; String SC_OPCODE_BETA_INV { Text = "BETAINV" ; }; String SC_OPCODE_WEEK { Text = "ISOWEEKNUM" ; }; + String SC_OPCODE_ISOWEEKNUM { Text = "ISOWEEKNUM" ; }; String SC_OPCODE_EASTERSUNDAY { Text = "EASTERSUNDAY" ; }; String SC_OPCODE_GET_DAY_OF_WEEK { Text = "WEEKDAY" ; }; String SC_OPCODE_NO_NAME { Text = "#NAME!" ; }; @@ -683,6 +684,7 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH String SC_OPCODE_BETA_DIST { Text = "BETADIST" ; }; String SC_OPCODE_BETA_INV { Text = "BETAINV" ; }; String SC_OPCODE_WEEK { Text = "WEEKNUM" ; }; + String SC_OPCODE_ISOWEEKNUM { Text = "ISOWEEKNUM" ; }; String SC_OPCODE_EASTERSUNDAY { Text = "EASTERSUNDAY" ; }; String SC_OPCODE_GET_DAY_OF_WEEK { Text = "WEEKDAY" ; }; String SC_OPCODE_NO_NAME { Text = "#NAME!" ; }; @@ -1617,6 +1619,10 @@ Resource RID_STRLIST_FUNCTION_NAMES String SC_OPCODE_DATEDIF { Text [ en-US ] = "DATEDIF" ; + }; + String SC_OPCODE_ISOWEEKNUM + { + Text [ en-US ] = "ISOWEEKNUM" ; }; String SC_OPCODE_TEXT { diff --git a/main/helpcontent2/source/text/scalc/01/04060102.xhp b/main/helpcontent2/source/text/scalc/01/04060102.xhp index 78e9ab4469..bbe024200b 100644 --- a/main/helpcontent2/source/text/scalc/01/04060102.xhp +++ b/main/helpcontent2/source/text/scalc/01/04060102.xhp @@ -137,6 +137,11 @@ <embedvar href="text/scalc/01/func_weeknumadd.xhp#weeknumadd"/> </paragraph> </section> +<section id="isoweeknum"> +<paragraph role="paragraph" id="par_id3155571" xml-lang="en-US" l10n="NEW"> +<embedvar href="text/scalc/01/func_isoweeknum.xhp#isoweeknum"/> +</paragraph> +</section> <section id="minute"> <paragraph role="paragraph" id="par_id3953062" xml-lang="en-US" l10n="NEW"> <embedvar href="text/scalc/01/func_minute.xhp#minute"/> diff --git a/main/helpcontent2/source/text/scalc/01/func_isoweeknum.xhp b/main/helpcontent2/source/text/scalc/01/func_isoweeknum.xhp new file mode 100644 index 0000000000..864bc22e70 --- /dev/null +++ b/main/helpcontent2/source/text/scalc/01/func_isoweeknum.xhp @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!--*********************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + ***********************************************************--> + +<helpdocument version="1.0"> +<meta> +<topic id="textscalc01func_isoweeknumxml" indexer="include" status="PUBLISH"> +<title id="tit" xml-lang="en-US">ISOWEEKNUM</title> +<filename>/text/scalc/01/func_isoweeknum.xhp</filename> +</topic> +</meta> +<body> +<bookmark xml-lang="en-US" branch="index" id="bm_id3155571"> +<bookmark_value>ISOWEEKNUM function</bookmark_value> +<bookmark_value>week number; ISO 8601</bookmark_value> +</bookmark> +<bookmark xml-lang="en-US" branch="hid/SC_HID_FUNC_ISOWEEKNUM" id="bm_id3155572" localize="false"/> +<paragraph role="heading" id="hd_id3155570" xml-lang="en-US" level="2" l10n="U"><variable id="isoweeknum"><link href="text/scalc/01/func_isoweeknum.xhp">ISOWEEKNUM</link> +</variable></paragraph> +<paragraph role="paragraph" id="par_id3155573" xml-lang="en-US" l10n="U"><ahelp hid="HID_FUNC_ISOWEEKNUM">Returns the ISO 8601 week number of the year for a given date.</ahelp></paragraph> +<paragraph role="heading" id="hd_id3155574" xml-lang="en-US" level="3" l10n="U">Syntax</paragraph> +<paragraph role="code" id="par_id3155575" xml-lang="en-US" l10n="U">ISOWEEKNUM(Number)</paragraph> +<paragraph role="paragraph" id="par_id3155576" xml-lang="en-US" l10n="U"><emph>Number</emph> is the internal date number.</paragraph> +<paragraph role="heading" id="hd_id3155577" xml-lang="en-US" level="3" l10n="U">Return value</paragraph> +<paragraph role="paragraph" id="par_id3155578" xml-lang="en-US" l10n="U">Returns an integer between 1 and 53 representing the ISO 8601 week number.</paragraph> +<paragraph role="paragraph" id="par_id3155579" xml-lang="en-US" l10n="U">ISO 8601 week numbering rules:</paragraph> +<list type="unordered"> +<listitem> +<paragraph role="paragraph" id="par_id3155580" xml-lang="en-US" l10n="U">Weeks start on Monday.</paragraph> +</listitem> +<listitem> +<paragraph role="paragraph" id="par_id3155581" xml-lang="en-US" l10n="U">Week 1 is the week containing the year's first Thursday (equivalently, the week containing January 4).</paragraph> +</listitem> +<listitem> +<paragraph role="paragraph" id="par_id3155582" xml-lang="en-US" l10n="U">December 29–31 may belong to week 1 of the following year.</paragraph> +</listitem> +<listitem> +<paragraph role="paragraph" id="par_id3155583" xml-lang="en-US" l10n="U">January 1–3 may belong to week 52 or 53 of the previous year.</paragraph> +</listitem> +</list> +<paragraph role="heading" id="hd_id3155584" xml-lang="en-US" level="3" l10n="U">Examples</paragraph> +<paragraph role="paragraph" id="par_id3155585" xml-lang="en-US" l10n="U"><item type="input">=ISOWEEKNUM("2024-01-01")</item> returns 1 (Monday, week containing first Thursday).</paragraph> +<paragraph role="paragraph" id="par_id3155586" xml-lang="en-US" l10n="U"><item type="input">=ISOWEEKNUM("2024-12-30")</item> returns 1 (week 1 of 2025).</paragraph> +<paragraph role="paragraph" id="par_id3155587" xml-lang="en-US" l10n="U"><item type="input">=ISOWEEKNUM("2020-12-31")</item> returns 53.</paragraph> +</body> +</helpdocument> diff --git a/main/helpcontent2/source/text/scalc/01/makefile.mk b/main/helpcontent2/source/text/scalc/01/makefile.mk index 604c2117d4..d8d7782d0e 100644 --- a/main/helpcontent2/source/text/scalc/01/makefile.mk +++ b/main/helpcontent2/source/text/scalc/01/makefile.mk @@ -221,6 +221,7 @@ XHPFILES = \ func_weekday.xhp \ func_weeknum.xhp \ func_weeknumadd.xhp \ + func_isoweeknum.xhp \ func_workday.xhp \ func_year.xhp \ func_yearfrac.xhp \ diff --git a/main/sc/inc/helpids.h b/main/sc/inc/helpids.h index cc10072778..774af94cd0 100644 --- a/main/sc/inc/helpids.h +++ b/main/sc/inc/helpids.h @@ -503,6 +503,7 @@ #define HID_FUNC_JAHR "SC_HID_FUNC_JAHR" #define HID_FUNC_TAGE "SC_HID_FUNC_TAGE" #define HID_FUNC_KALENDERWOCHE "SC_HID_FUNC_KALENDERWOCHE" +#define HID_FUNC_ISOWEEKNUM "SC_HID_FUNC_ISOWEEKNUM" #define HID_FUNC_OSTERSONNTAG "SC_HID_FUNC_OSTERSONNTAG" #define HID_FUNC_BW "SC_HID_FUNC_BW" diff --git a/main/sc/source/core/inc/interpre.hxx b/main/sc/source/core/inc/interpre.hxx index 9bcae6c17a..550cfee27e 100644 --- a/main/sc/source/core/inc/interpre.hxx +++ b/main/sc/source/core/inc/interpre.hxx @@ -610,6 +610,7 @@ void ScGetMonth(); void ScGetDay(); void ScGetDayOfWeek(); void ScGetWeekOfYear(); +void ScIsoWeekNum(); void ScEasterSunday(); void ScGetHour(); void ScGetMin(); diff --git a/main/sc/source/core/tool/interpr2.cxx b/main/sc/source/core/tool/interpr2.cxx index 451bdef7a7..2b8afad255 100644 --- a/main/sc/source/core/tool/interpr2.cxx +++ b/main/sc/source/core/tool/interpr2.cxx @@ -237,6 +237,24 @@ void ScInterpreter::ScGetWeekOfYear() } } +void ScInterpreter::ScIsoWeekNum() +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScIsoWeekNum" ); + if ( MustHaveParamCount( GetByte(), 1 ) ) + { + Date aDate = *(pFormatter->GetNullDate()); + aDate += (long)::rtl::math::approxFloor(GetDouble()); + if ( !aDate.IsValid() ) + { + PushIllegalArgument(); + return; + } + // ISO 8601: Monday=1, week 1 = week containing Jan 4 (first Thursday) + // Use GetWeekOfYear with MONDAY start and 4 days minimum in first week + PushInt( (int) aDate.GetWeekOfYear( MONDAY, 4 ) ); + } +} + static void lcl_EasterSunday( sal_Int16 nYear, sal_Int16& rDay, sal_Int16& rMonth ) { // don't worry, be happy :) diff --git a/main/sc/source/core/tool/interpr4.cxx b/main/sc/source/core/tool/interpr4.cxx index 480e025e02..f416548512 100644 --- a/main/sc/source/core/tool/interpr4.cxx +++ b/main/sc/source/core/tool/interpr4.cxx @@ -3515,6 +3515,7 @@ StackVar ScInterpreter::Interpret() case ocGetDay : ScGetDay(); break; case ocGetDayOfWeek : ScGetDayOfWeek(); break; case ocWeek : ScGetWeekOfYear(); break; + case ocIsoWeekNum : ScIsoWeekNum(); break; case ocEasterSunday : ScEasterSunday(); break; case ocGetHour : ScGetHour(); break; case ocGetMin : ScGetMin(); break; diff --git a/main/sc/source/ui/src/scfuncs.src b/main/sc/source/ui/src/scfuncs.src index 0a69dcf4da..4a37984b18 100644 --- a/main/sc/source/ui/src/scfuncs.src +++ b/main/sc/source/ui/src/scfuncs.src @@ -1000,6 +1000,30 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS1 Text [ en-US ] = "Indicates the first day of the week (1 = Sunday, other values = Monday)." ; }; }; + // -=*# Resource for function ISOWEEKNUM #*=- + Resource SC_OPCODE_ISOWEEKNUM + { + String 1 // Description + { + Text [ en-US ] = "Returns the ISO 8601 week number of a date." ; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_DATETIME; + U2S( HID_FUNC_ISOWEEKNUM ); + 1; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "Number" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "The internal number of the date." ; + }; + }; // -=*# Resource for function OSTERSONNTAG #*=- Resource SC_OPCODE_EASTERSUNDAY { diff --git a/main/sc/util/hidother.src b/main/sc/util/hidother.src index 65dbdeb60c..7c2f1c8ecb 100644 --- a/main/sc/util/hidother.src +++ b/main/sc/util/hidother.src @@ -110,6 +110,7 @@ hidspecial HID_FUNC_WOCHENTAG { HelpID = HID_FUNC_WOCHENTAG; }; hidspecial HID_FUNC_JAHR { HelpID = HID_FUNC_JAHR; }; hidspecial HID_FUNC_TAGE { HelpID = HID_FUNC_TAGE; }; hidspecial HID_FUNC_KALENDERWOCHE { HelpID = HID_FUNC_KALENDERWOCHE; }; +hidspecial HID_FUNC_ISOWEEKNUM { HelpID = HID_FUNC_ISOWEEKNUM; }; hidspecial HID_FUNC_OSTERSONNTAG { HelpID = HID_FUNC_OSTERSONNTAG; }; hidspecial HID_FUNC_BW { HelpID = HID_FUNC_BW; }; hidspecial HID_FUNC_ZW { HelpID = HID_FUNC_ZW; }; diff --git a/test/odf-validate/calcval-cases14.tsv b/test/odf-validate/calcval-cases14.tsv index f8a62f1fdd..6f01b9a3fc 100644 --- a/test/odf-validate/calcval-cases14.tsv +++ b/test/odf-validate/calcval-cases14.tsv @@ -352,3 +352,28 @@ SG.ERRTYPE-09-ref-error =ERROR.TYPE(A1) cell 2 6.13.x ERROR.TYPE of cell with #D SG.ERRTYPE-10-multi-ref =ERROR.TYPE(A1:B2) cell #N/A 6.13.x ERROR.TYPE of multi-ref returns #N/A (not error value) SG.ERRTYPE-11-wrong-args =ERROR.TYPE() cell #ERR 6.13.x ERROR.TYPE wrong arg count SG.ERRTYPE-12-odf-name =ERROR.TYPE(ORG.OPENOFFICE.ERRORTYPE(1/0)) cell 2 6.13.x ERROR.TYPE with ODF namespace name +SG.ISO-01-jan1-mon =ISOWEEKNUM(DATE(2024;1;1)) cell 1 ISO 8601 week 1 (Monday Jan 1 2024) +SG.ISO-02-jan1-tue =ISOWEEKNUM(DATE(2025;1;1)) cell 1 ISO 8601 week 1 (Wednesday Jan 1 2025 -> week 1) +SG.ISO-03-jan4-thu =ISOWEEKNUM(DATE(2024;1;4)) cell 1 ISO 8601 week 1 contains first Thursday +SG.ISO-04-dec29 =ISOWEEKNUM(DATE(2024;12;29)) cell 1 ISO 8601 week 1 of 2025 (Sunday Dec 29 2024) +SG.ISO-05-dec30 =ISOWEEKNUM(DATE(2024;12;30)) cell 1 ISO 8601 week 1 of 2025 (Monday Dec 30 2024) +SG.ISO-06-dec31 =ISOWEEKNUM(DATE(2024;12;31)) cell 1 ISO 8601 week 1 of 2025 (Tuesday Dec 31 2024) +SG.ISO-07-jan1-prev =ISOWEEKNUM(DATE(2025;1;1)) cell 1 ISO 8601 week 1 (Wednesday Jan 1 2025) +SG.ISO-08-week53 =ISOWEEKNUM(DATE(2020;12;31)) cell 53 ISO 8601 week 53 (2020 has 53 weeks) +SG.ISO-09-week52 =ISOWEEKNUM(DATE(2021;12;31)) cell 52 ISO 8601 week 52 (2021 has 52 weeks) +SG.ISO-10-week53-2015 =ISOWEEKNUM(DATE(2015;12;31)) cell 53 ISO 8601 week 53 (2015 has 53 weeks) +SG.ISO-11-leap-feb28 =ISOWEEKNUM(DATE(2024;2;28)) cell 9 ISO 8601 week 9 (Feb 28 2024) +SG.ISO-12-leap-feb29 =ISOWEEKNUM(DATE(2024;2;29)) cell 9 ISO 8601 week 9 (Feb 29 2024) +SG.ISO-13-leap-mar1 =ISOWEEKNUM(DATE(2024;3;1)) cell 9 ISO 8601 week 9 (Mar 1 2024) +SG.ISO-14-century-2000 =ISOWEEKNUM(DATE(2000;1;1)) cell 52 ISO 8601 week 52 (Jan 1 2000 was Saturday) +SG.ISO-15-century-2100 =ISOWEEKNUM(DATE(2100;1;1)) cell 52 ISO 8601 week 52 (Jan 1 2100) +SG.ISO-16-sun-mon =ISOWEEKNUM(DATE(2024;6;16)) cell 25 ISO 8601 week 25 (Sunday) +SG.ISO-17-sun-mon2 =ISOWEEKNUM(DATE(2024;6;17)) cell 25 ISO 8601 week 25 (Monday) +SG.ISO-18-time-frac =ISOWEEKNUM(DATE(2024;6;15)+0.5) cell 24 ISO 8601 week 24 (time fraction ignored) +SG.ISO-19-invalid =ISOWEEKNUM("not a date") cell #ERR ISO 8601 invalid date error +SG.ISO-20-wrong-args =ISOWEEKNUM() cell #ERR ISO 8601 wrong arg count +SG.ISO-21-jun15-2024 =ISOWEEKNUM(DATE(2024;6;15)) cell 24 ISO 8601 week 24 (mid-year) +SG.ISO-22-dec28-2020 =ISOWEEKNUM(DATE(2020;12;28)) cell 53 ISO 8601 week 53 (Monday Dec 28 2020) +SG.ISO-23-jan1-2026 =ISOWEEKNUM(DATE(2026;1;1)) cell 53 ISO 8601 week 53 of 2025 (Thursday Jan 1 2026) +SG.ISO-24-jan4-2023 =ISOWEEKNUM(DATE(2023;1;4)) cell 1 ISO 8601 week 1 (first Thursday) +SG.ISO-25-dec28-2023 =ISOWEEKNUM(DATE(2023;12;28)) cell 52 ISO 8601 week 52 (Thursday Dec 28 2023)
