feat: WEEK() ISO-8601 week-number built-in (#44)#48
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 theYEAR()/MONTH()/DAY()shape from PR #17.Implementation notes:
Date.UTC+getUTC*), so a local timezone offset can never shift the day across a week boundary.0instead of silently rolling over —Date.UTC(2024, 1, 30)would otherwise yield Mar 1. A round-trip check rejects2024-02-30,2023-02-29,2024-13-45. Real leap days (2024-02-29) still work.YYYY-MM-DDorMM/DD/YY; composes withCTOD().BUILTIN_FUNCTIONSinParser.ts. Implementing a built-in inBuiltins.tsalone 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 newBuiltinsParse.test.tscase 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 orHELPenumerates built-ins today.Test plan
Ran serially (the two suites share
data/, so they can't run concurrently).npm test— 283/283 vitest (was 281). New cases intests/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) andtests/BuiltinsParse.test.ts(through the parser).npx playwright test— 75/75 (was 74). Newparity-commands.spec.tscase 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 --noEmitclean.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.tsandtests/TimeType.test.tswere absent from theCLAUDE.mdarchitecture/test trees, and the test counts there were stale.