feat: DATEADD() date-arithmetic built-in (#52) - #53
Merged
Conversation
DATEADD(date, n) returns the ISO date n days later; n may be negative. W3Script had no date arithmetic at all — CTOD/DTOC only reformat and YEAR/MONTH/DAY only decompose — so there was no way to say "the day after this one". demos/overtime.prg (#46) needs it to derive each TIMESHEET.WORKDATE from the week's Monday. Computed in UTC, so month, year and leap-day boundaries are exact and no local timezone offset can shift the day. Impossible ISO dates return '' rather than rolling over, matching WEEK(). WEEK() already parsed dates exactly this way, so that logic is extracted into a shared parseDateUTC() rather than duplicated. Registered in Parser's BUILTIN_FUNCTIONS, and covered directly, through the parser, and end-to-end in the REPL — the three-way coverage the #4 built-ins lacked when they shipped broken.
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 #52. Unblocks #46.
Why
W3Script has no date arithmetic.
CTOD/DTOConly reformat,YEAR/MONTH/DAYonly decompose — nothing can say "the day after this one".demos/overtime.prgneeds it to deriveTIMESHEET.WORKDATEfrom the week's Monday (WEEKDATE + (DOW-1)days). Surfaced while designing #46; the demo should have nothing to work around.What
DATEADD(date, n)→ the ISO datendays later (nmay be negative), asYYYY-MM-DD.2023-02-29,2024-13-01) return''rather than silently rolling over, matchingWEEK()'s round-trip rejection.YYYY-MM-DDorMM/DD/YY; composes withCTOD().WEEK()already parsed dates in exactly this way, so that logic is extracted into a sharedparseDateUTC()instead of duplicated. No behavior change toWEEK()(its tests are untouched and still pass).BUILTIN_FUNCTIONSinParser.ts— omitting that is how the More built-in functions: ROUND(), MOD(), MAX(), MIN(), TIME(), YEAR()/MONTH()/DAY() #4 built-ins shipped unreachable.Assistant parity
Not surfaced, consistent with every other built-in (
ROUND,WEEK,YEAR, …): built-ins are expression-level functions used inside commands, not GUI-shaped actions, and nothing in the sidebar orHELPenumerates them.Test plan
Suites run serially (they share
data/).npx tsc --noEmitclean.npm test— 369/369 vitest (was 358). New cases intests/Builtins.test.ts(direct: same month, month/year rollover, leap day2024-02-28→2024-02-29, non-leap2023-02-28→2023-03-01, negativen,n = 0normalisingMM/DD/YY→ISO, Monday+4, invalid/impossible →'') andtests/BuiltinsParse.test.ts(through the parser, plus composing withCTOD).npx playwright test— 84/84 (was 83). Newparity-commands.spec.tscase types? DATEADD(...)into the real REPL and asserts the printed value.Docs
CHANGELOG.md,README.mdandCLAUDE.mdbuilt-ins tables, test counts.