Repository navigation
fix(core): compareTo on a forward date range (next month, next quarter, next 30 days) compares with the period just before it, not with itself - #30196
Merged
Conversation
… just before it, not with itself
previousPeriod moved only current_* / today tokens, so a dashboard window of
next_month or next_quarter was compared with itself (a 0 change every time)
and next_30_days moved only its start. A forward window now steps back one
period: next_month_* to this month, next_quarter_* to this quarter, and a
{today} .. {N_days_from_now} pair to the N + 1 days ending yesterday. The
trend label names that window (vsThisMonth, vsThisQuarter, vsPreviousPeriod);
the two new keys are in all ten locale packs. The 13 backward presets keep
their windows and labels.
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzijmF7yUSk5ga9jRkh
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzijmF7yUSk5ga9jRkh
This was referenced Nov 5, 2026
Contributor
Author
|
domain:ui#1 · os-support-ai · session_01WGufzfE4V9fzZgJLrLDmMC 维护者速读(席位终稿)
席位核对 · ACCEPT · head
|
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.
Requested by Yibo Wang · project thread
Fixes #30140
维护者速读
compare-to.ts的一个纯函数和文案。其余 13 个预设的对比窗口与文字逐字节不变(新加对照钉住,另在 8 个参考日期上整表比对 main 与本分支一致)。回滚即 revert。ui/packages/core/src/utils/compare-to.ts的forwardRollingPair/shiftForwardRollingWindows(滚动窗口怎么认、怎么平移);② 同文件PREVIOUS_PERIOD_TOKENS为什么一次替换(两次会把下月一路推到上月);③compareToTrendLabelKey里前向判断排在后向判断之前。pnpm --dir ui exec vitest run packages/core/src/utils/__tests__/dashboard-filters.presetWindows-29116.test.ts,预期 16 个预设各有一条对比用例全部通过。Clause-②: no
Metadata-protocol: none
What changes
@object-ui/coreshiftFilterByCompareTo,kind: 'previousPeriod'. It substituted onlycurrent_*/todaytokens. The forward presets are spelled{next_month_start}…{next_month_end},{next_quarter_start}…{next_quarter_end}and{today}…{30_days_from_now}(DATE_RANGE_PRESET_MACRO_WINDOWS), so the first two compared the window with itself and the third moved only its start ({yesterday}…{30_days_from_now}, a 32-day window overlapping the current one). Now:NEXT_TO_CURRENT_TOKENSmapsnext_month_*/next_quarter_*tocurrent_*. It is merged withCURRENT_TO_LAST_TOKENSinto one map applied in ONE pass; a second pass would carrynext_month_starton tolast_month_start.{today}+{N_days_from_now}pair inside one field's operator object (or a two-member$between) moves back by its own length, N + 1 days:{(N+1)_days_ago}…{yesterday}. This runs first, so the generictoday→yesterdayswap never sees that{today}. A lone{today}, a lone{N_days_from_now}, and two FIELDS holding those tokens keep today's reading.next_week_start/next_year_startare not mapped: the macro vocabulary has no_endpartner for them, so no preset or closed window uses them.compareToTrendLabelKeynames the window really compared:vsThisMonth,vsThisQuarter, andvsPreviousPeriodfor a forward rolling window (it readvsLastMonth,vsLastQuarter,vsYesterday). Each forward check sits before the backward pattern that also matches it (quarter_startis insidenext_quarter_start).@object-ui/i18n:dashboard.trend.vsThisMonth/vsThisQuarterin all ten locale packs (zh 较本月 / 较本季度). No other existing key fits:vsLastMonthnames the wrong month, andvsPreviousPeriodis used where it is exact (the rolling window).ObjectMetricWidget,MetricWidget(its defaults table and its phrase-to-key map) andObjectChart's comparison-series label;plugin-dashboard/SKILL.md's label table gains the three rows.Why
Issue #30140: a should-fix from the contract review of #30133. The governing text is the
compare-to.tsdocblock: "kind: 'previousPeriod'— the equal-length window immediately before the current one". No spec change, no newcompareTokind, no new preset.Tests
compare-to.test.ts: next month → this month, next quarter → this quarter (also across a year boundary, from 2026-12-10),{today}…{30_days_from_now}→ the 31 days ending yesterday, a$betweenrolling window, and the cases that must NOT move (lone tokens, two fields). Label keys for all three, underpreviousPeriodandpreviousYear.dashboard-filters.presetWindows-29116.test.ts: the compareTo case now runs on all 16 presets, with a completeness pin. Each preset pins both kinds' windows and the label at 2026-07-15. Forward presets also assert, on all six reference dates, that the previous window ends the day before the current one starts (equal length fornext_30_days, starting on the 1st for the calendar ones).RETIRED_COMPARE_AT_REFERENCEholds the 13 earlier presets' windows and labels read offcompare-to.tsatb7075d99before the fix; the retired-spelling equivalence still runs on all six dates.ObjectMetricWidget.compareTo.forwardPresets-30140.test.tsx(rendered): the registeredobject-metricblock with each forward preset's window andcompareTo: previousPeriod. The data source answers 120 for the current window, 100 only for the expected previous window, 7 otherwise; the tile shows20%and the right label, and not the stale one.Acceptance notes
metricwidget is dataset-bound:DashboardRendererroutes it toDatasetWidget, and the comparison is shifted by the analytics executor (shiftRange), labelled fromcompareTo.kindalone (vsPreviousPeriod).shiftFilterByCompareToruns inObjectMetricWidget(theobject-metricblock) and inObjectChart(aprovider: 'object'series widget, which the dashboard date filter is broadcast into). Those are the surfaces this PR changes.tsxprobe oflowerDatasetCompareDateRange+inclusiveCalendarDayWindow+shiftRangewith the clock at 2026-07-15:next_month2026-08-01..08-31 → 2026-07-01..07-31;next_quarter2026-10-01..12-31 → 2026-07-01..09-30;next_30_days2026-07-15..08-14 → 2026-06-14..07-14. No forward window compares with itself, andnext_30_daysmatches this PR's inline window exactly. The executor counts days, so a forward month of 30 days (2026-09-01..09-30) compares with 2026-08-02..08-31, not calendar August; that is its rule for every preset (this_month2026-07-01..07-31 → 2026-05-31..06-30), not a forward-preset defect.yesterday,last_week,last_month,last_quarterandlast_yearcompare with themselves (nolast_*token is shifted; e.g.last_monthat 2026-07-15 → 2026-06-01..06-30), andlast_N_dayscompares an N + 1 day window with N days.previousYearfrom a leap day re-resolves at 2027-03-01, sothis_monthon 2028-02-29 compares with March 2027.metricwidget in the console would exercise the dataset path, which this PR does not touch.Verification
Suites, type-check, lint, ablations
pnpm --dir ui exec vitest run --maxWorkers=3 packages/<pkg>/underos-verify-lock: core exit 0, i18n exit 0, plugin-dashboard exit 0 (201 files, 1,925 passed, 6 skipped), plugin-charts exit 0 (103 files, 1,333 passed, 9 skipped).pnpm run type-checkin core, i18n, plugin-dashboard and plugin-charts: exit 0 each.npx eslinton every touched file: 0 errors (warnings only,no-explicit-any, as in the surrounding code).scripts/ablation-replace.mjs): previousPeriod back tosubstituteTokens(filter, CURRENT_TO_LAST_TOKENS)→ 11 failed / 70 passed across the three test files (every forward-window pin, the three forward 29116 rows, the three rendered rows); restored,git diff HEADempty.next_quarter_label check → 3 failed (label pin, thenext_quarter29116 row, the renderednext_quarterrow); restored.tsxprobe of all 16 presets × 8 reference dates × both kinds plus labels, onmainand on this branch — the 13 earlier presets' output is byte-identical; only the three forward presets change.dispatch-gates --commands, 35): see the report on Dashboard compareTo on a forward date preset (下月, 下季度, 未来 30 天) compares the window with itself #30140.Human Minimum
packages/specholds no runtime logic. (not touched)main, one pull request.packages/spectouched: n/a.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01WGufzijmF7yUSk5ga9jRkh