Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 6650259

Browse files
fix(plugin-calendar): a day event moved across a DST change writes the days it was dropped on; timeZone prose and zone pins (objectui#10866, slice 4) (#10994)
Part of #10866 Clause-②: no Slice 4 of objectui#10866: the items slice 1 left owed (claim `5870315836`, release `5870108114`). The binding reading is the release's: a calendar day reads and moves on the UTC calendar; a `datetime` keeps its instant and is displayed in the viewer's zone. No instant behaviour moves here. ## What changes 1. **The calendar's DST-day move: measured, and it moved stored days, so it is repaired.** The month grid moves each date of an event by the milliseconds between two local midnights, the grabbed cell's and the drop cell's, and a date-only value is read at local midnight of its day. When a DST change lies between one of the event's dates and where it lands, but not between the two cells (or the other way round), that date comes back an hour off local midnight; at 23:00 of the day before, the write took the day before. Measured under `America/Los_Angeles` through `ObjectCalendar`: four of ten day moves across November 1st and March 8th wrote a day one short (an October 29th to 31st span moved two days wrote its end `2026-11-01`; a November 1st to 3rd span grabbed on the 2nd and moved one day wrote its start `2026-11-01`; an October 31st to November 2nd span grabbed on the 2nd and moved back one day wrote its start `2026-10-29`; a March 5th to 9th span moved back one day wrote its end `2026-03-07`). `Asia/Shanghai` and UTC wrote every day right. - `ObjectCalendar` now writes a `date` field of a **day event** (its start, and its end when it has one, are both stored calendar days) as its stored day moved by the whole days the grid moved it, on the UTC calendar (`toMovedDateValue`). Every other write takes the path it took before. 2. **The `timeZone` prose**, made true of the code at three sites plus one comment of the same sentence: - `@object-ui/types` `GanttConfig.timeZone`: a `datetime` value stays a real instant; a `date` value is a calendar day, drawn from that day's midnight in the chart's zone and written back as the day it was dropped on, `YYYY-MM-DD`; near a DST change of the chart's zone or the viewer's, that midnight can be placed an hour early, onto the day before (measured, see Acceptance notes). - plugin-gantt `GanttViewProps.timeZone`: dates handed to `onTaskUpdate` are translated back into real instants; for a date-only value the host translates both ways itself, as `ObjectGantt` does. - `makeTzShift`'s JSDoc: what `from` gives back, how `ObjectGantt` hands a day in and writes it back, and that `to` and `from` are exact inverses except near a DST change of either zone. The old sentence "fixed-offset zones (Asia/Shanghai) are exact" was false for a viewer whose own zone keeps DST (measured on a verbatim copy of the function: for an `America/Los_Angeles` viewer of an `Asia/Shanghai` chart, 31 of 2026's hourly instants do not round-trip, all around March 8th and November 1st), so it is replaced rather than kept. - The comment above `GanttView`'s `onTaskUpdate` wrapper said "writes must persist real time"; it now says the host decides what to persist. Same sentence class, same file, comment only. 3. **Zone pins**, registered in the driver's `PINS`: - `ObjectCalendar.dstDayMove-10866`: the ten day moves in Los Angeles and Shanghai, three `datetime` controls in Los Angeles and one in Shanghai, a rig case per zone, and a fixture-validity case (November 1st is 25 hours long in Los Angeles, March 8th 23). - `ObjectCalendar.endDateNoSchemaZone-10866`: the `endDateField` write (move, end-handle drag, quick-create), and the calendar with no object schema (read, move, end drag, quick-create), with `datetime` controls, in the suite zone, Los Angeles and Shanghai. - `ObjectGantt.noSchemaZone-10866`: the gantt with no object schema, for an adapter with no `getObjectSchema` and for one whose schema has no fields (the `api` provider's shape): read, drag write, a zoned chart, and an instant control, in the suite zone, Los Angeles and Shanghai. 4. **One `FormulaFunctions` docblock sentence**: a mixed `DATEDIFF`, one day and one instant, reads each argument by its own kind when it counts months or years, the day on the UTC calendar and the instant in the zone the formula runs in. Comment only. 5. **The day-scale gantt misalignment rides nowhere here.** Measured not small: the header row is equal-width columns (one per bucket, the end inclusive) while every bar is a percentage of the continuous minimum-to-maximum span. Read in `generateTimeScaleHeaders` and `calculateBarDimensions` (not driven), the hour, week and month scales are built the same way, so the choice (an inclusive end, or an axis stretched to the last bucket's end) is a design decision across every scale, and it moves the bar percentages slice 3's gantt pin asserts. Reported below. ## Why the repair sits in `ObjectCalendar`, not in the grid The grid cannot tell a day from an instant at local midnight, and the calendar's own month-view quick-create writes exactly such an instant into a `datetime` field. Every grid-side repair that makes a day exact also moves those instants, which this slice may not do. `ObjectCalendar` knows the field's declared type (or, with no schema, the stored value's shape), and a day event can only be dragged in the month grid: the week and day views draw it in their all-day row, which has no drag handlers. So the day event's `date` fields are written from their stored day, and the grid's arithmetic is untouched. The instant-side defect this leaves standing is in the Acceptance notes. ## Instants are byte-equal to the base A probe drove 19 moves through `ObjectCalendar` in UTC, Los Angeles and Shanghai, against the base source and against this head. The only rows that differ are the four Los Angeles day moves above. The nine instant and mixed rows (`datetime` spans, a local-midnight `datetime` span, a one-day `datetime` event, a `date` start with a `datetime` end, `date` fields holding instants, `datetime` fields holding days) are equal in UTC and Los Angeles; in Shanghai five of them were measured equal, and four were not measured there (their grab cell names a day the instant does not fall on in that zone, and they errored the same way on base and head). The pin's `datetime` controls hold the same instants on both. ## Evidence - **New pins, red on base then green.** The three pins in a forks child with `OBJECTUI_DATE_ZONE_CHILD=1`, `ObjectCalendar.tsx` checked out from the base: `Tests 4 failed | 84 passed (88)`, the four red rows exactly the four day moves named above (`"end": "2026-11-01"` for `"2026-11-02"`, `"start": "2026-11-01"` for `"2026-11-02"`, `"start": "2026-10-29"` for `"2026-10-30"`, `"end": "2026-03-07"` for `"2026-03-08"`). Restored by `git checkout HEAD --`, blob equal to HEAD, `git diff HEAD` empty. Head: `Tests 88 passed (88)`. - **The coverage pins can fail.** The end-date, no-schema calendar and no-schema gantt paths were already right on the base, so those rows pass there by design. Four ablations on the committed head through `ablation-replace.mjs`, each anchor hit once, each blob changed and restored to HEAD: - the calendar's stored-shape arm answering `false`: `6 failed | 30 passed (36)`, the no-schema move and end-drag rows in all three zones; - the calendar's end write as `toISOString()`: `33 failed | 31 passed (64)` over the end-date and DST pins; - the gantt's stored-shape arm answering `false`: `9 failed | 15 passed (24)`, the drag writes and the zoned drop in all three zones; - the gantt read through the engine parse: `6 failed | 18 passed (24)`, the Los Angeles and Shanghai reads and zoned cases. - **Suites at head `4dddfff0b`**, each under the shared verify lock: `packages/plugin-calendar/` `Test Files 54 passed (54)`, `Tests 363 passed | 70 skipped (433)`; `packages/plugin-gantt/` `Test Files 86 passed (86)`, `Tests 630 passed | 43 skipped (673)`; the zone-pin driver `Tests 23 passed (23)`; `packages/types/` `Test Files 270 passed (270)`, `Tests 5977 passed (5977)`; `packages/core/` `Test Files 184 passed (184)`, `Tests 3658 passed | 27 skipped (3685)`; the 38 test files outside those packages that name a touched file or a touched plugin's source directory `Test Files 34 passed | 4 skipped (38)` (the four skipped are other slices' zone pins, which run in the driver's child); the 48 `scripts/__tests__` files that mention `.changeset` or enumerate files (`ls-files`, a glob, a directory walk) `Test Files 48 passed (48)`, `Tests 1899 passed (1899)`. - **Type-check**: the two plugins' dependency closure built, then `type-check` for plugin-calendar, plugin-gantt, types and core, each echoing `type-check$ tsc --noEmit ... && tsc -p tsconfig.test.json` and `Done`; `tsc -p tsconfig.test.json --listFiles` includes all three new pins. - **Gates**: `check-changeset-presence` (`8 source file(s) of 4 released package(s) changed, and this change declares 1 changeset(s)`), `-no-major`, `-fixed`, `-overwrite`, `-claims` (report-only; no pending changeset repeats the "real instants" sentence), `check-pending-changeset-literals`, `check-control-bytes`, `check-new-cross-file-line-citations` (`0 new citation(s)`), `check-test-path-roots`, the three `check-vi-mock-*`, `check-unreferenced-sources`: all exit 0. A control-byte scan of the changed files finds none. `check-governed-queue-guard --test` over the ten paths: NOT GOVERNED. - **Lint, narrowed and stated as a narrowing**: the root config with `--no-inline-config --format json` over the nine changed code files (nine results): 0 errors; each modified file's warnings equal its base blob's (`ObjectCalendar.tsx` 31, `GanttView.tsx` 12, `objectql.ts` 34, `FormulaFunctions.ts` 26); the new files and `tzShift.ts` 0. The config sets no `parserOptions.project` or `projectService`, so linting is not type-aware and this diff cannot move an untouched file's verdict. Repo-wide lint is CI's. - **Bundle**: no import added; plugin-calendar and plugin-gantt load through `registerLazy`, outside the console's eager closure. `Bundle Analysis` is read from CI. - **Serial**: this seat's open PR objectui#10962 edits two comment blocks in `ObjectCalendar.tsx` and one in `types/src/objectql.ts`; every hunk here stays at least 16 lines clear of them, and `git merge-tree` of this head with that PR's head is clean. ## Acceptance notes Recorded here, not filed by the dev; the seat decides. - **The zoned gantt's day can move on a DST day (new measurement, this card's family).** With a business `timeZone`, a viewer whose own zone keeps DST, and a chart zone with a different DST, `makeTzShift`'s round trip puts a day's midnight at 23:00 of the day before on a DST day: an `America/Los_Angeles` viewer of an `America/New_York` chart sees a stored `2026-03-08` drawn from 23:00 on March 7th, and a drop onto March 8th writes `2026-03-07`; the same with an `Europe/Berlin` chart on March 29th. A Shanghai viewer of a New York chart is exact on those days. Measured through `ObjectGantt` with the `GanttView` probe. The repair is not the family's shared step (it is the shim's inverse, for days only), so it is not made here; no named producer sets a gantt `timeZone`. - **A `datetime` event at local midnight moved across a DST change in the month grid lands in the cell before the drop (instant path, unchanged here).** Measured in Los Angeles: a `datetime` span starting `2026-11-01T07:00:00.000Z` (local midnight), grabbed on November 2nd and dropped on November 3rd, writes its start `2026-11-02T07:00:00.000Z`, which is 23:00 on November 1st. The calendar's own month-view quick-create writes such local-midnight instants into a `datetime` field. Repairing it moves instants, so it needs its own ruling. - **Day-scale gantt misalignment (pre-existing, zone-independent).** The timeline's gantt variant draws one equal-width header column per bucket, end inclusive, and places bars as percentages of the minimum-to-maximum span, so on the day scale the bars sit on a scale one column narrower than the headers, and the other scales disagree with their buckets too. Dedupe words: `timeline gantt header column bar percentage`, `generateTimeScaleHeaders calculateBarDimensions`, `day scale misaligned`. - **Cross-repo half, not edited here.** objectstack `packages/spec/src/ui/view.zod.ts`, `GanttConfig` `timeZone` describe, which `@object-ui/types`' zod mirror reuses, still says "persisted data stays real instants". - **A pending changeset sentence this slice's measurement contradicts.** Slice 1's `.changeset/10866-calendar-gantt-date-only-days.md` says a zoned chart's drop "writes the day of the chart's calendar that the bar was dropped on"; the first note above measures a case where it writes the day before. Not edited here: it is another slice's release declaration, and `check-changeset-overwrite` reports a change that modifies one. It publishes at the next release. Commits carry the model-free trailer pair only. --- _Generated by [Claude Code](https://claude.ai/code/session_01DuWo5bdP9SdVebamn99GGk)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1f5a644 commit 6650259

10 files changed

Lines changed: 942 additions & 17 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/plugin-calendar': patch
3+
'@object-ui/plugin-gantt': patch
4+
'@object-ui/types': patch
5+
'@object-ui/core': patch
6+
---
7+
8+
fix(plugin-calendar): a day event moved across a DST change writes the days it was dropped on (objectui#10866, slice 4)
9+
10+
- **plugin-calendar.** The month grid moves each date of an event by the milliseconds between two local midnights, the grabbed cell's and the drop cell's, and a date-only value is read at local midnight of its day. So when a DST change lay between one of an event's dates and where it landed, but not between the two cells (or the other way round), that date came back an hour off local midnight; at 23:00 of the day before, the write took the day before. Under `America/Los_Angeles` a span of `date` fields moved across November 1st or March 8th could be written a day short at its start or its end. A move of an event whose start, and end when it has one, are both stored calendar days now writes each `date` field as its stored day moved by the whole days the grid moved it. Every other write is unchanged: a `datetime` field still writes the instant the grid hands back, and the grid's own arithmetic does not change.
11+
- **plugin-gantt, types.** The business `timeZone` prose (`GanttConfig.timeZone`, `GanttViewProps.timeZone` and `makeTzShift`) said persisted data stays real instants. A `date` field under a zoned chart has been written as a calendar day since this card's first slice; the prose now says so, and says that near a DST change of the chart's zone or the viewer's the shim can place a day's midnight an hour early, onto the day before. Documentation only.
12+
- **core.** The `DATEADD` / `DATEDIFF` / `DATEFORMAT` docblock names how a mixed `DATEDIFF`, one day and one instant, reads each argument when it counts months or years. Comment only.

‎packages/core/src/evaluator/FormulaFunctions.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ export class FormulaFunctions {
278278
* February 29th plus a year is February 28th.
279279
* - `DATEFORMAT` prints a day as itself, and `DATEDIFF` counts months and
280280
* years between two days' own months and years.
281+
* - A mixed `DATEDIFF`, one day and one instant, reads each argument by its
282+
* own kind when it counts months or years: the day on the UTC calendar,
283+
* the instant in the zone the formula runs in (in a browser, the viewer's).
281284
* - Anything else, a value with a time part included, is unchanged: it is
282285
* moved and read with local setters and getters, in the zone the formula
283286
* runs in, and `DATEADD` hands it back as an instant (`toISOString()`).

‎packages/plugin-calendar/src/ObjectCalendar.tsx‎

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,55 @@ function getCalendarConfig(schema: ObjectCalendarSchema): ObjectCalendarConfig |
336336
* event. A quick-create has no stored value, so it keeps the instant there.
337337
*/
338338
function toStoredDateValue(date: Date, declaredType: unknown, stored: unknown): string {
339-
const dateOnly =
340-
typeof declaredType === 'string'
341-
? declaredType === 'date'
342-
: typeof stored === 'string' && isRealCalendarDate(stored);
343-
return dateOnly ? toDateInputValue(date) : date.toISOString();
339+
return isDateOnlyField(declaredType, stored) ? toDateInputValue(date) : date.toISOString();
340+
}
341+
342+
/** Does this date field hold a calendar day? {@link toStoredDateValue}'s split. */
343+
function isDateOnlyField(declaredType: unknown, stored: unknown): boolean {
344+
return typeof declaredType === 'string'
345+
? declaredType === 'date'
346+
: typeof stored === 'string' && isRealCalendarDate(stored);
347+
}
348+
349+
/** A stored calendar day: a `YYYY-MM-DD` string naming a day its month has. */
350+
function isStoredDay(value: unknown): value is string {
351+
return typeof value === 'string' && isRealCalendarDate(value);
352+
}
353+
354+
const DAY_MS = 86_400_000;
355+
356+
/**
357+
* The value a MOVED event writes into one of its date fields (objectui#10866,
358+
* slice 4): {@link toStoredDateValue}'s answer, except for a `date` field of a
359+
* DAY EVENT, one whose start and end (when it has one) are both stored calendar
360+
* days.
361+
*
362+
* Only the month grid drags a day event: the week and day views draw it in
363+
* their all-day row, which does not drag. The month grid moves each date by the
364+
* milliseconds between two local midnights, the grabbed cell's and the drop
365+
* cell's, and a day event's dates were handed to it at local midnight of their
366+
* days (`toDisplayDate`). When a DST change lies between a date and where it
367+
* lands but not between the two cells, or the other way round, the moved date
368+
* comes back an hour off local midnight: 23:00 of the day before when the
369+
* clocks fell back in between. Measured under `America/Los_Angeles`: a
370+
* two-day span grabbed on its start and moved two days, across November 1st,
371+
* wrote its end one day short, and the local day of that `Date` is what
372+
* {@link toStoredDateValue} writes.
373+
*
374+
* So a day event's `date` field is written as its stored day moved by the
375+
* whole days the grid moved it, on the UTC calendar, the way this card's
376+
* binding reading moves a calendar day. The grid's own arithmetic is
377+
* unchanged, because the grid cannot tell a day from an instant at local
378+
* midnight: every other field, instants included, writes exactly what it did.
379+
*/
380+
function toMovedDateValue(moved: Date, declaredType: unknown, stored: unknown, dayEvent: boolean): string {
381+
if (!dayEvent || !isStoredDay(stored) || !isDateOnlyField(declaredType, stored)) {
382+
return toStoredDateValue(moved, declaredType, stored);
383+
}
384+
const days = Math.round((moved.getTime() - toDisplayDate(stored).getTime()) / DAY_MS);
385+
const day = new Date(`${stored}T00:00:00.000Z`);
386+
day.setUTCDate(day.getUTCDate() + days);
387+
return day.toISOString().slice(0, 10);
344388
}
345389

346390
/**
@@ -1060,13 +1104,18 @@ export const ObjectCalendar: React.FC<ObjectCalendarComponentProps> = ({
10601104
if (!id || !schema.objectName || !dataSource?.update) return;
10611105

10621106
// A `date` field is written as the calendar day, a `datetime` as the
1063-
// instant (objectui#10866, `toStoredDateValue`).
1107+
// instant (objectui#10866, `toStoredDateValue`); a day event's `date`
1108+
// field moves by whole days (`toMovedDateValue`). `dayEvent` asks the same
1109+
// values the read handed the view: the start, and the end only when set.
10641110
const fieldDefs = objectSchema?.fields as Record<string, { type?: unknown } | undefined> | undefined;
1111+
const storedStart: unknown = record?.[startDateField];
1112+
const storedEnd: unknown = endDateField ? record?.[endDateField] : undefined;
1113+
const dayEvent = isStoredDay(storedStart) && (!storedEnd || isStoredDay(storedEnd));
10651114
const patch: Record<string, string> = {
1066-
[startDateField]: toStoredDateValue(newStart, fieldDefs?.[startDateField]?.type, record?.[startDateField]),
1115+
[startDateField]: toMovedDateValue(newStart, fieldDefs?.[startDateField]?.type, storedStart, dayEvent),
10671116
};
10681117
if (endDateField && newEnd) {
1069-
patch[endDateField] = toStoredDateValue(newEnd, fieldDefs?.[endDateField]?.type, record?.[endDateField]);
1118+
patch[endDateField] = toMovedDateValue(newEnd, fieldDefs?.[endDateField]?.type, storedEnd, dayEvent);
10701119
}
10711120

10721121
// Optimistic UI update

0 commit comments

Comments
 (0)