Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(sheets): pick dates from a calendar in date cells (#8131)
teo94e6c523e93d
diff --git a/apps/web/src/features/block-spreadsheet/README.md b/apps/web/src/features/block-spreadsheet/README.mdindex 3216a304eb..fa3798a2a5 100644--- a/apps/web/src/features/block-spreadsheet/README.md+++ b/apps/web/src/features/block-spreadsheet/README.md@@ -377,6 +377,15 @@ compare formula, error, and formatting behavior before replacing it.numbers in the `date` format (formula results only from the year 2000 on, so daycounts stay numbers). A cell holding one `<m-date-mention>` pill calculates asthat local calendar date.+ Results shown as a calendar date (not a time) carry `date: true`. Editing such a+ literal cell, or any cell under a date validation rule, without typing+ (double-click, double-tap, Enter or F2) opens `components/CellDatePicker.tsx`+ below the editor in the shared `EditorPopup`, so the editor keeps focus. The+ grid sends it arrows (a day or a week), Page Up/Down (a month, Shift a year),+ Enter (pick and move down) and Escape (close); typing closes it. A picked day+ goes through the normal commit and validation, written the way the cell stores+ dates (`core/cell-date.ts`): a serial keeps its time of day, a date pill stays a+ pill, ISO text stays ISO, and other text becomes month/day/year.Plain text treats formula-looking input literally. Wrapped rows grow to 160px at100% zoom; larger content remains available in the formula bar/editor.- Internal copying preserves formatting and translates relative/mixed references@@ -443,6 +452,7 @@ Import keeps what Excel calculates and shows:rejects the entry, warnings and information accept it, and each shows therule's message in the footer. List rules offer their values in a dropdown on theactive cell (Alt+Down), and every cell they cover shows an arrow that opens it.+ Date rules open the date calendar on their cells, empty ones included.`components/CellListMenu.tsx` anchors the non-modal list to the cell: below it,or above or beside it when there is no room, never over it. While a list isopen, pressing another dropdown cell opens that cell's list instead.@@ -591,6 +601,7 @@ The [browser fixture](browser-test/README.md) runs the composed editor with realcalculation and Excel workers. Its Playwright suite covers formula autocompleteand range picking, dragging a selection to move it, menu/dialog focus, sheet navigation, read-only transitions,Excel round trips, imported conditional formatting, data validation and notes,+date cell calendars,imported charts and images (following edits, Delete and undo, and download),radar, bubble, stock and contour charts, shapes, SmartArt and EMF images,workbook import undo, and formatting without remounts or flashes.diff --git a/apps/web/src/features/block-spreadsheet/browser-test/README.md b/apps/web/src/features/block-spreadsheet/browser-test/README.mdindex 114dda8442..4b67dc5a69 100644--- a/apps/web/src/features/block-spreadsheet/browser-test/README.md+++ b/apps/web/src/features/block-spreadsheet/browser-test/README.md@@ -38,6 +38,8 @@ Dropdowns added, used and removed from the toolbar and cell menus (withchoice colors drawn as chips in cells and in the open list), open listskept clear of their cell (above it near the bottom edge) and moved to anotherdropdown cell with one click,+date calendars on typed, imported and date-validated cells (keys, clicks and+the stored form of the picked day),imported conditional formatting, validation lists and notes, imported chartsand images (drawn over their cells, following edits, deleted and restored withundo, and kept in the download), radar, bubble, stock and contour chartsdiff --git a/apps/web/src/features/block-spreadsheet/browser-test/date-picker.browser.e2e.ts b/apps/web/src/features/block-spreadsheet/browser-test/date-picker.browser.e2e.tsnew file mode 100644index 0000000000..99435ceea5--- /dev/null+++ b/apps/web/src/features/block-spreadsheet/browser-test/date-picker.browser.e2e.ts@@ -0,0 +1,213 @@+import { expect, type Page, test } from '@playwright/test';+import ExcelJS from 'exceljs';++const cell = (page: Page, address: string) =>+ page.locator(`[data-address="${address}"]`);+const picker = (page: Page) => page.locator('[data-cell-date-picker]');+const pickerDay = (page: Page, state: 'active' | 'selected' | 'today') =>+ picker(page).locator(`[data-${state}]`);+const value = (page: Page, sheet: number, address: string) =>+ page.evaluate(+ ([index, key]) =>+ window.spreadsheetFixture.snapshot()[Number(index)].cells[key]?.value,+ [sheet, address]+ );++async function enter(page: Page, address: string, text: string) {+ await cell(page, address).click();+ await page.keyboard.type(text);+ await page.keyboard.press('Enter');+}++/** Due dates with a time, and a column that only accepts dates from 2026. */+async function scheduleWorkbook() {+ const workbook = new ExcelJS.Workbook();+ const sheet = workbook.addWorksheet('Schedule');+ sheet.getRow(1).values = ['Due', 'Review'];+ sheet.getCell('A2').value = new Date(Date.UTC(2026, 9, 16, 9, 30));+ sheet.getCell('A2').numFmt = 'mmm d, yyyy h:mm';+ sheet.getCell('C2').value = { formula: 'A2+1' };+ sheet.getCell('C2').numFmt = 'm/d/yyyy';+ for (let row = 2; row <= 10; row++)+ sheet.getCell(`B${row}`).dataValidation = {+ type: 'date',+ operator: 'greaterThanOrEqual',+ allowBlank: true,+ formulae: [new Date(Date.UTC(2026, 0, 1))],+ showErrorMessage: true,+ error: 'Pick a date in 2026 or later.',+ };+ return Buffer.from(await workbook.xlsx.writeBuffer());+}++test.beforeEach(async ({ page }) => {+ await page.clock.setFixedTime(new Date(2026, 9, 16, 12));+ await page.goto('/');+ await expect(cell(page, 'B4')).toHaveText('30');+});++test('a date cell opens a calendar below its editor; keys move and pick days', async ({+ page,+}) => {+ const grid = page.getByRole('grid', { name: 'Spreadsheet' });+ const address = page.getByRole('textbox', { name: 'Go to cell' });+ const editor = page.getByRole('textbox', { name: 'Edit C2', exact: true });+ // It opens even while the new date is still being calculated.+ await enter(page, 'C2', '10/16/2026');+ await cell(page, 'C2').dblclick();+ await expect(picker(page)).toBeVisible();+ await expect(editor).toBeFocused();+ await expect(picker(page)).toContainText('October 2026');+ await expect(pickerDay(page, 'selected')).toHaveText('16');+ await expect(pickerDay(page, 'active')).toHaveText('16');+ // Like the dropdown list, the calendar sits beside the cell, not over it.+ const cellBox = await cell(page, 'C2').boundingBox();+ const pickerBox = await picker(page).boundingBox();+ expect(pickerBox!.y).toBeGreaterThanOrEqual(cellBox!.y + cellBox!.height);++ await page.keyboard.press('ArrowRight');+ await expect(pickerDay(page, 'active')).toHaveText('17');+ await page.keyboard.press('ArrowDown');+ await expect(pickerDay(page, 'active')).toHaveText('24');+ await page.keyboard.press('Enter');+ await expect(picker(page)).toBeHidden();+ await expect(cell(page, 'C2')).toHaveText('10/24/2026');+ // A typed date is stored as its serial number shown as a date.+ expect(await value(page, 0, 'C2')).toBe('46319');+ await expect(address).toHaveValue('C3');+ await expect(grid).toBeFocused();++ // Escape closes the calendar first, then the editor, changing nothing.+ await cell(page, 'C2').click();+ await page.keyboard.press('Enter');+ await expect(pickerDay(page, 'active')).toHaveText('24');+ await page.keyboard.press('PageDown');+ await expect(picker(page)).toContainText('November 2026');+ await page.keyboard.press('Escape');+ await expect(picker(page)).toBeHidden();+ await expect(editor).toBeFocused();+ await page.keyboard.press('Escape');+ await expect(editor).toBeHidden();+ await expect(cell(page, 'C2')).toHaveText('10/24/2026');++ // A pressed day is written and the cell stays selected.+ await page.keyboard.press('Enter');+ await picker(page).getByRole('button', { name: 'Next month' }).click();+ await expect(picker(page)).toContainText('November 2026');+ await picker(page)+ .getByRole('gridcell', { name: '3', exact: true, disabled: false })+ .click();+ await expect(cell(page, 'C2')).toHaveText('11/3/2026');+ await expect(address).toHaveValue('C2');+ await expect(grid).toBeFocused();++ // Typing edits the raw value; arrows then move the caret, not days.+ await page.keyboard.press('Enter');+ await expect(picker(page)).toBeVisible();+ await page.keyboard.press('Backspace');+ await expect(picker(page)).toBeHidden();+ await page.keyboard.type('7');+ await page.keyboard.press('ArrowLeft');+ await expect(editor).toHaveValue('11/3/2027');+ await page.keyboard.press('Enter');+ await expect(cell(page, 'C2')).toHaveText('11/3/2027');++ // Text and formulas have no calendar.+ await cell(page, 'A2').dblclick();+ await expect(+ page.getByRole('textbox', { name: 'Edit A2', exact: true })+ ).toBeFocused();+ await expect(picker(page)).toHaveCount(0);+ await page.keyboard.press('Escape');+ await enter(page, 'D2', '=C2+1');+ await expect(cell(page, 'D2')).toHaveText('11/4/2027');+ await cell(page, 'D2').dblclick();+ await expect(+ page.getByRole('textbox', { name: 'Edit D2', exact: true })+ ).toBeFocused();+ await expect(picker(page)).toHaveCount(0);+});++test('a picked date is written the way the cell already stores it', async ({+ page,+}) => {+ await enter(page, 'C2', '2026-01-31');+ await expect(cell(page, 'C2')).toHaveText('2026-01-31');+ await cell(page, 'C2').click();+ await page.keyboard.press('Enter');+ // A month later than the 31st is the month's last day.+ await page.keyboard.press('PageDown');+ await expect(pickerDay(page, 'active')).toHaveText('28');+ await page.keyboard.press('Enter');+ await expect(cell(page, 'C2')).toHaveText('2026-02-28');+ expect(await value(page, 0, 'C2')).toBe('46081');++ const chooser = page.waitForEvent('filechooser');+ await page+ .getByRole('button', { name: 'Import and export', exact: true })+ .click();+ await page.getByRole('menuitem', { name: 'Import…', exact: true }).click();+ await (await chooser).setFiles({+ name: 'schedule.xlsx',+ mimeType:+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',+ buffer: await scheduleWorkbook(),+ });+ await page.getByRole('button', { name: 'Import workbook' }).click();+ await page.getByRole('tab', { name: 'Schedule', exact: true }).click();+ await expect(cell(page, 'A2')).toHaveText('Oct 16, 2026 9:30');+ await expect(cell(page, 'C2')).toHaveText('10/17/2026');++ // A serial number keeps its time of day and its number format.+ await cell(page, 'A2').dblclick();+ await expect(pickerDay(page, 'selected')).toHaveText('16');+ await page.keyboard.press('ArrowRight');+ await page.keyboard.press('Enter');+ await expect(cell(page, 'A2')).toHaveText('Oct 17, 2026 9:30');+ expect(Number(await value(page, 1, 'A2'))).toBeCloseTo(46312.3958333, 6);+ await expect(cell(page, 'C2')).toHaveText('10/18/2026');+});++test('date validation opens the calendar on empty cells and checks the pick', async ({+ page,+}) => {+ const chooser = page.waitForEvent('filechooser');+ await page+ .getByRole('button', { name: 'Import and export', exact: true })+ .click();+ await page.getByRole('menuitem', { name: 'Import…', exact: true }).click();+ await (await chooser).setFiles({+ name: 'schedule.xlsx',+ mimeType:+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',+ buffer: await scheduleWorkbook(),+ });+ await page.getByRole('button', { name: 'Import workbook' }).click();+ await page.getByRole('tab', { name: 'Schedule', exact: true }).click();+ await expect(cell(page, 'A2')).toHaveText('Oct 16, 2026 9:30');++ // An empty cell starts at today, with no day selected.+ await cell(page, 'B3').dblclick();+ await expect(picker(page)).toContainText('October 2026');+ await expect(pickerDay(page, 'selected')).toHaveCount(0);+ await expect(pickerDay(page, 'active')).toHaveText('16');+ await expect(pickerDay(page, 'today')).toHaveText('16');+ await page.keyboard.press('Enter');+ await expect(cell(page, 'B3')).toHaveText('10/16/2026');++ // A day the rule rejects is not written.+ await cell(page, 'B4').click();+ await page.keyboard.press('Enter');+ await page.keyboard.press('Shift+PageUp');+ await expect(picker(page)).toContainText('October 2025');+ await page.keyboard.press('Enter');+ await expect(cell(page, 'B4')).toHaveText('');+ await expect(page.getByText('Pick a date in 2026 or later.')).toBeVisible();++ // Cells outside the rule without a date keep a plain editor.+ await cell(page, 'D3').dblclick();+ await expect(+ page.getByRole('textbox', { name: 'Edit D3', exact: true })+ ).toBeFocused();+ await expect(picker(page)).toHaveCount(0);+});diff --git a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.tsindex 50872685b9..4768080abe 100644--- a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts+++ b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts@@ -195,6 +195,27 @@ test('touch taps select, edit, apply, and cancel cell drafts', async ({await expect(formulaBar(page)).toHaveValue('42');});+test('editing a date cell by touch opens its calendar, and a tapped day is written', async ({+ page,+}) => {+ await cell(page, 'C2').tap();+ await cell(page, 'C2').tap();+ await page.getByRole('textbox', { name: 'Edit C2' }).fill('10/16/2026');+ await button(page, 'Apply edit').tap();+ await expect(cell(page, 'C2')).toHaveText('10/16/2026');++ await cell(page, 'C2').tap();+ await cell(page, 'C2').tap();+ const picker = page.locator('[data-cell-date-picker]');+ await expect(picker).toBeVisible();+ await expectInsideViewport(page, picker);+ await picker+ .getByRole('gridcell', { name: '20', exact: true, disabled: false })+ .tap();+ await expect(cell(page, 'C2')).toHaveText('10/20/2026');+ await expect(picker).toBeHidden();+});+test('selection handles extend a range (WebKit drag uses a mouse pointer)', async ({page,browserName,diff --git a/apps/web/src/features/block-spreadsheet/components/CellDatePicker.test.ts b/apps/web/src/features/block-spreadsheet/components/CellDatePicker.test.tsnew file mode 100644index 0000000000..4d2268856f--- /dev/null+++ b/apps/web/src/features/block-spreadsheet/components/CellDatePicker.test.ts@@ -0,0 +1,56 @@+import { describe, expect, it } from 'vitest';+import { datePickerKeyDay } from './CellDatePicker';++const key = (key: string, init: KeyboardEventInit = {}) =>+ new KeyboardEvent('keydown', { key, ...init });++describe('date picker keys', () => {+ it('moves by a day with left and right, and a week with up and down', () => {+ const day = new Date(2026, 9, 31);+ expect(datePickerKeyDay(key('ArrowLeft'), day)).toEqual(+ new Date(2026, 9, 30)+ );+ expect(datePickerKeyDay(key('ArrowRight'), day)).toEqual(+ new Date(2026, 10, 1)+ );+ expect(datePickerKeyDay(key('ArrowUp'), day)).toEqual(+ new Date(2026, 9, 24)+ );+ expect(datePickerKeyDay(key('ArrowDown'), day)).toEqual(+ new Date(2026, 10, 7)+ );+ });++ it('moves by a month or a year to the same day, or the last of a shorter month', () => {+ expect(datePickerKeyDay(key('PageDown'), new Date(2026, 0, 31))).toEqual(+ new Date(2026, 1, 28)+ );+ expect(datePickerKeyDay(key('PageUp'), new Date(2026, 2, 15))).toEqual(+ new Date(2026, 1, 15)+ );+ expect(+ datePickerKeyDay(key('PageUp', { shiftKey: true }), new Date(2028, 1, 29))+ ).toEqual(new Date(2027, 1, 28));+ expect(+ datePickerKeyDay(+ key('PageDown', { shiftKey: true }),+ new Date(2026, 11, 31)+ )+ ).toEqual(new Date(2027, 11, 31));+ });++ it('leaves modified arrows and other keys to the editor', () => {+ const day = new Date(2026, 9, 16);+ expect(+ datePickerKeyDay(key('ArrowLeft', { shiftKey: true }), day)+ ).toBeUndefined();+ expect(+ datePickerKeyDay(key('ArrowRight', { metaKey: true }), day)+ ).toBeUndefined();+ expect(+ datePickerKeyDay(key('ArrowDown', { altKey: true }), day)+ ).toBeUndefined();+ expect(datePickerKeyDay(key('Home'), day)).toBeUndefined();+ expect(datePickerKeyDay(key('1'), day)).toBeUndefined();+ });+});diff --git a/apps/web/src/features/block-spreadsheet/components/CellDatePicker.tsx b/apps/web/src/features/block-spreadsheet/components/CellDatePicker.tsxnew file mode 100644index 0000000000..734452c88a--- /dev/null+++ b/apps/web/src/features/block-spreadsheet/components/CellDatePicker.tsx@@ -0,0 +1,179 @@+import Calendar from '@corvu/calendar';+import CaretLeft from '@phosphor/caret-left.svg';+import CaretRight from '@phosphor/caret-right.svg';+import { Index } from 'solid-js';+import { Portal } from 'solid-js/web';+import { createTouchPress } from '../primitives/create-touch-press';+import { EditorPopup } from './EditorPopup';++const monthLabel = new Intl.DateTimeFormat('en-US', {+ month: 'long',+ year: 'numeric',+}).format;+const weekdayLong = new Intl.DateTimeFormat('en-US', { weekday: 'long' })+ .format;+const weekdayNarrow = new Intl.DateTimeFormat('en-US', { weekday: 'narrow' })+ .format;+const dayLabel = new Intl.DateTimeFormat('en-US', { dateStyle: 'full' }).format;+const DAY_KEYS: Record<string, number> = {+ ArrowLeft: -1,+ ArrowRight: 1,+ ArrowUp: -7,+ ArrowDown: 7,+};++/** `day` moved by days, or by months to the same day or the month's last. */+function moveDay(day: Date, days: number, months = 0) {+ const last = new Date(day.getFullYear(), day.getMonth() + months + 1, 0);+ return new Date(+ last.getFullYear(),+ last.getMonth(),+ Math.min(day.getDate(), last.getDate()) + days+ );+}++/**+ * The day a key moves the date picker to: arrows by a day or a week, Page Up+ * and Page Down by a month, or by a year with Shift.+ */+export function datePickerKeyDay(+ event: KeyboardEvent,+ day: Date+): Date | undefined {+ if (event.altKey || event.ctrlKey || event.metaKey) return;+ if (event.key === 'PageUp' || event.key === 'PageDown')+ return moveDay(+ day,+ 0,+ (event.key === 'PageUp' ? -1 : 1) * (event.shiftKey ? 12 : 1)+ );+ const days = DAY_KEYS[event.key];+ if (event.shiftKey || days === undefined) return;+ return moveDay(day, days);+}++/**+ * A calendar beside a date cell's editor. The editor keeps focus, so the grid+ * moves `day` with the keyboard; pressing a day picks it.+ */+export function CellDatePicker(props: {+ anchor: HTMLElement;+ /** The day the cell holds. */+ value?: Date;+ /** The day the keyboard moves and Enter picks. */+ day: Date;+ onDayChange: (day: Date) => void;+ onPick: (day: Date) => void;+ onDismiss: () => void;+}) {+ const navigation =+ 'flex size-7 items-center justify-center rounded-md text-ink-muted hover:bg-hover hover:text-ink touch:size-10';+ return (+ <Portal>+ <EditorPopup+ anchor={props.anchor}+ interactive+ class="w-64 p-2 touch:w-80"+ onOutsidePress={props.onDismiss}+ >+ <Calendar+ mode="single"+ value={props.value ?? null}+ month={new Date(props.day.getFullYear(), props.day.getMonth(), 1)}+ focusedDay={props.day}+ startOfWeek={0}+ fixedWeeks+ >+ {(calendar) => (+ <div data-cell-date-picker>+ <div class="flex items-center gap-0.5">+ <Calendar.Label class="min-w-0 flex-1 truncate px-1 text-xs font-medium">+ {monthLabel(calendar.month)}+ </Calendar.Label>+ <button+ {...createTouchPress(() =>+ props.onDayChange(moveDay(props.day, 0, -1))+ )}+ type="button"+ tabIndex={-1}+ aria-label="Previous month"+ class={navigation}+ >+ <CaretLeft class="size-3" />+ </button>+ <button+ {...createTouchPress(() =>+ props.onDayChange(moveDay(props.day, 0, 1))+ )}+ type="button"+ tabIndex={-1}+ aria-label="Next month"+ class={navigation}+ >+ <CaretRight class="size-3" />+ </button>+ </div>+ <Calendar.Table class="mt-1 w-full table-fixed border-collapse">+ <thead>+ <tr>+ <Index each={calendar.weekdays}>+ {(weekday) => (+ <Calendar.HeadCell+ abbr={weekdayLong(weekday())}+ class="h-7 text-center text-[10px] font-medium text-ink-extra-muted"+ >+ {weekdayNarrow(weekday())}+ </Calendar.HeadCell>+ )}+ </Index>+ </tr>+ </thead>+ <tbody>+ <Index each={calendar.weeks}>+ {(week) => (+ <tr>+ <Index each={week()}>+ {(day) => {+ const press = createTouchPress(() =>+ props.onPick(day())+ );+ return (+ <Calendar.Cell class="p-0 text-center">+ <Calendar.CellTrigger+ {...press}+ day={day()}+ month={calendar.month}+ tabIndex={-1}+ data-active={+ day().getTime() === props.day.getTime()+ ? ''+ : undefined+ }+ class="mx-auto flex size-7 items-center justify-center rounded-md text-xs text-ink-muted hover:bg-hover hover:text-ink disabled:pointer-events-none disabled:opacity-30 touch:size-10 touch:text-sm data-today:border data-today:border-accent data-today:font-semibold data-active:bg-hover data-active:ring-2 data-active:ring-accent data-active:text-ink data-selected:bg-accent! data-selected:text-surface!"+ onClick={(event: MouseEvent) => {+ // Corvu skips its own selection.+ event.preventDefault();+ press.onClick(event);+ }}+ >+ {day().getDate()}+ </Calendar.CellTrigger>+ </Calendar.Cell>+ );+ }}+ </Index>+ </tr>+ )}+ </Index>+ </tbody>+ </Calendar.Table>+ <span class="sr-only" aria-live="polite">+ {dayLabel(props.day)}+ </span>+ </div>+ )}+ </Calendar>+ </EditorPopup>+ </Portal>+ );+}diff --git a/apps/web/src/features/block-spreadsheet/components/EditorPopup.tsx b/apps/web/src/features/block-spreadsheet/components/EditorPopup.tsxnew file mode 100644index 0000000000..6dc4c1e588--- /dev/null+++ b/apps/web/src/features/block-spreadsheet/components/EditorPopup.tsx@@ -0,0 +1,81 @@+import {+ autoUpdate,+ computePosition,+ flip,+ offset,+ shift,+ size,+} from '@floating-ui/dom';+import { type JSX, onCleanup, onMount } from 'solid-js';++/**+ * A popup below (or above) a cell or formula editor. Pressing it keeps focus+ * and editing in the editor.+ */+export function EditorPopup(props: {+ anchor: HTMLElement;+ interactive: boolean;+ class?: string;+ children: JSX.Element;+ onReady?: (element: HTMLDivElement) => void;+ onOutsidePress: () => void;+}) {+ let element!: HTMLDivElement;+ onMount(() => {+ props.onReady?.(element);+ // Pressing a cell, sheet tab, or toolbar keeps the draft but closes the popup.+ const press = (event: PointerEvent) => {+ const target = event.target as Node;+ if (!element.contains(target) && !props.anchor.contains(target))+ props.onOutsidePress();+ };+ document.addEventListener('pointerdown', press, true);+ onCleanup(() => document.removeEventListener('pointerdown', press, true));+ let alive = true;+ const update = async () => {+ const position = await computePosition(props.anchor, element, {+ strategy: 'fixed',+ placement: 'bottom-start',+ middleware: [+ offset(5),+ flip(),+ shift({ padding: 12 }),+ size({+ padding: 12,+ apply({ availableHeight, elements }) {+ elements.floating.style.maxHeight = `${Math.max(0, availableHeight)}px`;+ },+ }),+ ],+ });+ if (alive)+ Object.assign(element.style, {+ left: `${position.x}px`,+ top: `${position.y}px`,+ visibility: 'visible',+ });+ };+ const cleanup = autoUpdate(props.anchor, element, () => {+ void update();+ });+ onCleanup(() => {+ alive = false;+ cleanup();+ });+ });+ return (+ <div+ ref={element}+ style={{ visibility: 'hidden' }}+ class={`fixed z-[100] flex max-w-[calc(100vw-24px)] flex-col overflow-hidden rounded-lg border border-edge bg-panel text-ink shadow-xl ${props.class ?? ''}`}+ classList={{ 'pointer-events-none': !props.interactive }}+ onPointerDown={(event) => {+ event.preventDefault();+ event.stopPropagation();+ }}+ onMouseDown={(event) => event.preventDefault()}+ >+ {props.children}+ </div>+ );+}diff --git a/apps/web/src/features/block-spreadsheet/components/FormulaInput.tsx b/apps/web/src/features/block-spreadsheet/components/FormulaInput.tsxindex 2a9854bc25..cfe9cc5549 100644--- a/apps/web/src/features/block-spreadsheet/components/FormulaInput.tsx+++ b/apps/web/src/features/block-spreadsheet/components/FormulaInput.tsx@@ -1,11 +1,3 @@-import {- autoUpdate,- computePosition,- flip,- offset,- shift,- size,-} from '@floating-ui/dom';import {createEffect,createSignal,@@ -33,6 +25,7 @@ import {createFormulaAssistance,} from '../primitives/create-formula-assistance';import { createTouchPress } from '../primitives/create-touch-press';+import { EditorPopup } from './EditorPopup';/** Shared cell/formula-bar input. The popup keeps focus and editing in the textarea. */export type FormulaInputProps = {@@ -242,9 +235,10 @@ function FormulaTextarea(props: FormulaInputProps & { typed?: boolean }) {</Show><Show when={popupVisible()}><Portal>- <FormulaPopup+ <EditorPopupanchor={input}interactive={choices().length > 0}+ class="w-72"onReady={(element) => {popup = element;}}@@ -325,7 +319,7 @@ function FormulaTextarea(props: FormulaInputProps & { typed?: boolean }) {</p></Show></div>- </FormulaPopup>+ </EditorPopup></Portal></Show></>@@ -419,70 +413,3 @@ function ReferenceMirror(props: {</div>);}--function FormulaPopup(props: {- anchor: HTMLElement;- interactive: boolean;- children: import('solid-js').JSX.Element;- onReady: (element: HTMLDivElement) => void;- onOutsidePress: () => void;-}) {- let element!: HTMLDivElement;- onMount(() => {- props.onReady(element);- // Pressing a cell, sheet tab, or toolbar keeps the draft but closes help.- const press = (event: PointerEvent) => {- const target = event.target as Node;- if (!element.contains(target) && !props.anchor.contains(target))- props.onOutsidePress();- };- document.addEventListener('pointerdown', press, true);- onCleanup(() => document.removeEventListener('pointerdown', press, true));- let alive = true;- const update = async () => {- const position = await computePosition(props.anchor, element, {- strategy: 'fixed',- placement: 'bottom-start',- middleware: [- offset(5),- flip(),- shift({ padding: 12 }),- size({- padding: 12,- apply({ availableHeight, elements }) {- elements.floating.style.maxHeight = `${Math.max(0, availableHeight)}px`;- },- }),- ],- });- if (alive)- Object.assign(element.style, {- left: `${position.x}px`,- top: `${position.y}px`,- visibility: 'visible',- });- };- const cleanup = autoUpdate(props.anchor, element, () => {- void update();- });- onCleanup(() => {- alive = false;- cleanup();- });- });- return (- <div- ref={element}- style={{ visibility: 'hidden' }}- class="fixed z-[100] flex w-72 max-w-[calc(100vw-24px)] flex-col overflow-hidden rounded-lg border border-edge bg-panel text-ink shadow-xl"- classList={{ 'pointer-events-none': !props.interactive }}- onPointerDown={(event) => {- event.preventDefault();- event.stopPropagation();- }}- onMouseDown={(event) => event.preventDefault()}- >- {props.children}- </div>- );-}diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsxindex 4c825fd774..a3dc118087 100644--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx@@ -54,6 +54,7 @@ import {} from '../core/spreadsheet-document';import type { SpreadsheetCursor } from '../core/spreadsheet-presence';import type { CompleteFormula } from '../primitives/create-formula-assistance';+import { CellDatePicker, datePickerKeyDay } from './CellDatePicker';import { CellListMenu } from './CellListMenu';import { ChoiceChip } from './ChoiceChip';import { ConditionalIcon } from './ConditionalIcon';@@ -210,6 +211,9 @@ export function SpreadsheetGrid(props: {/** The active cell's list of allowed values, offered in a dropdown. */listItems?: string[];onPickListItem?: (item: string) => void;+ /** The active cell offers a calendar while it is edited; `date` is its day. */+ datePicker?: { date?: Date };+ onPickDate?: (day: Date) => void;/*** Dropdown rules: their ranges (Excel sqrefs), whose cells show an arrow,* and their choice colors by lowercase text.@@ -288,6 +292,27 @@ export function SpreadsheetGrid(props: {!props.editing &&!props.formulaEditing &&!!props.listItems?.length;+ // Opening an editor without typing asks for a calendar, shown once the cell+ // is known to offer one. Typing, Escape and ending the edit close it.+ const [pickerOpen, setPickerOpen] = createSignal(false);+ // The day its keys moved to; it starts at the cell's day, or today.+ const [pickerDay, setPickerDay] = createSignal<Date>();+ const shownPickerDay = () => {+ if (!props.editing || !pickerOpen() || !props.datePicker) return;+ const now = new Date();+ return (+ pickerDay() ??+ props.datePicker.date ??+ new Date(now.getFullYear(), now.getMonth(), now.getDate())+ );+ };+ function openDatePicker() {+ setPickerDay(undefined);+ setPickerOpen(props.editing);+ }+ createEffect(() => {+ if (!props.editing) setPickerOpen(false);+ });const dropdownAreas = createMemo(() =>(props.dropdowns ?? []).map((dropdown) => ({bounds: sqrefBounds(dropdown.range),@@ -695,6 +720,7 @@ export function SpreadsheetGrid(props: {props.onSelect(position);if (repeat && !props.readonly) {props.onEdit();+ openDatePicker();// iOS may synthesize mousedown on the old cell after mounting its editor.keepReferenceFocus = true;lastTap = undefined;@@ -1042,6 +1068,8 @@ export function SpreadsheetGrid(props: {function editKeyDown(event: KeyboardEvent) {event.stopPropagation();if (event.isComposing) return;+ const day = shownPickerDay();+ if (day && datePickerKeyDown(event, day)) return;if (event.key === 'Escape') {event.preventDefault();props.onCancel();@@ -1061,6 +1089,28 @@ export function SpreadsheetGrid(props: {}}+ /** Keys of an open date picker. Others, such as typing, stay the editor's. */+ function datePickerKeyDown(event: KeyboardEvent, day: Date) {+ if (event.key === 'Escape') {+ event.preventDefault();+ setPickerOpen(false);+ return true;+ }+ if (event.key === 'Enter' && !event.altKey) {+ event.preventDefault();+ props.onPickDate?.(day);+ props.onMove(event.shiftKey ? -1 : 1, 0);+ focusGrid();+ revealSelection();+ return true;+ }+ const next = datePickerKeyDay(event, day);+ if (!next) return false;+ event.preventDefault();+ setPickerDay(next);+ return true;+ }+function copyCells(event: ClipboardEvent) {event.preventDefault();event.clipboardData?.setData('text/plain', props.onCopy());@@ -1337,6 +1387,7 @@ export function SpreadsheetGrid(props: {(event.metaKey || event.ctrlKey) &&event.key.toLowerCase() === 'a';props.onKeyDown(event);+ if (event.key === 'Enter' || event.key === 'F2') openDatePicker();// Select all ends at the last cell; revealing it would scroll away// from the cells the user is looking at.if (@@ -1878,8 +1929,9 @@ export function SpreadsheetGrid(props: {else dragging = false;}}onDblClick={() => {- if (!touchMode() && !props.referenceSelection)- props.onEdit();+ if (touchMode() || props.referenceSelection) return;+ props.onEdit();+ openDatePicker();}}><Show when={look()?.dataBar}>@@ -1999,7 +2051,10 @@ export function SpreadsheetGrid(props: {: 'text-left'}`}value={props.draft}- onInput={props.onDraft}+ onInput={(value) => {+ setPickerOpen(false);+ props.onDraft(value);+ }}onKeyDown={editKeyDown}onBlur={() => {if (props.editing) props.onCommit();@@ -2266,6 +2321,30 @@ export function SpreadsheetGrid(props: {);}}</Show>+ <Show when={shownPickerDay()}>+ {(day) => (+ <Show+ when={renderedSelectionCell(grid, {+ anchor: props.selection.anchor,+ focus: props.selection.anchor,+ })}+ >+ {(anchor) => (+ <CellDatePicker+ anchor={anchor()}+ value={props.datePicker?.date}+ day={day()}+ onDayChange={setPickerDay}+ onPick={(picked) => {+ props.onPickDate?.(picked);+ focusGrid();+ }}+ onDismiss={() => setPickerOpen(false)}+ />+ )}+ </Show>+ )}+ </Show><Showwhen={!props.editing &&diff --git a/apps/web/src/features/block-spreadsheet/core/calculation.test.ts b/apps/web/src/features/block-spreadsheet/core/calculation.test.tsindex 369d27884d..b2a714287a 100644--- a/apps/web/src/features/block-spreadsheet/core/calculation.test.ts+++ b/apps/web/src/features/block-spreadsheet/core/calculation.test.ts@@ -280,25 +280,72 @@ describe('spreadsheet calculation with IronCalc', () => {A13: { value: '=YEAR(A1)' },A14: { value: '=A1+7', numberFormat: '0.0' },});- expect(result.A1).toEqual({ display: '9/28/2026', number: 46293 });- expect(result.A2).toEqual({ display: '9/28/2026', number: 46293 });- expect(result.A3).toEqual({ display: '10/5/2026', number: 46300 });- expect(result.A4).toEqual({ display: '1/1/2026', number: 46023 });+ expect(result.A1).toEqual({+ display: '9/28/2026',+ number: 46293,+ date: true,+ });+ expect(result.A2).toEqual({+ display: '9/28/2026',+ number: 46293,+ date: true,+ });+ expect(result.A3).toEqual({+ display: '10/5/2026',+ number: 46300,+ date: true,+ });+ expect(result.A4).toEqual({+ display: '1/1/2026',+ number: 46023,+ date: true,+ });// The engine formats a difference of dates as a date; a day count is not.expect(result.A5).toEqual({ display: '7', number: 7 });expect(result.A6.display).toBe('46,300.00');- expect(result.A7).toEqual({ display: '5/1/1985', number: 31168 });+ expect(result.A7).toEqual({+ display: '5/1/1985',+ number: 31168,+ date: true,+ });// Formula results before 2000 stay serial numbers; day counts are common there.expect(result.A8).toEqual({ display: '31168', number: 31168 });// Chained formulas are entered in grid order, so each inherits the format.- expect(result.A9).toEqual({ display: '9/29/2026', number: 46294 });- expect(result.A10).toEqual({ display: '9/30/2026', number: 46295 });+ expect(result.A9).toEqual({+ display: '9/29/2026',+ number: 46294,+ date: true,+ });+ expect(result.A10).toEqual({+ display: '9/30/2026',+ number: 46295,+ date: true,+ });expect(result.A11).toEqual({ display: '46293', number: 46293 });expect(result.A12).toEqual({ display: 'Sep 28, 2026' });expect(result.A13).toEqual({ display: '2026', number: 2026 });expect(result.A14.display).toBe('46300.0');});+ it('marks numbers shown as calendar dates, not times or plain numbers', () => {+ const result = calculator.calculate({+ A1: { value: '46293', format: 'date' },+ A2: { value: '46293.5', numberFormat: 'mmm d, yyyy h:mm' },+ A3: { value: '0.5', format: 'time' },+ A4: { value: '0.5', numberFormat: 'h:mm' },+ A5: { value: '46293', numberFormat: '#,##0 "days"' },+ A6: { value: '$1,000' },+ });+ expect(result.A1.date).toBe(true);+ expect(result.A2).toEqual({+ display: 'Sep 28, 2026 12:00',+ number: 46293.5,+ date: true,+ });+ for (const address of ['A3', 'A4', 'A5', 'A6'])+ expect(result[address].date).toBeUndefined();+ });+it('shows serials in date formats as dates, and formulas on them inherit a date display', () => {const result = calculator.calculate({A1: { value: '46023', format: 'date', numberFormat: 'mmm yyyy' },@@ -312,14 +359,27 @@ describe('spreadsheet calculation with IronCalc', () => {A5: { value: '46023', format: 'date' },A6: { value: '=A1+31', format: 'number', decimals: 0 },});- expect(result.A1).toEqual({ display: 'Jan 2026', number: 46023 });- expect(result.A2).toEqual({ display: '2/1/2026', number: 46054 });+ expect(result.A1).toEqual({+ display: 'Jan 2026',+ number: 46023,+ date: true,+ });+ expect(result.A2).toEqual({+ display: '2/1/2026',+ number: 46054,+ date: true,+ });expect(result.A3).toEqual({display: 'Thursday, September 17, 2026',number: 46282,+ date: true,});expect(result.A4).toEqual({ display: '259', number: 259 });- expect(result.A5).toEqual({ display: '1/1/2026', number: 46023 });+ expect(result.A5).toEqual({+ display: '1/1/2026',+ number: 46023,+ date: true,+ });expect(result.A6.display).toBe('46,054');});diff --git a/apps/web/src/features/block-spreadsheet/core/cell-date.test.ts b/apps/web/src/features/block-spreadsheet/core/cell-date.test.tsnew file mode 100644index 0000000000..9d997cf2de--- /dev/null+++ b/apps/web/src/features/block-spreadsheet/core/cell-date.test.ts@@ -0,0 +1,52 @@+import {+ cellDateMention,+ cellPlainText,+ encodeCellMention,+} from '@macro-inc/spreadsheet/cell-mentions';+import { describe, expect, it } from 'vitest';+import { cellDateInput, serialDay } from './cell-date';++describe('date cells', () => {+ it('reads the calendar day of an Excel serial, around its 1900 leap day', () => {+ expect(serialDay(46311)).toEqual(new Date(2026, 9, 16));+ expect(serialDay(46311.75)).toEqual(new Date(2026, 9, 16));+ expect(serialDay(59)).toEqual(new Date(1900, 1, 28));+ expect(serialDay(61)).toEqual(new Date(1900, 2, 1));+ });++ it('writes a serial number for a serial, keeping its time of day', () => {+ expect(cellDateInput('46311', new Date(2026, 9, 24))).toBe('46319');+ expect(cellDateInput('46311.395833333336', new Date(2026, 9, 17))).toBe(+ '46312.3958333333'+ );+ expect(cellDateInput('59', new Date(1900, 2, 1))).toBe('61');+ });++ it('writes typed dates as ISO when they were, and month/day/year otherwise', () => {+ expect(cellDateInput('2026-01-31', new Date(2026, 1, 28))).toBe(+ '2026-02-28'+ );+ expect(cellDateInput('10/16/2026', new Date(2026, 9, 24))).toBe(+ '10/24/2026'+ );+ expect(cellDateInput('16-Oct-2026', new Date(2026, 9, 24))).toBe(+ '10/24/2026'+ );+ expect(cellDateInput('', new Date(2027, 0, 5))).toBe('1/5/2027');+ });++ it('keeps a date pill a pill', () => {+ const pill = encodeCellMention({+ type: 'date',+ date: new Date(2026, 9, 16).toISOString(),+ displayFormat: 'Today',+ });+ const written = cellDateInput(pill, new Date(2026, 9, 24));+ expect(cellDateMention(written)).toEqual({+ type: 'date',+ date: new Date(2026, 9, 24).toISOString(),+ displayFormat: '',+ });+ expect(cellPlainText(written)).toBe('Oct 24, 2026');+ });+});diff --git a/apps/web/src/features/block-spreadsheet/core/cell-date.ts b/apps/web/src/features/block-spreadsheet/core/cell-date.tsnew file mode 100644index 0000000000..860adb0842--- /dev/null+++ b/apps/web/src/features/block-spreadsheet/core/cell-date.ts@@ -0,0 +1,49 @@+import {+ cellDateMention,+ encodeCellMention,+} from '@macro-inc/spreadsheet/cell-mentions';+import { numericLiteral } from '@macro-inc/spreadsheet/number-display';++const DAY_MILLISECONDS = 86_400_000;+/** Excel's serial day 0. Serials after 60 skip its fictitious 29 February 1900. */+const SERIAL_ZERO = Date.UTC(1899, 11, 31);++/** The local calendar day an Excel serial number falls on. */+export function serialDay(serial: number): Date {+ const day = Math.floor(serial);+ const date = new Date(+ SERIAL_ZERO + (day > 60 ? day - 1 : day) * DAY_MILLISECONDS+ );+ return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());+}++function daySerial(day: Date): number {+ const days =+ (Date.UTC(day.getFullYear(), day.getMonth(), day.getDate()) - SERIAL_ZERO) /+ DAY_MILLISECONDS;+ return days >= 60 ? days + 1 : days;+}++/**+ * The input that puts `day` in a cell holding `value`, written the way+ * `value` is: a serial number keeps its time of day, a date pill stays a pill+ * and ISO text stays ISO. Other cells get month/day/year, as the grid shows+ * dates.+ */+export function cellDateInput(value: string, day: Date): string {+ if (numericLiteral.test(value)) {+ const serial = Number(value);+ const time = serial - Math.floor(serial);+ return String(Number((daySerial(day) + time).toPrecision(15)));+ }+ if (cellDateMention(value))+ return encodeCellMention({+ type: 'date',+ date: day.toISOString(),+ displayFormat: '',+ });+ const month = day.getMonth() + 1;+ if (/^\s*\d{4}-\d{1,2}-\d{1,2}\s*$/.test(value))+ return `${day.getFullYear()}-${String(month).padStart(2, '0')}-${String(day.getDate()).padStart(2, '0')}`;+ return `${month}/${day.getDate()}/${day.getFullYear()}`;+}diff --git a/apps/web/src/features/block-spreadsheet/core/cell-mentions.test.ts b/apps/web/src/features/block-spreadsheet/core/cell-mentions.test.tsindex b39108a3b7..4846d0d87e 100644--- a/apps/web/src/features/block-spreadsheet/core/cell-mentions.test.ts+++ b/apps/web/src/features/block-spreadsheet/core/cell-mentions.test.ts@@ -178,8 +178,16 @@ describe('spreadsheet mention source', () => {A7: { value: '=A1-DATE(2026,9,20)' },});// The pill's time of day is dropped so date arithmetic stays whole days.- expect(values.A1).toEqual({ display: '9/28/2026', number: 46293 });- expect(values.A2).toEqual({ display: '10/5/2026', number: 46300 });+ expect(values.A1).toEqual({+ display: '9/28/2026',+ number: 46293,+ date: true,+ });+ expect(values.A2).toEqual({+ display: '10/5/2026',+ number: 46300,+ date: true,+ });expect(values.A3).toEqual({ display: 'Due Tomorrow' });expect(values.A4).toEqual({ display: 'Due Tomorrow' });expect(values.A5).toEqual({ display: '46,293.00', number: 46293 });diff --git a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsxindex 3f0350e840..16e1beae20 100644--- a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx+++ b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx@@ -52,6 +52,7 @@ import {} from '../components/SpreadsheetWorkbookDialogs';import type { SpreadsheetCommentsCapability } from '../context/spreadsheet-comments';import type { SpreadsheetMentions } from '../context/spreadsheet-mentions';+import { cellDateInput, serialDay } from '../core/cell-date';import { cellEditValue } from '../core/cell-input';import { chartData, createChartReader } from '../core/chart-data';import { encodeCsv } from '../core/csv-export';@@ -365,6 +366,17 @@ export function SpreadsheetEditor(props: {spreadsheetCursors(props.store.peers(), props.store.rowCount()));const activeCell = () => props.store.cells()[grid.activeAddress()];+ // A calendar edits literal dates, and any value of a date-validated cell.+ const activeDatePicker = createMemo(() => {+ const cell = activeCell();+ if (cell?.value.startsWith('=') && cell.format !== 'text') return;+ const result = values()[grid.activeAddress()];+ const date =+ result?.date && result.number !== undefined+ ? serialDay(result.number)+ : undefined;+ if (date || activeValidation()?.type === 'date') return { date };+ });const footerNotice = () =>workbookActions.busy() ||workbookActions.notice() ||@@ -1084,6 +1096,12 @@ export function SpreadsheetEditor(props: {},});}}+ datePicker={activeDatePicker()}+ onPickDate={(day) => {+ if (day.getTime() !== activeDatePicker()?.date?.getTime())+ grid.setDraft(cellDateInput(activeCell()?.value ?? '', day));+ grid.commit();+ }}pendingFormulas={calculation.busy() &&!(props.store.activeSheetId() in calculation.workbookValues())diff --git a/apps/web/src/features/block-spreadsheet/workers/calculation.worker.ts b/apps/web/src/features/block-spreadsheet/workers/calculation.worker.tsindex 98551033e0..04c4152996 100644--- a/apps/web/src/features/block-spreadsheet/workers/calculation.worker.ts+++ b/apps/web/src/features/block-spreadsheet/workers/calculation.worker.ts@@ -32,6 +32,7 @@ function sameResult(left: CalculatedCell, right: CalculatedCell) {left.number === right.number &&left.error === right.error &&left.warning === right.warning &&+ left.date === right.date &&left.type === right.type &&left.value === right.value &&left.spill?.rows === right.spill?.rows &&diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.mdindex 9976106351..b365a4e863 100644--- a/docs/agent-guide/documents.md+++ b/docs/agent-guide/documents.md@@ -203,6 +203,19 @@ shows the rule's message in the footer, and a "stop" rule keeps the previous valA red corner marks a cell with a note; selecting the cell shows the note, and anyinput message, beside it.+Double-clicking a cell that holds a date (typed, imported or a date pill, but not+a formula), or pressing Enter or F2 on it, opens a calendar below its editor; an+Excel date validation rule opens it on its cells even when they are empty,+starting at today. The editor keeps focus: arrows move the outlined day by a day+or a week, Page Up and Page Down by a month (with Shift, a year), Enter writes the+day and moves down, and Escape closes the calendar (a second Escape cancels the+edit). Clicking a day writes it and keeps the cell selected. Typing closes the+calendar and edits the text as usual. The day is written the way the cell stores+dates, so its format stays: a serial number keeps its time of day, a date pill+stays a pill and ISO text stays ISO. The calendar is `[data-cell-date-picker]`;+its days are `gridcell` buttons marked `data-active` (the keyboard's day),+`data-selected` (the cell's date) and `data-today`.+Images and charts (column, bar, line and area, each clustered, stacked or100% stacked, plus pie, doughnut, scatter, combo, radar, bubble, stock andsurface, drawn as a contour) are drawn over their cells and move with them;diff --git a/packages/spreadsheet/src/calculation.ts b/packages/spreadsheet/src/calculation.tsindex 3b5e532f59..b0db723a5f 100644--- a/packages/spreadsheet/src/calculation.ts+++ b/packages/spreadsheet/src/calculation.ts@@ -38,6 +38,8 @@ export type CalculatedCell = {number?: number;error?: string;warning?: string;+ /** The number shows as a calendar date. */+ date?: boolean;/** Included only for callers requesting typed results. */type?: 'blank' | 'number' | 'text' | 'boolean' | 'error';value?: string | number | boolean | null;@@ -160,11 +162,12 @@ function dateMentionSerial(iso: string): number {}/**- * IronCalc assigns date and time number formats to typed dates and to formulas- * that operate on them, as Excel does. Honor those for cells without an- * explicit Macro format; other inferred formats stay general.+ * Whether an Excel number format shows a date or a time of day. IronCalc+ * assigns such formats to typed dates and to formulas that operate on them,+ * as Excel does. Cells without an explicit Macro format honor those; other+ * inferred formats stay general.*/-function inferredFormat(numberFormat: string): 'date' | 'time' | undefined {+function dateTimeFormat(numberFormat: string): 'date' | 'time' | undefined {const tokens = numberFormat.replace(/"[^"]*"|\\.|\[[^\]]*\]/g, '');if (/[dy]/i.test(tokens)) return 'date';if (/[hs]/i.test(tokens)) return 'time';@@ -991,7 +994,7 @@ function readCell(// The engine infers display formats for typed dates and for formulas that// refer to them, as Excel does.const engineFormat = entered.inferable.has(address)- ? inferredFormat(model.getCellNumberFormat(sheetIndex, row + 1, column + 1))+ ? dateTimeFormat(model.getCellNumberFormat(sheetIndex, row + 1, column + 1)): undefined;// IronCalc also formats a difference of two dates as a date, so// formula results only count as dates from 2000 onwards; a day@@ -1000,10 +1003,12 @@ function readCell(engineFormat !== 'date' ||!cell?.value.startsWith('=') ||number >= MIN_FORMULA_DATE_SERIAL;- let formatted = displayNumber(- number,- engineFormat && dateLike ? { ...cell!, format: engineFormat } : cell- );+ const shown =+ engineFormat && dateLike ? { ...cell!, format: engineFormat } : cell;+ let formatted = displayNumber(number, shown);+ const date = cell?.numberFormat+ ? dateTimeFormat(cell.numberFormat) === 'date'+ : shown?.format === 'date';let warning: string | undefined;if (cell?.numberFormat) {try {@@ -1017,6 +1022,7 @@ function readCell(display: formatted,...(warning && { warning }),number,+ ...(date && { date }),...(includeTypes && { type: 'number' as const, value: number }),};}@@ -1211,6 +1217,7 @@ function sameCalculatedCell(left: CalculatedCell, right: CalculatedCell) {left.number === right.number &&left.error === right.error &&left.warning === right.warning &&+ left.date === right.date &&left.type === right.type &&left.value === right.value &&left.spill?.rows === right.spill?.rows &&