Skip to content

Commit 8dec3da

Browse files
committed
fix(core): resolve {next_week_end} and {next_year_end} in the client date-macro resolver
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CXcHcEtzn8WgUC46Xj
1 parent 9afcd6a commit 8dec3da

3 files changed

Lines changed: 65 additions & 5 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/core': patch
3+
---
4+
5+
fix(core): the client date-macro resolver answers `{next_week_end}` and `{next_year_end}`
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`resolveDateMacros` now resolves `{next_week_end}` (Sunday of next week, Monday-start weeks) and `{next_year_end}` (Dec 31 of next year), the two fixed tokens `@objectstack/spec`'s `DATE_MACRO_TOKENS` declared that the Console passed through as raw text. A test now reads `DATE_MACRO_TOKENS` from the spec and fails on any token the client leaves unresolved, so the two lists cannot drift again.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import { describe, it, expect } from 'vitest';
10+
import { DATE_MACRO_TOKENS } from '@objectstack/spec/data';
11+
import { resolveDateMacros } from '../date-macros';
12+
13+
/**
14+
* The client resolver answers every fixed token the spec declares
15+
* (objectstack#30134). The list is read from the spec, never copied, so a
16+
* token added there without a resolver entry here fails this file.
17+
*/
18+
describe('resolveDateMacros covers the spec vocabulary (objectstack#30134)', () => {
19+
// Monday 2026-05-25, local noon.
20+
const now = new Date(2026, 4, 25, 12, 0, 0);
21+
22+
it.each(DATE_MACRO_TOKENS.map((t) => [t]))('{%s} resolves to a day or an instant', (token) => {
23+
const out = resolveDateMacros(`{${token}}`, now);
24+
expect(out).not.toContain('{');
25+
expect(out).toMatch(/^\d{4}-\d{2}-\d{2}(T|$)/);
26+
});
27+
28+
it('{next_week_end} is the Sunday of next week (Monday-start weeks)', () => {
29+
// From a Monday.
30+
expect(resolveDateMacros('{next_week_end}', now)).toBe('2026-06-07');
31+
// From a Sunday: still the week after the one that Sunday closes.
32+
expect(resolveDateMacros('{next_week_end}', new Date(2026, 4, 31, 12))).toBe('2026-06-07');
33+
// Across a year boundary: Wednesday 2026-12-30 → next week is Jan 4–10, 2027.
34+
const dec30 = new Date(2026, 11, 30, 12);
35+
expect(resolveDateMacros('{next_week_start}', dec30)).toBe('2027-01-04');
36+
expect(resolveDateMacros('{next_week_end}', dec30)).toBe('2027-01-10');
37+
});
38+
39+
it('{next_year_end} is Dec 31 of next year', () => {
40+
expect(resolveDateMacros('{next_year_end}', now)).toBe('2027-12-31');
41+
// On Dec 31 itself the answer is a full year out, not today.
42+
expect(resolveDateMacros('{next_year_end}', new Date(2026, 11, 31, 12))).toBe('2027-12-31');
43+
// On Jan 1 the year has rolled: next year is 2028.
44+
expect(resolveDateMacros('{next_year_end}', new Date(2027, 0, 1, 12))).toBe('2028-12-31');
45+
});
46+
});

‎ui/packages/core/src/utils/date-macros.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ import { getDisplayTimeZone } from './date-display.js';
2727
* - last_month_start / last_month_end
2828
* - last_quarter_start / last_quarter_end
2929
* - last_year_start / last_year_end
30-
* - next_week_start / next_month_start / next_quarter_start / next_year_start
31-
* - next_month_end / next_quarter_end
30+
* - next_week_start / next_week_end
31+
* - next_month_start / next_month_end
32+
* - next_quarter_start / next_quarter_end
33+
* - next_year_start / next_year_end
3234
*
3335
* Parameterised tokens (match `N` as any positive integer):
3436
* - {N_minutes_ago} / {N_minutes_from_now} (returns full ISO timestamp)
@@ -39,9 +41,9 @@ import { getDisplayTimeZone } from './date-display.js';
3941
* - {N_years_ago} / {N_years_from_now}
4042
*
4143
* The canonical grammar is also published as part of the platform contract at
42-
* `@objectstack/spec` → `DATE_MACRO_TOKENS` / `DATE_MACRO_PARAM_RE`. Keep this
43-
* file in sync with the spec; the duplication is temporary until the next
44-
* coordinated `@objectstack/spec` release.
44+
* `@objectstack/spec` → `DATE_MACRO_TOKENS` / `DATE_MACRO_PARAM_RE`. Every
45+
* fixed token there must resolve here; `date-macros.specTokens-30134.test.ts`
46+
* reads the spec list and fails on any token this resolver leaves unresolved.
4547
*
4648
* Walks any plain-object / array structure recursively. Non-string values
4749
* (and unknown tokens) are passed through untouched.
@@ -128,11 +130,13 @@ export function resolveDateMacros<T = any>(filter: T, now: Date = new Date()): T
128130
last_year_end: () => isoDate(new Date(today.getFullYear() - 1, 11, 31)),
129131

130132
next_week_start: () => isoDate(addDays(startOfWeek(today), 7)),
133+
next_week_end: () => isoDate(addDays(startOfWeek(today), 13)),
131134
next_month_start: () => isoDate(addMonths(startOfMonth(today), 1)),
132135
next_month_end: () => isoDate(endOfMonth(addMonths(startOfMonth(today), 1))),
133136
next_quarter_start: () => isoDate(addMonths(startOfQuarter(today), 3)),
134137
next_quarter_end: () => isoDate(endOfQuarter(addMonths(startOfQuarter(today), 3))),
135138
next_year_start: () => isoDate(new Date(today.getFullYear() + 1, 0, 1)),
139+
next_year_end: () => isoDate(new Date(today.getFullYear() + 1, 11, 31)),
136140
};
137141

138142
// Aliases: bare {week_start} etc. mean the current period.

0 commit comments

Comments
 (0)