Move an event by the days the hand moved it, not to the date dropped on

Dragging an event across the month grid wrote the date of the cell it
landed on into the event's stored start. Those are the same date only
while the event's time zone is the reader's.

An event kept in Asia/Tokyo at 15:00 is drawn to a reader in Phoenix at
23:00 the previous evening. Dropped on the 11th, it was written as the
11th in Tokyo -- which is the 10th on screen. It went where its own
calendar said rather than where the pointer did, one day short, every
time.

Moving by the difference between the two local days instead moves it
exactly as far as the hand did, and adding whole days to a stored wall
clock leaves the time of day alone without touching the zone -- so the
frame the rest of this path is careful about is still not crossed.

Found by giving the mock an event in a zone that is not the machine's.
Every other fixture used the machine's own, which cannot tell a correct
conversion from no conversion at all: the case that works is the one the
fixtures were all testing.
This commit is contained in:
2026-09-02 01:07:07 -07:00
parent 13a6bcd66b
commit 7b3069e41b
5 changed files with 69 additions and 11 deletions
+24 -4
View File
@@ -121,14 +121,34 @@ export function movePatch(storedStart: string, deltaMinutes: number): DragPatch
return { start: formatStored(addMinutes(base, snap(deltaMinutes))) };
}
/** Moved to another date, keeping the time of day it already had. */
export function moveToDayPatch(storedStart: string, day: Date): DragPatch {
/**
* Moved by a whole number of days, keeping the time of day it already had.
*
* A day *delta*, not a target date, and the difference matters whenever the
* event's zone is not the reader's. The month grid's cells are local days; the
* event's stored date is in its own zone. Rewriting the stored date to the day
* that was dropped on put a Tokyo event dropped on the 11th onto the 10th,
* because 15:00 in Tokyo on the 11th is 23:00 in Phoenix on the 10th — the
* event went where its own calendar said, not where the pointer did.
*
* Shifting by the difference between the two local days moves it exactly as
* far as the hand did, and adding whole days to a wall clock leaves the time
* of day alone without touching the zone.
*/
export function moveByDaysPatch(storedStart: string, days: number): DragPatch {
const base = parseStored(storedStart);
if (!base) return {};
const moved = new Date(day.getFullYear(), day.getMonth(), day.getDate(), base.getHours(), base.getMinutes(), base.getSeconds(), 0);
if (!base || !Number.isFinite(days)) return {};
const moved = new Date(base.getFullYear(), base.getMonth(), base.getDate() + Math.round(days), base.getHours(), base.getMinutes(), base.getSeconds(), 0);
return { start: formatStored(moved) };
}
/** Whole days between two local dates, ignoring the time of day on each. */
export function dayDelta(from: Date, to: Date): number {
const a = new Date(from.getFullYear(), from.getMonth(), from.getDate()).getTime();
const b = new Date(to.getFullYear(), to.getMonth(), to.getDate()).getTime();
return Math.round((b - a) / 86400_000);
}
/**
* Resized from its end. Only the duration moves, so the start -- and with it
* the whole question of zones -- is not touched at all.