Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

improvement(web): show a schedule in UTC or in your own time (#820)

Croff904812cdea4c
diff --git a/apps/web/messages/ar/settings.json b/apps/web/messages/ar/settings.json
index cda1cad2..785e10c5 100644
--- a/apps/web/messages/ar/settings.json
+++ b/apps/web/messages/ar/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "كل يوم عمل في 9:00 صباحًا",
"presetEveryDayAt9": "كل يوم في 9:00 صباحًا",
"inputPlaceholder": "Every weekday at 9:00 AM أو 0 9 * * 1-5",
- "runs": "التشغيل: {description} UTC",
+ "runs": "التشغيل: {description}",
+ "clockLabel": "المنطقة الزمنية",
+ "clockUtc": "UTC",
+ "clockLocal": "وقتي",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "نشطة",
diff --git a/apps/web/messages/en/settings.json b/apps/web/messages/en/settings.json
index a32741bc..2b7f3302 100644
--- a/apps/web/messages/en/settings.json
+++ b/apps/web/messages/en/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "Every weekday at 9:00 AM",
"presetEveryDayAt9": "Every day at 9:00 AM",
"inputPlaceholder": "Every weekday at 9:00 AM or 0 9 * * 1-5",
- "runs": "Runs: {description} UTC",
+ "runs": "Runs: {description}",
+ "clockLabel": "Time zone",
+ "clockUtc": "UTC",
+ "clockLocal": "My time",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "Active",
diff --git a/apps/web/messages/es-ES/settings.json b/apps/web/messages/es-ES/settings.json
index d2356026..2fc58d07 100644
--- a/apps/web/messages/es-ES/settings.json
+++ b/apps/web/messages/es-ES/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "Cada día laborable a las 9:00",
"presetEveryDayAt9": "Cada día a las 9:00",
"inputPlaceholder": "Cada día laborable a las 9:00 o 0 9 * * 1-5",
- "runs": "Ejecuciones: {description} UTC",
+ "runs": "Ejecuciones: {description}",
+ "clockLabel": "Zona horaria",
+ "clockUtc": "UTC",
+ "clockLocal": "Mi hora",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "Activa",
diff --git a/apps/web/messages/fa/settings.json b/apps/web/messages/fa/settings.json
index bac83b0b..950400c3 100644
--- a/apps/web/messages/fa/settings.json
+++ b/apps/web/messages/fa/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "هر روز کاری ساعت 9:00 AM",
"presetEveryDayAt9": "هر روز ساعت 9:00 AM",
"inputPlaceholder": "هر روز کاری ساعت 9:00 AM یا 0 9 * * 1-5",
- "runs": "اجراها: {description} UTC",
+ "runs": "اجراها: {description}",
+ "clockLabel": "منطقه زمانی",
+ "clockUtc": "UTC",
+ "clockLocal": "وقت من",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "فعال",
diff --git a/apps/web/messages/fr/settings.json b/apps/web/messages/fr/settings.json
index 096a7711..9ffa1f0b 100644
--- a/apps/web/messages/fr/settings.json
+++ b/apps/web/messages/fr/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "Chaque jour ouvré à 9h00",
"presetEveryDayAt9": "Chaque jour à 9h00",
"inputPlaceholder": "Chaque jour ouvré à 9h00 ou 0 9 * * 1-5",
- "runs": "S'exécute : {description} UTC",
+ "runs": "S'exécute : {description}",
+ "clockLabel": "Fuseau horaire",
+ "clockUtc": "UTC",
+ "clockLocal": "Mon heure",
"cronLabel": "Cron :",
"runsSuffix": "{description} UTC",
"statusActive": "Active",
diff --git a/apps/web/messages/id/settings.json b/apps/web/messages/id/settings.json
index ad93b49b..82ec3007 100644
--- a/apps/web/messages/id/settings.json
+++ b/apps/web/messages/id/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "Setiap hari kerja pukul 09.00",
"presetEveryDayAt9": "Setiap hari pukul 09.00",
"inputPlaceholder": "Setiap hari kerja pukul 09.00 atau 0 9 * * 1-5",
- "runs": "Eksekusi: {description} UTC",
+ "runs": "Eksekusi: {description}",
+ "clockLabel": "Zona waktu",
+ "clockUtc": "UTC",
+ "clockLocal": "Waktu saya",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "Aktif",
diff --git a/apps/web/messages/ko/settings.json b/apps/web/messages/ko/settings.json
index b4f2f502..91668ce7 100644
--- a/apps/web/messages/ko/settings.json
+++ b/apps/web/messages/ko/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "평일 오전 9시마다",
"presetEveryDayAt9": "매일 오전 9시",
"inputPlaceholder": "평일 오전 9시 또는 0 9 * * 1-5",
- "runs": "실행: {description} UTC",
+ "runs": "실행: {description}",
+ "clockLabel": "시간대",
+ "clockUtc": "UTC",
+ "clockLocal": "내 시간",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "활성",
diff --git a/apps/web/messages/pt-BR/settings.json b/apps/web/messages/pt-BR/settings.json
index abcd5873..d1854843 100644
--- a/apps/web/messages/pt-BR/settings.json
+++ b/apps/web/messages/pt-BR/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "Todo dia útil às 9h",
"presetEveryDayAt9": "Todo dia às 9h",
"inputPlaceholder": "Todo dia útil às 9h ou 0 9 * * 1-5",
- "runs": "Executa: {description} UTC",
+ "runs": "Executa: {description}",
+ "clockLabel": "Fuso horário",
+ "clockUtc": "UTC",
+ "clockLocal": "Meu horário",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "Ativo",
diff --git a/apps/web/messages/ru/settings.json b/apps/web/messages/ru/settings.json
index 787eecd4..47c44f59 100644
--- a/apps/web/messages/ru/settings.json
+++ b/apps/web/messages/ru/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "По будням в 9:00",
"presetEveryDayAt9": "Каждый день в 9:00",
"inputPlaceholder": "Every weekday at 9:00 AM или 0 9 * * 1-5",
- "runs": "Запуск: {description} UTC",
+ "runs": "Запуск: {description}",
+ "clockLabel": "Часовой пояс",
+ "clockUtc": "UTC",
+ "clockLocal": "Моё время",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "Активное",
diff --git a/apps/web/messages/tr/settings.json b/apps/web/messages/tr/settings.json
index 9186e839..b85820bb 100644
--- a/apps/web/messages/tr/settings.json
+++ b/apps/web/messages/tr/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "Hafta içi her gün saat 09:00'da",
"presetEveryDayAt9": "Her gün saat 09:00'da",
"inputPlaceholder": "Hafta içi her gün saat 09:00'da veya 0 9 * * 1-5",
- "runs": "Çalışma: {description} UTC",
+ "runs": "Çalışma: {description}",
+ "clockLabel": "Saat dilimi",
+ "clockUtc": "UTC",
+ "clockLocal": "Benim saatim",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "Aktif",
diff --git a/apps/web/messages/uk/settings.json b/apps/web/messages/uk/settings.json
index 4fd245dd..30456a8b 100644
--- a/apps/web/messages/uk/settings.json
+++ b/apps/web/messages/uk/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "У будні о 9:00",
"presetEveryDayAt9": "Щодня о 9:00",
"inputPlaceholder": "Every weekday at 9:00 AM або 0 9 * * 1-5",
- "runs": "Запуск: {description} UTC",
+ "runs": "Запуск: {description}",
+ "clockLabel": "Часовий пояс",
+ "clockUtc": "UTC",
+ "clockLocal": "Мій час",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "Активний",
diff --git a/apps/web/messages/zh-CN/settings.json b/apps/web/messages/zh-CN/settings.json
index 63d9fdfb..d9e9a6af 100644
--- a/apps/web/messages/zh-CN/settings.json
+++ b/apps/web/messages/zh-CN/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "每个工作日 9:00",
"presetEveryDayAt9": "每天 9:00",
"inputPlaceholder": "每个工作日早上 9:00 或 0 9 * * 1-5",
- "runs": "运行时间:{description} UTC",
+ "runs": "运行时间:{description}",
+ "clockLabel": "时区",
+ "clockUtc": "UTC",
+ "clockLocal": "我的时间",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "已启用",
diff --git a/apps/web/messages/zh-TW/settings.json b/apps/web/messages/zh-TW/settings.json
index d6a50b42..4a5b725d 100644
--- a/apps/web/messages/zh-TW/settings.json
+++ b/apps/web/messages/zh-TW/settings.json
@@ -43,7 +43,10 @@
"presetEveryWeekdayAt9": "每個工作日 9:00",
"presetEveryDayAt9": "每天 9:00",
"inputPlaceholder": "每個工作日早上 9:00 或 0 9 * * 1-5",
- "runs": "執行時間:{description} UTC",
+ "runs": "執行時間:{description}",
+ "clockLabel": "時區",
+ "clockUtc": "UTC",
+ "clockLocal": "我的時間",
"cronLabel": "Cron:",
"runsSuffix": "{description} UTC",
"statusActive": "已啟用",
diff --git a/apps/web/src/features/settings/components/schedules/SettingsScheduleInput.test.tsx b/apps/web/src/features/settings/components/schedules/SettingsScheduleInput.test.tsx
new file mode 100644
index 00000000..5ef7a34a
--- /dev/null
+++ b/apps/web/src/features/settings/components/schedules/SettingsScheduleInput.test.tsx
@@ -0,0 +1,188 @@
+import assert from 'node:assert/strict';
+import { afterEach, beforeEach, describe, it } from 'node:test';
+import { act, useState } from 'react';
+import type { Root } from 'react-dom/client';
+import { NextIntlClientProvider } from 'next-intl';
+import { JSDOM } from 'jsdom';
+import { setDisplayTimezone } from '@/utils/dates';
+import settings from '../../../../../messages/en/settings.json';
+
+// Dubai keeps one offset all year, UTC+4, so these do not depend on the date they run.
+const ZONE = 'Asia/Dubai';
+
+const replacedGlobals = [
+ 'window',
+ 'document',
+ 'navigator',
+ 'Node',
+ 'Element',
+ 'HTMLElement',
+ 'HTMLInputElement',
+ 'SVGElement',
+ 'Event',
+ 'CustomEvent',
+ 'MutationObserver',
+ 'ResizeObserver',
+ 'getComputedStyle',
+ 'requestAnimationFrame',
+ 'cancelAnimationFrame',
+ 'localStorage',
+ 'fetch',
+ 'IS_REACT_ACT_ENVIRONMENT',
+] as const;
+
+let dom: JSDOM;
+let root: Root;
+let originals: Map<string, PropertyDescriptor | undefined>;
+let saved: string;
+
+async function render(initial: string) {
+ const { SettingsScheduleInput } = await import('./SettingsScheduleInput');
+ function Form() {
+ const [value, setValue] = useState(initial);
+ saved = value;
+ return <SettingsScheduleInput id="schedule" value={value} onChange={setValue} />;
+ }
+ await act(async () =>
+ root.render(
+ <NextIntlClientProvider locale="en" messages={{ settings }} timeZone="UTC">
+ <Form />
+ </NextIntlClientProvider>,
+ ),
+ );
+}
+
+const input = () => document.querySelector<HTMLInputElement>('#schedule')!;
+
+function clock(label: string) {
+ const button = [...document.querySelectorAll('button')].find((b) => b.textContent === label);
+ assert.ok(button);
+ return button;
+}
+
+async function pick(label: string) {
+ await act(async () => {
+ clock(label).dispatchEvent(new dom.window.MouseEvent('mousedown', { bubbles: true }));
+ });
+}
+
+async function type(text: string) {
+ const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!;
+ await act(async () => {
+ setValue.call(input(), text);
+ input().dispatchEvent(new Event('input', { bubbles: true }));
+ });
+}
+
+beforeEach(async () => {
+ originals = new Map(
+ replacedGlobals.map((name) => [name, Object.getOwnPropertyDescriptor(globalThis, name)]),
+ );
+ dom = new JSDOM('<!doctype html><div id="root"></div>', {
+ url: 'https://example.test/',
+ pretendToBeVisual: true,
+ });
+ for (const name of replacedGlobals) {
+ if (name in dom.window) {
+ Object.defineProperty(globalThis, name, {
+ configurable: true,
+ value: dom.window[name as keyof typeof dom.window],
+ });
+ }
+ }
+ Object.defineProperties(globalThis, {
+ getComputedStyle: { configurable: true, value: dom.window.getComputedStyle.bind(dom.window) },
+ ResizeObserver: {
+ configurable: true,
+ value: class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+ },
+ fetch: { configurable: true, value: () => new Promise(() => {}) },
+ IS_REACT_ACT_ENVIRONMENT: { configurable: true, value: true },
+ });
+ Object.defineProperty(window, '__ITSAPLAN_ENV__', {
+ value: { apiUrl: 'https://example.test', privacyUrl: '', termsUrl: '' },
+ });
+ setDisplayTimezone(ZONE);
+ const { createRoot } = await import('react-dom/client');
+ root = createRoot(document.querySelector('#root')!);
+});
+
+afterEach(async () => {
+ await act(async () => root.unmount());
+ setDisplayTimezone('');
+ dom.window.close();
+ for (const [name, descriptor] of originals) {
+ if (descriptor) Object.defineProperty(globalThis, name, descriptor);
+ else Reflect.deleteProperty(globalThis, name);
+ }
+});
+
+const line = () => document.querySelector('[aria-live]')?.textContent;
+
+describe('SettingsScheduleInput', () => {
+ it('starts on UTC', async () => {
+ await render('0 7 * * *');
+
+ assert.equal(clock('UTC').getAttribute('aria-selected'), 'true');
+ assert.equal(line(), 'Runs: At 7:00 AM UTC');
+ });
+
+ it('describes a cron on the user clock under the input, which stays as it is', async () => {
+ await render('0 7 * * *');
+ await pick('My time');
+
+ assert.equal(line(), 'Runs: At 11:00 AM');
+ assert.equal(input().value, '0 7 * * *');
+ assert.equal(saved, '0 7 * * *');
+ });
+
+ it('describes a written schedule on the user clock too', async () => {
+ await render('Every day at 9:00 AM');
+ await pick('My time');
+
+ assert.equal(line(), 'Cron: 0 9 * * * · At 1:00 PM');
+ assert.equal(input().value, 'Every day at 9:00 AM');
+ assert.equal(saved, 'Every day at 9:00 AM');
+ });
+
+ it('takes what is typed as UTC on either clock', async () => {
+ await render('0 7 * * *');
+ await pick('My time');
+ await type('0 9 * * *');
+
+ assert.equal(saved, '0 9 * * *');
+ assert.equal(line(), 'Runs: At 1:00 PM');
+ });
+
+ it('does not call UTC days the user clock', async () => {
+ await render('*/15 * * * 1-5');
+ await pick('My time');
+
+ assert.equal(line(), 'Runs: Every 15 minutes on weekdays UTC');
+ });
+
+ it('stays in UTC for a schedule that cannot be moved to the user clock', async () => {
+ await render('0 23 1 * *');
+ await pick('My time');
+
+ assert.ok(line()?.endsWith(' UTC'));
+ assert.ok(line()?.startsWith('Runs: '));
+ });
+
+ it('remembers the last clock on every input', async () => {
+ await render('0 7 * * *');
+ await pick('My time');
+ await act(async () => root.unmount());
+
+ const { createRoot } = await import('react-dom/client');
+ root = createRoot(document.querySelector('#root')!);
+ await render('0 9 * * *');
+
+ assert.equal(clock('My time').getAttribute('aria-selected'), 'true');
+ assert.equal(line(), 'Runs: At 1:00 PM');
+ });
+});
diff --git a/apps/web/src/features/settings/components/schedules/SettingsScheduleInput.tsx b/apps/web/src/features/settings/components/schedules/SettingsScheduleInput.tsx
index d424e304..9533fefb 100644
--- a/apps/web/src/features/settings/components/schedules/SettingsScheduleInput.tsx
+++ b/apps/web/src/features/settings/components/schedules/SettingsScheduleInput.tsx
@@ -1,7 +1,10 @@
import { useId } from 'react';
import { SettingsSuggestionsInput, type InputSuggestion } from './SettingsSuggestionsInput';
+import { useScheduleClock } from '../../hooks/useScheduleClock';
import { parseScheduleInput } from '../../utils/cronSchedule';
+import { describeCronInDisplayZone } from '../../utils/cronZone';
import { useTranslations } from 'next-intl';
+import DisplaySegmented from '@/components/layout/DisplaySegmented';
// `value` is what the preset writes into the input, and `parseScheduleInput` reads
// English phrases — so only the label is translated.
@@ -16,6 +19,8 @@ const SCHEDULE_PRESETS = [
{ value: 'Every day at 9:00 AM', labelKey: 'presetEveryDayAt9', description: '0 9 * * *' },
] as const;
+// The input takes UTC, the zone a cron runs in. The clock picked under it changes only the line
+// that describes the schedule: UTC, or the zone of the user's profile.
export function SettingsScheduleInput({
id,
value,
@@ -26,7 +31,10 @@ export function SettingsScheduleInput({
onChange: (value: string) => void;
}) {
const t = useTranslations('settings.schedules');
+ const { clock, pick } = useScheduleClock();
const result = parseScheduleInput(value);
+ // A schedule that cannot be shown on the user's clock stays in UTC, with the zone written out.
+ const localTime = clock === 'local' && result.ok ? describeCronInDisplayZone(result.cron) : null;
const messageId = useId();
const scheduleSuggestions: InputSuggestion[] = SCHEDULE_PRESETS.map((preset) => ({
value: preset.value,
@@ -48,28 +56,39 @@ export function SettingsScheduleInput({
aria-invalid={!result.ok}
aria-describedby={messageId}
/>
- <span
- id={messageId}
- className={
- result.ok ? 'block text-xs text-muted-foreground' : 'block text-xs text-destructive'
- }
- aria-live="polite"
- >
- {result.ok ? successMessage(result, t) : result.error}
- </span>
+ <div className="mt-1 flex items-center justify-between gap-2">
+ <span
+ id={messageId}
+ className={result.ok ? 'text-xs text-muted-foreground' : 'text-xs text-destructive'}
+ aria-live="polite"
+ >
+ {result.ok ? successMessage(result, localTime, t) : result.error}
+ </span>
+ <div role="group" aria-label={t('clockLabel')} className="shrink-0">
+ <DisplaySegmented
+ value={clock}
+ onChange={pick}
+ options={[
+ { value: 'utc', label: t('clockUtc') },
+ { value: 'local', label: t('clockLocal') },
+ ]}
+ />
+ </div>
+ </div>
</>
);
}
function successMessage(
result: Extract<ReturnType<typeof parseScheduleInput>, { ok: true }>,
+ localTime: string | null,
t: ReturnType<typeof useTranslations<'settings.schedules'>>,
): React.ReactNode {
- if (result.source === 'cron') return t('runs', { description: result.description });
+ const when = localTime ?? t('runsSuffix', { description: result.description });
+ if (result.source === 'cron') return t('runs', { description: when });
return (
<>
- {t('cronLabel')} <code className="font-mono">{result.cron}</code> ·{' '}
- {t('runsSuffix', { description: result.description })}
+ {t('cronLabel')} <code className="font-mono">{result.cron}</code> · {when}
</>
);
}
diff --git a/apps/web/src/features/settings/hooks/useScheduleClock.ts b/apps/web/src/features/settings/hooks/useScheduleClock.ts
new file mode 100644
index 00000000..a14fd1e7
--- /dev/null
+++ b/apps/web/src/features/settings/hooks/useScheduleClock.ts
@@ -0,0 +1,31 @@
+import { useCallback, useEffect, useState } from 'react';
+
+type ScheduleClock = 'utc' | 'local';
+
+const STORAGE_KEY = 'schedule-clock';
+
+// The clock schedules are written on: the one last picked in this browser, on any schedule input.
+// The stored value is read in an effect, not in the state initializer: the initializer also runs
+// during the server render, where there is no localStorage.
+export function useScheduleClock() {
+ const [clock, setClock] = useState<ScheduleClock>('utc');
+
+ useEffect(() => {
+ try {
+ if (localStorage.getItem(STORAGE_KEY) === 'local') setClock('local');
+ } catch {
+ // Storage unavailable (private mode): the input stays on UTC.
+ }
+ }, []);
+
+ const pick = useCallback((next: ScheduleClock) => {
+ setClock(next);
+ try {
+ localStorage.setItem(STORAGE_KEY, next);
+ } catch {
+ // Ignore write failures (private mode / quota); the state still updates.
+ }
+ }, []);
+
+ return { clock, pick };
+}
diff --git a/apps/web/src/features/settings/utils/cronSchedule.ts b/apps/web/src/features/settings/utils/cronSchedule.ts
index 65d09e32..9ffbcecd 100644
--- a/apps/web/src/features/settings/utils/cronSchedule.ts
+++ b/apps/web/src/features/settings/utils/cronSchedule.ts
@@ -34,8 +34,8 @@ function looksLikeCron(value: string): boolean {
return parts.length === 5 && /^[\d*/,-]+$/.test(parts[0]);
}
-// A schedule's times are stored and shown in UTC, which is the only zone a cron here
-// runs in, so the zone is written out with them.
+// A schedule's times are stored in UTC, the only zone a cron here runs in. A list of schedules
+// shows them in UTC too, with the zone written out.
export function formatUtc(value: string): string {
return `${new Intl.DateTimeFormat(getIntlLocale(), {
dateStyle: 'medium',
diff --git a/apps/web/src/features/settings/utils/cronZone.test.ts b/apps/web/src/features/settings/utils/cronZone.test.ts
new file mode 100644
index 00000000..138762e9
--- /dev/null
+++ b/apps/web/src/features/settings/utils/cronZone.test.ts
@@ -0,0 +1,86 @@
+import assert from 'node:assert/strict';
+import { afterEach, describe, it } from 'node:test';
+import { setDisplayTimezone } from '@/utils/dates';
+import { cronInDisplayZone, describeCronInDisplayZone } from './cronZone';
+
+const winter = new Date('2026-11-05T12:00:30Z');
+const summer = new Date('2026-07-05T12:00:30Z');
+
+function inZone(zone: string, cron: string, at = winter) {
+ setDisplayTimezone(zone);
+ return cronInDisplayZone(cron, at);
+}
+
+afterEach(() => setDisplayTimezone(''));
+
+describe('cronInDisplayZone', () => {
+ it('moves a time of day by the offset the zone has then', () => {
+ assert.equal(inZone('Europe/Kyiv', '0 7 * * *'), '0 9 * * *');
+ assert.equal(inZone('Europe/Kyiv', '0 7 * * *', summer), '0 10 * * *');
+ assert.equal(inZone('UTC', '0 7 * * *'), '0 7 * * *');
+ });
+
+ it('moves the minutes of a zone off the hour', () => {
+ assert.equal(inZone('Asia/Kolkata', '30 9 * * *'), '0 15 * * *');
+ });
+
+ it('moves the weekdays when the time crosses midnight', () => {
+ assert.equal(inZone('Europe/Kyiv', '0 23 * * 1-5'), '0 1 * * 2,3,4,5,6');
+ assert.equal(inZone('America/New_York', '0 1 * * 0'), '0 20 * * 6');
+ assert.equal(inZone('Europe/Kyiv', '0 7 * * 1-5'), '0 9 * * 1-5');
+ });
+
+ it('keeps hours in order, and a range as a range', () => {
+ assert.equal(inZone('Europe/Kyiv', '0 6,23 * * *'), '0 1,8 * * *');
+ assert.equal(inZone('Europe/Kyiv', '*/15 7-15 * * 1-5'), '*/15 9-17 * * 1-5');
+ });
+
+ it('keeps a day of the month while the time stays on that day', () => {
+ assert.equal(inZone('Europe/Kyiv', '0 7 1 * *'), '0 9 1 * *');
+ });
+
+ it('leaves a schedule with no hours of its own and no days', () => {
+ assert.equal(inZone('Europe/Kyiv', '*/15 * * * *'), '*/15 * * * *');
+ assert.equal(inZone('Europe/Kyiv', '0 */2 * * *'), '0 */2 * * *');
+ assert.equal(inZone('Asia/Kolkata', '*/15 * * * *'), '*/15 * * * *');
+ });
+
+ it('is null when the time leaves the day one cron names', () => {
+ assert.equal(inZone('Europe/Kyiv', '0 23 1 * *'), null);
+ assert.equal(inZone('Europe/Kyiv', '0 6,23 * * 1'), null);
+ assert.equal(inZone('Europe/Kyiv', '0 23 * * */2'), null);
+ });
+
+ it('is null for a schedule with no hours of its own that names a day', () => {
+ assert.equal(inZone('Europe/Kyiv', '*/15 * * * 1-5'), null);
+ assert.equal(inZone('Europe/Kyiv', '0 */6 1 * *'), null);
+ });
+
+ it('is null for a minute a zone off the hour moves', () => {
+ assert.equal(inZone('Asia/Kolkata', '*/15 9-17 * * *'), null);
+ assert.equal(inZone('Asia/Kolkata', '5 * * * *'), null);
+ assert.equal(inZone('Asia/Kolkata', '30 */6 * * *'), null);
+ });
+
+ it("is null for a schedule in a month, whose offset may not be today's", () => {
+ assert.equal(inZone('Europe/Kyiv', '0 7 1 7 *'), null);
+ assert.equal(inZone('America/New_York', '0 7 * 7 *'), null);
+ });
+
+ it('is null for what does not parse', () => {
+ assert.equal(inZone('Europe/Kyiv', 'not a cron'), null);
+ });
+});
+
+describe('describeCronInDisplayZone', () => {
+ it('describes the cron in the display zone', () => {
+ setDisplayTimezone('Asia/Dubai');
+ assert.equal(describeCronInDisplayZone('0 7 * * *'), 'At 11:00 AM');
+ assert.equal(describeCronInDisplayZone('*/15 * * * *'), 'Every 15 minutes');
+ });
+
+ it('is null when the cron cannot be moved', () => {
+ setDisplayTimezone('Asia/Dubai');
+ assert.equal(describeCronInDisplayZone('0 23 1 * *'), null);
+ });
+});
diff --git a/apps/web/src/features/settings/utils/cronZone.ts b/apps/web/src/features/settings/utils/cronZone.ts
new file mode 100644
index 00000000..73cac7b8
--- /dev/null
+++ b/apps/web/src/features/settings/utils/cronZone.ts
@@ -0,0 +1,82 @@
+import { zoneOffsetMs } from '@/utils/dates';
+import { describeCron } from './cronDescription';
+import { formatCron, parseCron } from './cronFields';
+
+const MINUTES_A_DAY = 24 * 60;
+const DAYS_A_WEEK = 7;
+
+function modulo(value: number, size: number): number {
+ return ((value % size) + size) % size;
+}
+
+function ascending(values: number[]): number[] {
+ return [...new Set(values)].sort((a, b) => a - b);
+}
+
+// The values a field of numbers, ranges and steps stands for. Null for a field with a star.
+function valuesOf(field: string, max: number): number[] | null {
+ if (field.includes('*')) return null;
+ return field.split(',').flatMap((segment) => {
+ const [base, step] = segment.split('/');
+ const [from, to = step ? max : from] = base.split('-').map(Number);
+ const values: number[] = [];
+ for (let value = from; value <= to; value += Number(step ?? 1)) values.push(value);
+ return values;
+ });
+}
+
+function hourField(hours: number[], wasRange: boolean): string {
+ const unbroken = hours.every((hour, index) => index === 0 || hour === hours[index - 1] + 1);
+ return wasRange && unbroken && hours.length > 1
+ ? `${hours[0]}-${hours[hours.length - 1]}`
+ : hours.join(',');
+}
+
+// A UTC cron as it falls in the display zone, at the offset the zone has at `at`, so it follows
+// the zone's clock changes. Null when one cron cannot show that, or today's offset may not hold:
+// - the schedule names a month, whose offset may differ from today's;
+// - the time moves to another day of the month, or its times fall on different days;
+// - the zone is off the hour and the cron has no one minute;
+// - the cron has no hours of its own and names a day, or a minute in a zone off the hour.
+export function cronInDisplayZone(cron: string, at = new Date()): string | null {
+ const parsed = parseCron(cron);
+ if (!parsed.ok) return null;
+ const { minute, hour, dayOfMonth, month, dayOfWeek } = parsed.value;
+ if (month !== '*') return null;
+
+ const offset = Math.round(zoneOffsetMs(at) / 60_000);
+ const onTheHour = offset % 60 === 0;
+ const everyDay = dayOfMonth === '*' && dayOfWeek === '*';
+ const hours = valuesOf(hour, 23);
+ if (!hours) {
+ return everyDay && (onTheHour || minute.includes('*')) ? formatCron(parsed.value) : null;
+ }
+ const oneMinute = /^\d+$/.test(minute);
+ if (!oneMinute && !onTheHour) return null;
+
+ const times = hours.map((value) => value * 60 + (oneMinute ? Number(minute) : 0) + offset);
+ const inDay = times.map((time) => modulo(time, MINUTES_A_DAY));
+ const fields = {
+ ...parsed.value,
+ minute: oneMinute ? String(inDay[0] % 60) : minute,
+ hour: hourField(ascending(inDay.map((time) => Math.floor(time / 60))), hour.includes('-')),
+ };
+ if (everyDay) return formatCron(fields);
+
+ const days = new Set(times.map((time) => Math.floor(time / MINUTES_A_DAY)));
+ if (days.size > 1) return null;
+ const [daysMoved] = days;
+ if (daysMoved === 0) return formatCron(fields);
+ if (dayOfMonth !== '*') return null;
+ const weekdays = valuesOf(dayOfWeek, DAYS_A_WEEK - 1);
+ if (!weekdays) return null;
+ const moved = weekdays.map((day) => modulo(day + daysMoved, DAYS_A_WEEK));
+ return formatCron({ ...fields, dayOfWeek: ascending(moved).join(',') });
+}
+
+// A UTC cron's description in the display zone, or null when `cronInDisplayZone` is.
+export function describeCronInDisplayZone(cron: string): string | null {
+ const zoned = cronInDisplayZone(cron);
+ const description = zoned ? describeCron(zoned) : null;
+ return description?.ok ? description.value : null;
+}
diff --git a/apps/web/src/utils/dates.ts b/apps/web/src/utils/dates.ts
index 6e4ec2f6..05b0f61f 100644
--- a/apps/web/src/utils/dates.ts
+++ b/apps/web/src/utils/dates.ts
@@ -117,7 +117,7 @@ export function formatDateTime(value: string): string {
}
// The display zone's offset at a given moment, in ms (zone time minus UTC).
-function zoneOffsetMs(date: Date): number {
+export function zoneOffsetMs(date: Date): number {
const parts = new Intl.DateTimeFormat('en-US', {
hourCycle: 'h23',
year: 'numeric',