Skip to content

feat: WEEK() ISO-8601 week-number built-in (#44)#48

Merged
DDecoene merged 1 commit into
release/v1.2.0from
feature/44-week-builtin
Jul 9, 2026
Merged

feat: WEEK() ISO-8601 week-number built-in (#44)#48
DDecoene merged 1 commit into
release/v1.2.0from
feature/44-week-builtin

Conversation

@DDecoene

@DDecoene DDecoene commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Closes #44.

Summary

WEEK(date) → ISO-8601 week number (1–53). Monday-start weeks; week 1 is the week containing the year's first Thursday. Follows the YEAR()/MONTH()/DAY() shape from PR #17.

Implementation notes:

  • Computed in UTC (Date.UTC + getUTC*), so a local timezone offset can never shift the day across a week boundary.
  • ISO-shaped but impossible dates return 0 instead of silently rolling over — Date.UTC(2024, 1, 30) would otherwise yield Mar 1. A round-trip check rejects 2024-02-30, 2023-02-29, 2024-13-45. Real leap days (2024-02-29) still work.
  • Accepts ISO YYYY-MM-DD or MM/DD/YY; composes with CTOD().
  • Registered in BUILTIN_FUNCTIONS in Parser.ts. Implementing a built-in in Builtins.ts alone leaves it unreachable (Unknown command: () — that's exactly how the More built-in functions: ROUND(), MOD(), MAX(), MIN(), TIME(), YEAR()/MONTH()/DAY() #4 built-ins shipped broken, and the new BuiltinsParse.test.ts case fails loudly without it (verified: I watched it fail before adding the registration).

Assistant parity

Not surfaced in the Assistant, consistent with every other built-in (ROUND, MOD, YEAR, MONTH, DAY, …): built-ins are expression-level functions used inside commands, not GUI-shaped actions, and none of them have sidebar entries. Nothing in the sidebar or HELP enumerates built-ins today.

Test plan

Ran serially (the two suites share data/, so they can't run concurrently).

  • npm test283/283 vitest (was 281). New cases in tests/Builtins.test.ts (direct: mid-year, week-1 rule, year-boundary 52/53, 53-week years, MM/DD/YY, invalid → 0, impossible-date rejection, leap day) and tests/BuiltinsParse.test.ts (through the parser).
  • npx playwright test75/75 (was 74). New parity-commands.spec.ts case types ? WEEK(...) into the real REPL and asserts the printed value ('19', '53', '52', '1'), not merely that the digits appear somewhere in the scrollback.
  • npx tsc --noEmit clean.

Docs

CHANGELOG.md, README.md (built-ins table), CLAUDE.md (new Built-in functions section incl. a "must also register in Parser.ts" warning, roadmap, test counts).

Also folds in two doc fixes missed by #43: server/ColumnMetaStore.ts and tests/TimeType.test.ts were absent from the CLAUDE.md architecture/test trees, and the test counts there were stale.

WEEK(date) returns the ISO-8601 week number (1-53): Monday-start
weeks, week 1 being the week that contains the year's first Thursday.
Early-January dates therefore report the previous year's week 52/53,
and late-December dates week 1 of the next year.

Accepts ISO YYYY-MM-DD or MM/DD/YY. Computed in UTC so a local
timezone offset can't shift the day, and ISO-shaped but impossible
dates (2024-02-30, 2023-02-29) return 0 rather than silently rolling
over the way Date.UTC does.

Registered in Parser's BUILTIN_FUNCTIONS — implementing a built-in
without whitelisting it there is how the #4 built-ins shipped broken.
Covered directly (Builtins.test.ts), through the parser
(BuiltinsParse.test.ts), and end-to-end in the REPL
(parity-commands.spec.ts), asserting the printed value.

Also refreshes the doc test counts and adds ColumnMetaStore.ts /
TimeType.test.ts to the CLAUDE.md trees, both missed in #43.
@DDecoene DDecoene merged commit f0532b5 into release/v1.2.0 Jul 9, 2026
2 checks passed
@DDecoene DDecoene deleted the feature/44-week-builtin branch July 9, 2026 17:09
@DDecoene DDecoene mentioned this pull request Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant