From 9310fbe56b417f5278bf6f21a014c3f8ebdb7ef0 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 22:08:01 +0000 Subject: [PATCH 1/5] fix(plugin-list): a date condition value reads as a date in the viewer's locale Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QSeKYnagJvGbCtNg2PhvgW --- .../src/conditions/ListConditionControls.tsx | 27 +++++--- .../__tests__/listConditions.test.tsx | 66 +++++++++++++++++++ .../src/conditions/conditionDates.ts | 53 +++++++++++++++ 3 files changed, 136 insertions(+), 10 deletions(-) create mode 100644 ui/packages/plugin-list/src/conditions/conditionDates.ts diff --git a/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx b/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx index c454953b494..fdd48a9d426 100644 --- a/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx +++ b/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx @@ -43,8 +43,9 @@ import { type SortItem, } from '@object-ui/components'; import { referencedRecordTitle } from '@object-ui/core'; +import { formatConditionDate } from './conditionDates'; import type { DataSource } from '@object-ui/types'; -import { useSafeFieldLabel } from '@object-ui/i18n'; +import { useDisplayLocale, useSafeFieldLabel } from '@object-ui/i18n'; import { ArrowDown, ArrowUp, ArrowUpDown, ListFilter, Lock, Plus, RotateCcw, SlidersHorizontal, X } from 'lucide-react'; import { FieldList, type FieldListItem } from './FieldList'; import { FilterValuePanel, isQuickRowApplied, quickDateWindowOf } from './FilterValuePanel'; @@ -84,7 +85,8 @@ export type LookupValueName = (field: string, id: string) => string | undefined; /** * The value half of a chip: 「Negotiation, Proposal」, 「≥ 100」, 「Today」. * A lookup's value is the referenced record's name when `nameOf` has it, and - * its id only when the name cannot be read. + * its id only when the name cannot be read. A date field's value reads as a + * date in `locale` (`formatConditionDate`), never as the stored ISO string. */ export function describeConditionValue( field: ConditionField | undefined, @@ -92,6 +94,7 @@ export function describeConditionValue( value: unknown, t: Translate, nameOf?: LookupValueName, + locale?: string, ): string { const opLabel = quickOperatorLabel(operator, t); if (isValuelessOperator(operator)) return opLabel; @@ -102,16 +105,17 @@ export function describeConditionValue( // A named window says what it is on its own: 「Today」, not 「between Today」. const window = family === 'date' && operator === 'between' ? quickDateWindowOf(value as FilterBuilderRow['value']) : undefined; if (window) return quickDateWindowLabel(window, t); + const shown = family === 'date' ? (v: unknown) => formatConditionDate(v, field?.type, locale) : String; if (family === 'boolean') { text = list.map((v) => (v === true || v === 'true' ? t('listConditions.filter.yes') : t('listConditions.filter.no'))).join(joiner); } else if (operator === 'between') { - text = list.map(String).join(' – '); + text = list.map(shown).join(' – '); } else if (family === 'option') { text = list.map((v) => optionLabel(field, v)).join(joiner); } else if (family === 'lookup' && field && nameOf) { text = list.map((v) => nameOf(field.value, String(v)) ?? String(v)).join(joiner); } else { - text = list.map(String).join(joiner); + text = list.map(shown).join(joiner); } // 「is any of」 is what a value list means on its own; every other operator is // named, and with no value it is the operator alone, never one with a trailing space. @@ -126,10 +130,11 @@ function chipText( value: unknown, t: Translate, nameOf?: LookupValueName, + locale?: string, ) { return t('listConditions.chips.pattern', { field: field?.label ?? fieldName ?? '', - value: describeConditionValue(field, operator, value, t, nameOf), + value: describeConditionValue(field, operator, value, t, nameOf, locale), }); } @@ -139,9 +144,10 @@ function viewChipText( t: Translate, nameOf?: LookupValueName, relatedFieldOf?: RelatedFieldOf, + locale?: string, ): string { if (chip.anyOf) { - return chip.anyOf.map((member) => viewChipText(member, fields, t, nameOf, relatedFieldOf)).join(t('listConditions.chips.or')); + return chip.anyOf.map((member) => viewChipText(member, fields, t, nameOf, relatedFieldOf, locale)).join(t('listConditions.chips.or')); } if (!chip.field || !chip.operator) return t('listConditions.chips.viewFilter'); const path = relationPathOf(chip.field); @@ -156,11 +162,11 @@ function viewChipText( }); return t('listConditions.chips.pattern', { field: label, - value: describeConditionValue(related, chip.operator, chip.value, t), + value: describeConditionValue(related, chip.operator, chip.value, t, undefined, locale), }); } const field = fields.find((f) => f.value === chip.field); - return chipText(field, chip.field, chip.operator, chip.value, t, nameOf); + return chipText(field, chip.field, chip.operator, chip.value, t, nameOf, locale); } // --------------------------------------------------------------------------- @@ -659,6 +665,7 @@ export function ConditionChipRow({ className, }: ConditionChipRowProps) { const { t } = useListConditionTranslation(); + const locale = useDisplayLocale(); const [openChip, setOpenChip] = React.useState(null); // Keyed on the names, not on the array the host may rebuild every render. @@ -773,7 +780,7 @@ export function ConditionChipRow({ )} {viewChips.map((chip) => { - const text = viewChipText(chip, filterFields, t, nameOf, relatedFieldOf); + const text = viewChipText(chip, filterFields, t, nameOf, relatedFieldOf, locale); return ( { const field = fieldOf(filterFields, row.field); - const text = chipText(field, row.field, row.operator, row.value, t, nameOf); + const text = chipText(field, row.field, row.operator, row.value, t, nameOf, locale); return ( = 10', 'Deal Value: != 0']); }); }); + +// objectstack#37034 — a date condition's value reads as a date in the viewer's +// language, by the field's type, on every condition row: a drilled month +// bucket's two bounds (the rows `drillListConditions` writes from the dataset +// answer's `{ $gte, $lt }`, ISO instants at UTC midnight) included. +describe('date condition values read as dates (objectstack#37034)', () => { + const ISSUED_ON: ConditionField = { value: 'issued_on', label: '开具日期', type: 'date' }; + const CREATED_AT: ConditionField = { value: 'created_at', label: '创建时间', type: 'datetime' }; + const STARTS_AT: ConditionField = { value: 'starts_at', label: 'Starts at', type: 'time' }; + const rows = (conditions: Array<[string, string, unknown]>): FilterBuilderRowGroup => ({ + id: 'root', + logic: 'and', + conditions: conditions.map(([field, operator, value], i) => ({ id: `r${i}`, field, operator, value }) as FilterBuilderRow), + }); + function zhChips(filters: FilterBuilderRowGroup, field: string): string[] { + render( + + {}} + filters={filters} + filterFields={[ISSUED_ON, CREATED_AT]} + onFiltersChange={() => {}} + renderAdvanced={() =>
} + renderSortLevels={() =>
} + /> + , + ); + return screen.getAllByTestId(`filter-chip-open-${field}`).map((b) => b.textContent ?? ''); + } + + it('a drilled month bucket on a date field shows its range as two date rows, not ISO', () => { + const chips = zhChips(rows([ + ['issued_on', 'greater_than_or_equal', '2026-10-01T00:00:00.000Z'], + ['issued_on', 'before', '2026-11-01T00:00:00.000Z'], + ]), 'issued_on'); + expect(chips).toHaveLength(2); + // A day bound at UTC midnight names that day in every zone. + expect(chips[0]).toContain('2026年10月1日'); + expect(chips[1]).toContain('2026年11月1日'); + for (const chip of chips) { + expect(chip).toContain('开具日期'); + expect(chip).not.toMatch(/T\d\d:\d\d/); + } + }); + + it('a datetime field reads as a localized date and time, not ISO', () => { + // Noon UTC: the same calendar day in every zone a test runner sits in. + const [chip] = zhChips(rows([['created_at', 'greater_than_or_equal', '2026-10-15T12:00:00.000Z']]), 'created_at'); + expect(chip).toContain('创建时间'); + expect(chip).toContain('2026年10月15日'); + expect(chip).not.toContain('2026-10-15T12:00:00.000Z'); + }); + + it('a date between reads both ends as dates', () => { + const [chip] = zhChips(rows([['issued_on', 'between', ['2026-10-01', '2026-10-31']]]), 'issued_on'); + expect(chip).toContain('2026年10月1日 – 2026年10月31日'); + }); + + it('CONTROL: a time field and an unreadable value are shown as written', () => { + const { t } = { t: (k: string) => LIST_CONDITION_DEFAULT_TRANSLATIONS[k] ?? k }; + expect(describeConditionValue(STARTS_AT, 'after', '09:30', t as never, undefined, 'zh-CN')).toBe('after 09:30'); + expect(describeConditionValue(ISSUED_ON, 'after', 'not a date', t as never, undefined, 'zh-CN')).toBe('after not a date'); + }); +}); diff --git a/ui/packages/plugin-list/src/conditions/conditionDates.ts b/ui/packages/plugin-list/src/conditions/conditionDates.ts new file mode 100644 index 00000000000..280428d3b12 --- /dev/null +++ b/ui/packages/plugin-list/src/conditions/conditionDates.ts @@ -0,0 +1,53 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * How a date condition's value reads on a condition row (objectstack#37034). + * + * A row holds the value the query compares: a calendar day (`2026-10-01`) or + * an instant (`2026-10-01T00:00:00.000Z`, the bound a dataset bucket's drill + * writes). The row printed it as written, so a zh-CN chip read + * 「≥ 2026-10-01T00:00:00.000Z」. It reads as a date now, in the viewer's + * display locale, through the console's ONE date display path + * (`formatDate` / `formatDateTime` in `@object-ui/core`'s `date-display`): + * ⛔ no second formatter is written here. + * + * The field's type decides the face: + * + * - `date` names a calendar day, so the day is shown, with its year (a + * condition's bounds are read side by side). An instant at UTC midnight on + * a date field is how a day bound is written on the wire; it names that day + * in every zone, so its leading `YYYY-MM-DD` is what is shown — read as an + * instant it would name the previous day west of UTC. + * - `datetime` is an instant: the date and the time in the display zone. + * - `time` and anything else are shown as written. + * + * A value the display path cannot read (it answers `—`) is shown as written, + * so a row never hides what it compares. + */ + +import { formatDate, formatDateTime } from '@object-ui/core'; + +/** An instant at UTC midnight, captured as its calendar day. */ +const UTC_MIDNIGHT = /^(\d{4}-\d{2}-\d{2})T00:00(?::00(?:\.0+)?)?(?:Z|[+-]00:?00)$/; + +/** A date condition value as the row shows it: see the file header. */ +export function formatConditionDate(value: unknown, fieldType: string | undefined, locale: string | undefined): string { + if (typeof value !== 'string' && typeof value !== 'number') return String(value); + if (value === '') return value; + let shown: string; + if (fieldType === 'date') { + const day = typeof value === 'string' ? UTC_MIDNIGHT.exec(value)?.[1] ?? value : value; + shown = formatDate(day, undefined, { locale, alwaysShowYear: true }); + } else if (fieldType === 'datetime') { + shown = formatDateTime(value, { locale }); + } else { + return String(value); + } + return shown === '—' ? String(value) : shown; +} From f960940cb5909e74b52f423b44573b0f4ca803df Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 22:10:43 +0000 Subject: [PATCH 2/5] fix(app-showcase): zh-CN labels for the invoice region and account sales region fields Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QSeKYnagJvGbCtNg2PhvgW --- examples/app-showcase/src/system/translations/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/app-showcase/src/system/translations/index.ts b/examples/app-showcase/src/system/translations/index.ts index d5b892212c4..0d69ab6dc49 100644 --- a/examples/app-showcase/src/system/translations/index.ts +++ b/examples/app-showcase/src/system/translations/index.ts @@ -624,6 +624,10 @@ export const ShowcaseTranslationBundle = { billing_email: { label: '账单邮箱' }, support_config: { label: '支持配置' }, churn_reason: { label: '流失原因' }, + // The account side of the Revenue Pulse region filter + // (`filterBindings: { region: 'sales_region' }`), worded as the + // dataset's dimension describes it (销售区域). + sales_region: { label: '销售区域', options: { amer: '美洲', emea: '欧洲、中东和非洲', apac: '亚太' } }, }, // The zh-CN mirror of the `en` `_validations` block — see the note // there. Vocabulary is the one this bundle already established: @@ -758,6 +762,10 @@ export const ShowcaseTranslationBundle = { owner: { label: '负责人邮箱' }, status: { label: '状态' }, issued_on: { label: '开具日期' }, + // The Revenue Pulse dashboard's region filter lands on this field, so + // a drilled list's chip names it: the same words as the dashboard's + // own filter label and options (`dashboards.showcase_revenue_pulse`). + region: { label: '区域', options: { amer: '美洲', emea: '欧洲、中东和非洲', apac: '亚太' } }, tax_rate: { label: '税率 (%)' }, paid_on: { label: '付款日期' }, total: { label: '小计' }, From c85b502292777bf5c9a5dbe95aa1b594fdcd2f84 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 22:18:32 +0000 Subject: [PATCH 3/5] test(plugin-dashboard): pin a month bucket's drill rows Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QSeKYnagJvGbCtNg2PhvgW --- .../src/__tests__/drillConditions-36256.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts index 97801cb4790..543adb416f1 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts +++ b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts @@ -57,6 +57,23 @@ describe('drillListConditions', () => { ]); }); + it("writes a dataset month bucket's range as two date rows that compare exactly what the bucket counted (objectstack#37034)", () => { + // The dataset answer's drill range for 2026-10: `{ $gte, $lt }`, ISO + // instants (core's dataset-format). The list's chip reads each bound as a + // date (plugin-list `formatConditionDate`); the value stays the one the + // query compares. No date-family operator says "on or after", and `after` + // (>) would drop the records at the bound, so the lower bound keeps `>=`. + const { chips, rest } = drillListConditions( + { issued_on: { $gte: '2026-10-01T00:00:00.000Z', $lt: '2026-11-01T00:00:00.000Z' } }, + { dateFields: new Set(['issued_on']) }, + ); + expect(rest).toBeUndefined(); + expect(chips.conditions.map((c) => [c.field, c.operator, c.value])).toEqual([ + ['issued_on', 'greater_than_or_equal', '2026-10-01T00:00:00.000Z'], + ['issued_on', 'before', '2026-11-01T00:00:00.000Z'], + ]); + }); + it("lowers a page block's rule array, and an AST node, to chips", () => { // HotCRM's 销售主页 KPI tile: the spec's rule-array form, handed as written. expect(drillListConditions([{ field: 'stage', operator: 'equals', value: 'closed_won' }]).chips.conditions From 404a3c2f9ce5ececce563e2af4a0d1351a32c954 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 22:20:39 +0000 Subject: [PATCH 4/5] chore: changeset for date condition chips Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QSeKYnagJvGbCtNg2PhvgW --- .changeset/37034-date-condition-chips.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .changeset/37034-date-condition-chips.md diff --git a/.changeset/37034-date-condition-chips.md b/.changeset/37034-date-condition-chips.md new file mode 100644 index 00000000000..ce295142791 --- /dev/null +++ b/.changeset/37034-date-condition-chips.md @@ -0,0 +1,18 @@ +--- +'@object-ui/plugin-list': patch +--- + +fix(plugin-list): a date condition's value reads as a date in the viewer's language + +Clause-②: no +Metadata-protocol: none + +A list condition chip on a date field printed the stored value as written, so a +drilled dashboard bucket read 「创建时间:≥ 2026-10-01T00:00:00.000Z」 in a zh-CN +session. Every condition row (the reader's chips and the view's locked chips) now +formats a date-family value by the field's type through the console's one date +display path (`formatDate` / `formatDateTime` from `@object-ui/core`), in the +display locale: a `date` field shows the day with its year (an instant at UTC +midnight shows that calendar day in every zone), a `datetime` field shows the +date and time in the display zone, and a `time` field or an unreadable value is +shown as written. The filter the list sends is unchanged. From a5828298601d290c96190d0bb6108a6464cc39cb Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 23:32:16 +0000 Subject: [PATCH 5/5] fix(plugin-list): the phone filter row reads dates in the viewer's locale; pin the datetime sighting Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QSeKYnagJvGbCtNg2PhvgW --- scripts/i18n-coverage-baseline.json | 2 +- .../src/conditions/ListConditionControls.tsx | 15 +-- .../__tests__/listConditions.test.tsx | 109 ++++++++++++------ .../src/conditions/conditionDates.ts | 28 +++-- .../plugin-list/src/phone/PhoneListPanels.tsx | 5 +- 5 files changed, 101 insertions(+), 58 deletions(-) diff --git a/scripts/i18n-coverage-baseline.json b/scripts/i18n-coverage-baseline.json index 758b553f2e7..dd6dfbfd4f5 100644 --- a/scripts/i18n-coverage-baseline.json +++ b/scripts/i18n-coverage-baseline.json @@ -1,7 +1,7 @@ { "examples/app-crm/objectstack.config.ts": 0, "examples/app-multi-package/objectstack.config.ts": 0, - "examples/app-showcase/objectstack.config.ts": 449, + "examples/app-showcase/objectstack.config.ts": 441, "examples/app-todo/objectstack.config.ts": 136, "packages/platform-objects/scripts/i18n-extract.config.ts": 0, "packages/plugins/plugin-approvals/scripts/i18n-extract.config.ts": 0, diff --git a/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx b/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx index fdd48a9d426..50a65181763 100644 --- a/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx +++ b/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx @@ -93,8 +93,9 @@ export function describeConditionValue( operator: string, value: unknown, t: Translate, - nameOf?: LookupValueName, - locale?: string, + nameOf: LookupValueName | undefined, + // Required, so no caller formats a date in the runtime's default locale by omission. + locale: string, ): string { const opLabel = quickOperatorLabel(operator, t); if (isValuelessOperator(operator)) return opLabel; @@ -129,8 +130,8 @@ function chipText( operator: string, value: unknown, t: Translate, - nameOf?: LookupValueName, - locale?: string, + nameOf: LookupValueName | undefined, + locale: string, ) { return t('listConditions.chips.pattern', { field: field?.label ?? fieldName ?? '', @@ -142,9 +143,9 @@ function viewChipText( chip: ViewConditionChip, fields: ReadonlyArray, t: Translate, - nameOf?: LookupValueName, - relatedFieldOf?: RelatedFieldOf, - locale?: string, + nameOf: LookupValueName | undefined, + relatedFieldOf: RelatedFieldOf | undefined, + locale: string, ): string { if (chip.anyOf) { return chip.anyOf.map((member) => viewChipText(member, fields, t, nameOf, relatedFieldOf, locale)).join(t('listConditions.chips.or')); diff --git a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx index a37a14db15f..f673f22b65b 100644 --- a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx +++ b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx @@ -14,7 +14,7 @@ * which the host owns: one click is spent before any of these panels mounts. */ -import { describe, it, expect, vi } from 'vitest'; +import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest'; import * as React from 'react'; import { act, fireEvent, render, screen, within } from '@testing-library/react'; import type { FilterBuilderRowGroup, SortItem } from '@object-ui/components'; @@ -40,6 +40,8 @@ import { builtInLocales, en as enPack, zh as zhPack } from '@object-ui/i18n/loca import { I18nProvider } from '@object-ui/i18n'; import { parseFilterAST } from '@objectstack/spec/data'; import { convertFilterGroupToAST } from '../../ListView'; +import { PhoneFilterSheet } from '../../phone/PhoneListPanels'; +import { setDisplayTimeZone } from '@object-ui/core'; // The server's JSON-column refusal set, read from the module every server face // imports it from (`@objectstack/core`, which no UI package depends on): the @@ -550,7 +552,7 @@ describe('multi-value fields — the quick filter and the advanced panel offer o const enQuick = enPack.listConditions.operators as Record; expect(MULTI_OFFER.map((op) => enQuick[op])).toEqual(['contains', 'does not contain', 'is empty', 'is not empty']); const t = (key: string) => LIST_CONDITION_DEFAULT_TRANSLATIONS[key] ?? key; - expect(describeConditionValue(MULTI_VALUE[0], 'contains', 'quality_lead', t as never)).toBe('contains Quality lead'); + expect(describeConditionValue(MULTI_VALUE[0], 'contains', 'quality_lead', t as never, undefined, 'en-US')).toBe('contains Quality lead'); }); }); @@ -763,10 +765,10 @@ describe('condition model', () => { it('describes a chip value by operator: a bare list for 「is any of」, the operator named otherwise', () => { const t = (key: string, o?: Record) => (LIST_CONDITION_DEFAULT_TRANSLATIONS[key] ?? key).replace(/\{\{(\w+)\}\}/g, (_, k) => String(o?.[k] ?? '')); - expect(describeConditionValue(STAGE, 'in', ['proposal', 'negotiation'], t as never)).toBe('Proposal, Negotiation'); - expect(describeConditionValue(FIELDS[2], 'greater_than_or_equal', 100, t as never)).toBe('≥ 100'); - expect(describeConditionValue(FIELDS[3], 'between', quickDateWindowValue('today'), t as never)).toBe('Today'); - expect(describeConditionValue(STAGE, 'is_empty', undefined, t as never)).toBe('is empty'); + expect(describeConditionValue(STAGE, 'in', ['proposal', 'negotiation'], t as never, undefined, 'en-US')).toBe('Proposal, Negotiation'); + expect(describeConditionValue(FIELDS[2], 'greater_than_or_equal', 100, t as never, undefined, 'en-US')).toBe('≥ 100'); + expect(describeConditionValue(FIELDS[3], 'between', quickDateWindowValue('today'), t as never, undefined, 'en-US')).toBe('Today'); + expect(describeConditionValue(STAGE, 'is_empty', undefined, t as never, undefined, 'en-US')).toBe('is empty'); }); }); @@ -1106,10 +1108,16 @@ describe('ConditionChipRow — an operator only the advanced panel writes (objec }); // objectstack#37034 — a date condition's value reads as a date in the viewer's -// language, by the field's type, on every condition row: a drilled month -// bucket's two bounds (the rows `drillListConditions` writes from the dataset -// answer's `{ $gte, $lt }`, ISO instants at UTC midnight) included. +// language, by the field's type, on every condition row (the desktop chips and +// the phone filter sheet's rows). On the wire a `date` bound is `YYYY-MM-DD` +// and a `datetime` bound an ISO instant: the card's sighting was a drilled +// month bucket on `created_at`, 「创建时间:≥ 2026-10-01T00:00:00.000Z」. +// The display zone is pinned to UTC, so an instant's day and time do not +// depend on the zone the runner sits in. describe('date condition values read as dates (objectstack#37034)', () => { + beforeAll(() => setDisplayTimeZone('UTC')); + afterAll(() => setDisplayTimeZone(undefined)); + const ISSUED_ON: ConditionField = { value: 'issued_on', label: '开具日期', type: 'date' }; const CREATED_AT: ConditionField = { value: 'created_at', label: '创建时间', type: 'datetime' }; const STARTS_AT: ConditionField = { value: 'starts_at', label: 'Starts at', type: 'time' }; @@ -1118,45 +1126,56 @@ describe('date condition values read as dates (objectstack#37034)', () => { logic: 'and', conditions: conditions.map(([field, operator, value], i) => ({ id: `r${i}`, field, operator, value }) as FilterBuilderRow), }); + const inZh = (node: React.ReactNode) => ( + {node} + ); function zhChips(filters: FilterBuilderRowGroup, field: string): string[] { - render( - - {}} - filters={filters} - filterFields={[ISSUED_ON, CREATED_AT]} - onFiltersChange={() => {}} - renderAdvanced={() =>
} - renderSortLevels={() =>
} - /> - , - ); + render(inZh( + {}} + filters={filters} + filterFields={[ISSUED_ON, CREATED_AT]} + onFiltersChange={() => {}} + renderAdvanced={() =>
} + renderSortLevels={() =>
} + />, + )); return screen.getAllByTestId(`filter-chip-open-${field}`).map((b) => b.textContent ?? ''); } + const NOT_ISO = /T\d\d:\d\d|\d{4}-\d{2}-\d{2}/; + + it('the sighting: a drilled month bucket on a datetime field reads as two localized date-times, not ISO', () => { + const chips = zhChips(rows([ + ['created_at', 'greater_than_or_equal', '2026-10-01T00:00:00.000Z'], + ['created_at', 'before', '2026-11-01T00:00:00.000Z'], + ]), 'created_at'); + expect(chips).toHaveLength(2); + expect(chips[0]).toMatch(/^创建时间:≥ 2026年10月1日.*00:00$/); + expect(chips[1]).toMatch(/^创建时间:.*2026年11月1日.*00:00$/); + for (const chip of chips) expect(chip).not.toMatch(NOT_ISO); + }); - it('a drilled month bucket on a date field shows its range as two date rows, not ISO', () => { + it('a date field bound, as the wire writes it (YYYY-MM-DD), reads as its day', () => { const chips = zhChips(rows([ - ['issued_on', 'greater_than_or_equal', '2026-10-01T00:00:00.000Z'], - ['issued_on', 'before', '2026-11-01T00:00:00.000Z'], + ['issued_on', 'greater_than_or_equal', '2026-10-01'], + ['issued_on', 'before', '2026-11-01'], ]), 'issued_on'); expect(chips).toHaveLength(2); - // A day bound at UTC midnight names that day in every zone. - expect(chips[0]).toContain('2026年10月1日'); + expect(chips[0]).toBe('开具日期:≥ 2026年10月1日'); expect(chips[1]).toContain('2026年11月1日'); - for (const chip of chips) { - expect(chip).toContain('开具日期'); - expect(chip).not.toMatch(/T\d\d:\d\d/); - } + for (const chip of chips) expect(chip).not.toMatch(NOT_ISO); + }); + + it('a date field compared with an instant at UTC midnight reads as that day', () => { + const [chip] = zhChips(rows([['issued_on', 'greater_than_or_equal', '2026-10-01T00:00:00.000Z']]), 'issued_on'); + expect(chip).toBe('开具日期:≥ 2026年10月1日'); }); - it('a datetime field reads as a localized date and time, not ISO', () => { - // Noon UTC: the same calendar day in every zone a test runner sits in. + it('a datetime reads in the display zone', () => { const [chip] = zhChips(rows([['created_at', 'greater_than_or_equal', '2026-10-15T12:00:00.000Z']]), 'created_at'); - expect(chip).toContain('创建时间'); - expect(chip).toContain('2026年10月15日'); - expect(chip).not.toContain('2026-10-15T12:00:00.000Z'); + expect(chip).toMatch(/^创建时间:≥ 2026年10月15日.*12:00$/); }); it('a date between reads both ends as dates', () => { @@ -1164,6 +1183,22 @@ describe('date condition values read as dates (objectstack#37034)', () => { expect(chip).toContain('2026年10月1日 – 2026年10月31日'); }); + it("the phone filter sheet's row reads the date in the viewer's language, not the runtime default", () => { + // The runtime's own locale here is English: a row that left the locale out + // would read 「Oct 1, 2026」 on a zh-CN session. + expect(new Intl.DateTimeFormat().resolvedOptions().locale).toMatch(/^en/); + render(inZh( + {}} + fields={[ISSUED_ON, CREATED_AT]} + value={rows([['issued_on', 'greater_than_or_equal', '2026-10-01']])} + onApply={() => {}} + />, + )); + expect(screen.getByTestId('phone-filter-item-condition').textContent).toBe('≥ 2026年10月1日'); + }); + it('CONTROL: a time field and an unreadable value are shown as written', () => { const { t } = { t: (k: string) => LIST_CONDITION_DEFAULT_TRANSLATIONS[k] ?? k }; expect(describeConditionValue(STARTS_AT, 'after', '09:30', t as never, undefined, 'zh-CN')).toBe('after 09:30'); diff --git a/ui/packages/plugin-list/src/conditions/conditionDates.ts b/ui/packages/plugin-list/src/conditions/conditionDates.ts index 280428d3b12..841fee19338 100644 --- a/ui/packages/plugin-list/src/conditions/conditionDates.ts +++ b/ui/packages/plugin-list/src/conditions/conditionDates.ts @@ -9,22 +9,26 @@ /** * How a date condition's value reads on a condition row (objectstack#37034). * - * A row holds the value the query compares: a calendar day (`2026-10-01`) or - * an instant (`2026-10-01T00:00:00.000Z`, the bound a dataset bucket's drill - * writes). The row printed it as written, so a zh-CN chip read - * 「≥ 2026-10-01T00:00:00.000Z」. It reads as a date now, in the viewer's - * display locale, through the console's ONE date display path - * (`formatDate` / `formatDateTime` in `@object-ui/core`'s `date-display`): - * ⛔ no second formatter is written here. + * A row holds the value the query compares, written on the wire the way the + * field's type stores it: a `date` field's bound is a calendar day + * (`2026-10-01`), and a `datetime` field's bound is an ISO instant + * (`2026-10-01T00:00:00.000Z`; a dataset bucket's drill writes its month's + * bounds that way on a `created_at`). The row printed the value as written, so + * a zh-CN chip read 「创建时间:≥ 2026-10-01T00:00:00.000Z」. It reads as a + * date now, in the viewer's display locale, through the console's ONE date + * display path (`formatDate` / `formatDateTime` in `@object-ui/core`'s + * `date-display`): ⛔ no second formatter is written here. * * The field's type decides the face: * * - `date` names a calendar day, so the day is shown, with its year (a - * condition's bounds are read side by side). An instant at UTC midnight on - * a date field is how a day bound is written on the wire; it names that day - * in every zone, so its leading `YYYY-MM-DD` is what is shown — read as an - * instant it would name the previous day west of UTC. - * - `datetime` is an instant: the date and the time in the display zone. + * condition's bounds are read side by side). A `YYYY-MM-DD` value is that + * day in every zone. A date field compared with an instant at UTC midnight + * (an authored filter may write one) names the same day, so its leading + * `YYYY-MM-DD` is what is shown: read as an instant it would name the + * previous day west of UTC. + * - `datetime` is an instant: the date and the time in the display zone + * (`setDisplayTimeZone`, else the viewer's own). * - `time` and anything else are shown as written. * * A value the display path cannot read (it answers `—`) is shown as written, diff --git a/ui/packages/plugin-list/src/phone/PhoneListPanels.tsx b/ui/packages/plugin-list/src/phone/PhoneListPanels.tsx index 21f2cbfa7df..0b70cd730ed 100644 --- a/ui/packages/plugin-list/src/phone/PhoneListPanels.tsx +++ b/ui/packages/plugin-list/src/phone/PhoneListPanels.tsx @@ -48,6 +48,7 @@ import { type SortItem, } from '@object-ui/components'; import type { DataSource } from '@object-ui/types'; +import { useDisplayLocale } from '@object-ui/i18n'; import { ArrowUpDown, Check, ChevronLeft, GripVertical, Info, ListFilter, MoreHorizontal, Plus, X } from 'lucide-react'; import { FieldList } from '../conditions/FieldList'; import { isQuickRowApplied } from '../conditions/FilterValuePanel'; @@ -574,6 +575,8 @@ export function PhoneFilterSheet({ open, onOpenChange, fields, shownFields, valu const [staged, setStaged, step, setStep] = useStaged(open, value, { kind: 'list' }); const applied = (staged.conditions ?? []).filter(isQuickRowApplied); const nameOf = useLookupValueNames(dataSource, fields, applied); + // A date condition reads in the viewer's display locale, as the desktop chips do. + const locale = useDisplayLocale(); const independent = chipsAreIndependent(staged); const toList = () => setStep({ kind: 'list' }); @@ -626,7 +629,7 @@ export function PhoneFilterSheet({ open, onOpenChange, fields, shownFields, valu