Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { AnchoredMenu } from "../ui/AnchoredMenu";
import { MENU_SURFACE_CLASS } from "../ui/paneMenuTokens";
import { Z_LAYERS } from "../ui/zLayers";
import { cn } from "../ui/cn";
import { wallClockAsUtc } from "../../../shared/formatting";

const DUE_DATE_FORMAT = new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric", year: "numeric" });
const DUE_DATE_FORMAT = new Intl.DateTimeFormat(undefined, { timeZone: "UTC", month: "short", day: "numeric", year: "numeric" });

function isoDate(date: Date): string {
const year = date.getFullYear();
Expand Down Expand Up @@ -66,7 +67,7 @@ export function IssueDueDatePicker({
className="inline-flex h-7 max-w-full items-center gap-1.5 rounded-md border border-fg/[0.08] bg-fg/[0.02] px-2 text-[11.5px] text-fg/85 transition-colors hover:border-fg/[0.16] hover:bg-fg/[0.05] disabled:cursor-default disabled:opacity-70"
>
<CalendarBlank size={12} className="shrink-0 text-[color:var(--kit-text-3)]" />
<span className="truncate">{selected ? DUE_DATE_FORMAT.format(selected) : "None"}</span>
<span className="truncate">{selected ? DUE_DATE_FORMAT.format(wallClockAsUtc(selected)) : "None"}</span>
</button>
<AnchoredMenu
open={open}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { LaneShareGivenEntry } from "../../../shared/types/laneShare";
import { LANE_SHARING_UNAVAILABLE, LANE_SHARING_UNAVAILABLE_MESSAGE } from "../../../shared/laneShareDirectory";
import type { OpenProjectBinding } from "../../../shared/types";
import { rootAppStoreApi } from "../../state/appStore";
import { wallClockAsUtc } from "../../../shared/formatting";

/**
* Pure helpers for the owner's lane sharing UI: states, quick end dates,
Expand Down Expand Up @@ -128,10 +129,10 @@ export function laneShareQuickEnds(now: number): LaneShareQuickEnd[] {
];
}

const dateTime = new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" });
const dateTime = new Intl.DateTimeFormat(undefined, { timeZone: "UTC", month: "short", day: "numeric", hour: "numeric", minute: "2-digit" });

export function formatLaneShareEnd(endsAt: number | null): string {
return endsAt == null ? "No end date" : `Ends ${dateTime.format(new Date(endsAt))}`;
return endsAt == null ? "No end date" : `Ends ${dateTime.format(wallClockAsUtc(new Date(endsAt)))}`;
}

/** "12 of 50 today", "12 of 200", "12 messages", or null when nothing was counted here. */
Expand Down
15 changes: 15 additions & 0 deletions apps/desktop/src/shared/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,18 @@ export function formatGb(mb: number): string {
const value = mb / 1024;
return value >= 10 ? String(Math.round(value)) : value.toFixed(1).replace(/\.0$/u, "");
}

/**
* A Date whose UTC fields read the current zone's wall clock. A formatter
* pinned to `timeZone: "UTC"` then prints local time while still following a
* system time-zone change; one built without a zone would keep the zone it was
* constructed in for as long as it is cached. Built from the local calendar
* fields rather than an offset, so a historical sub-minute zone offset is not
* truncated by `getTimezoneOffset()`.
*/
export function wallClockAsUtc(date: Date): Date {
const wallClock = new Date(0);
wallClock.setUTCFullYear(date.getFullYear(), date.getMonth(), date.getDate());
wallClock.setUTCHours(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
return wallClock;
}
Comment on lines +80 to +85

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Incorrect historical timestamps in chat

For historical instants with sub-minute zone offsets, wallClockAsUtc drops the offset seconds. Chat timestamps near a minute boundary then display the wrong minute even when the system zone never changes.

Learn more

timeEntity accepts valid zoned ISO timestamps from assistant prose without a lower date bound. ThreadEntityNode displays those instants with formatThreadEntityTimestamp. The previous formatter applied the zone's historical offset directly. The new helper uses getTimezoneOffset(), which returns whole minutes and drops offset seconds before the UTC formatter chooses what minute to print.

Example: With the system zone set to Europe/Paris, an assistant reply containing 1900-01-01T12:00:45Z previously displayed Jan 1, 12:10 PM in en-US. Paris used UTC+00:09:21 at that instant. The new helper shifts by nine minutes, so the same reply displays Jan 1, 12:09 PM.

Recommended fix: Copy the local calendar and clock fields into a UTC date instead of shifting by getTimezoneOffset(). Use setUTCFullYear to avoid JavaScript's special handling of years 0–99 in Date.UTC.

Suggested change
export function wallClockAsUtc(date: Date): Date {
return new Date(date.getTime() - date.getTimezoneOffset() * 60_000);
}
export function wallClockAsUtc(date: Date): Date {
const wallClock = new Date(0);
wallClock.setUTCFullYear(date.getFullYear(), date.getMonth(), date.getDate());
wallClock.setUTCHours(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
return wallClock;
}

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

17 changes: 10 additions & 7 deletions apps/desktop/src/shared/threadEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { buildDeeplink, type DeeplinkTarget } from "./deeplinks";
import { normalizeJiraIssueKey, jiraIssueRef } from "./issueRefs";
import { getModelById, resolveModelDescriptor } from "./modelRegistry";
import { modelPermissionLabel } from "./modelPermissions";
import { wallClockAsUtc } from "./formatting";

export type ThreadEntityLane = { id: string; name: string };
export type ThreadEntitySession = { id: string };
Expand Down Expand Up @@ -400,10 +401,12 @@ export function linearTeamKeyFromIdentifier(identifier: string | null | undefine
return match ? match[1]!.toUpperCase() : null;
}

const TIME_SAME_DAY = new Intl.DateTimeFormat(undefined, { hour: "numeric", minute: "2-digit", second: "2-digit" });
const TIME_OTHER_DAY = new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" });
const TIME_RANGE = new Intl.DateTimeFormat(undefined, { hour: "numeric", minute: "2-digit" });
const TIME_DAY = new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric" });
// Pinned to UTC and fed wall-clock-shifted Dates (see wallClockAsUtc): a
// formatter built without a zone would keep the load-time zone after a change.
const TIME_SAME_DAY = new Intl.DateTimeFormat(undefined, { timeZone: "UTC", hour: "numeric", minute: "2-digit", second: "2-digit" });
const TIME_OTHER_DAY = new Intl.DateTimeFormat(undefined, { timeZone: "UTC", month: "short", day: "numeric", hour: "numeric", minute: "2-digit" });
const TIME_RANGE = new Intl.DateTimeFormat(undefined, { timeZone: "UTC", hour: "numeric", minute: "2-digit" });
const TIME_DAY = new Intl.DateTimeFormat(undefined, { timeZone: "UTC", month: "short", day: "numeric" });

/**
* A zoned timestamp (or same-day range) in the reader's local time, the one
Expand All @@ -418,10 +421,10 @@ export function formatThreadEntityTimestamp(
const date = new Date(epochMs);
const sameDay = new Date(now).toDateString() === date.toDateString();
if (endEpochMs != null) {
const range = TIME_RANGE.formatRange(date, new Date(endEpochMs));
return sameDay ? range : `${TIME_DAY.format(date)}, ${range}`;
const range = TIME_RANGE.formatRange(wallClockAsUtc(date), wallClockAsUtc(new Date(endEpochMs)));
return sameDay ? range : `${TIME_DAY.format(wallClockAsUtc(date))}, ${range}`;
}
return (sameDay ? TIME_SAME_DAY : TIME_OTHER_DAY).format(date);
return (sameDay ? TIME_SAME_DAY : TIME_OTHER_DAY).format(wallClockAsUtc(date));
}

/** Stable identity for "these two chips point at the same thing". */
Expand Down
Loading