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
fix(reminders): add comprehensive shorthand support for date parsing (#7832)
Jacob Beckerman747d61f9519b
diff --git a/apps/web/src/features/reminders/components/email-reminder-form.test.tsx b/apps/web/src/features/reminders/components/email-reminder-form.test.tsxindex 36a61368b2..3eb058b715 100644--- a/apps/web/src/features/reminders/components/email-reminder-form.test.tsx+++ b/apps/web/src/features/reminders/components/email-reminder-form.test.tsx@@ -40,6 +40,29 @@ it('selects a typed time with Enter, defaulting to if no reply', () => {'if_no_reply');});+it('resolves reminder shorthand like tmrw 8 and tmrw 8p', () => {+ setup();+ const input = screen.getByRole('combobox', { name: 'Remind me when' });++ fireEvent.input(input, { target: { value: 'tmrw' } });+ expect(screen.getByRole('option', { name: /Tomorrow/i })).toBeTruthy();+ expect(+ screen.queryByText('Enter a future time, like in 2 hours or tomorrow 9am.')+ ).toBeNull();++ fireEvent.input(input, { target: { value: 'tmrw 8' } });+ expect(+ screen.getByRole('option', { name: /Tomorrow at 8 AM/i })+ ).toBeTruthy();++ fireEvent.input(input, { target: { value: 'tmrw 8p' } });+ expect(+ screen.getByRole('option', { name: /Tomorrow at 8 PM/i })+ ).toBeTruthy();++ fireEvent.input(input, { target: { value: 'fri' } });+ expect(screen.getByRole('option', { name: /fri|Friday/i })).toBeTruthy();+});it('supports arrow-key selection and preserves the condition when editing', () => {const { onSave } = setup({initialTime: '2026-11-01T06:30:15Z',diff --git a/apps/web/src/features/reminders/primitives/create-reminder-time-options.test.ts b/apps/web/src/features/reminders/primitives/create-reminder-time-options.test.tsnew file mode 100644index 0000000000..6d200225af--- /dev/null+++ b/apps/web/src/features/reminders/primitives/create-reminder-time-options.test.ts@@ -0,0 +1,71 @@+import { createRoot, createSignal } from 'solid-js';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { createReminderTimeOptions } from './create-reminder-time-options';++describe('createReminderTimeOptions', () => {+ beforeEach(() => {+ vi.useFakeTimers();+ // Friday afternoon so "tomorrow" and weekday shorthands are unambiguous+ vi.setSystemTime(new Date('2026-10-09T15:00:00'));+ });++ afterEach(() => {+ vi.useRealTimers();+ });++ it('resolves tmrw to tomorrow morning', () => {+ createRoot((dispose) => {+ const [query] = createSignal('tmrw');+ const options = createReminderTimeOptions(query);+ const tomorrow = options().find((option) =>+ option.label.toLowerCase().includes('tomorrow')+ );+ expect(tomorrow).toBeTruthy();+ expect(tomorrow?.date.getDate()).toBe(10);+ expect(tomorrow?.date.getHours()).toBe(9);+ dispose();+ });+ });++ it('resolves tmrw 8 to tomorrow at 8am', () => {+ createRoot((dispose) => {+ const [query] = createSignal('tmrw 8');+ const options = createReminderTimeOptions(query);+ expect(options().length).toBeGreaterThan(0);+ const match = options()[0];+ expect(match.date.getDate()).toBe(10);+ expect(match.date.getHours()).toBe(8);+ expect(match.date.getMinutes()).toBe(0);+ dispose();+ });+ });++ it('resolves tmrw 8p to tomorrow at 8pm', () => {+ createRoot((dispose) => {+ const [query] = createSignal('tmrw 8p');+ const options = createReminderTimeOptions(query);+ expect(options().length).toBeGreaterThan(0);+ const match = options()[0];+ expect(match.label.toLowerCase()).toContain('8 pm');+ expect(match.date.getDate()).toBe(10);+ expect(match.date.getHours()).toBe(20);+ dispose();+ });+ });++ it('resolves weekday shorthands like fri and thu', () => {+ createRoot((dispose) => {+ for (const [queryText, expectedDay] of [+ ['fri', 5],+ ['thu', 4],+ ['mon', 1],+ ] as const) {+ const [query] = createSignal(queryText);+ const options = createReminderTimeOptions(query);+ expect(options().length).toBeGreaterThan(0);+ expect(options()[0].date.getDay()).toBe(expectedDay);+ }+ dispose();+ });+ });+});diff --git a/apps/web/src/lib/core/util/dateParser.ts b/apps/web/src/lib/core/util/dateParser.tsindex 1fafaab12b..a1bd1e7684 100644--- a/apps/web/src/lib/core/util/dateParser.ts+++ b/apps/web/src/lib/core/util/dateParser.ts@@ -20,6 +20,30 @@ const WEEKDAYS = ['saturday',];+const WEEKDAY_ABBR: Record<string, number> = {+ sun: 0,+ sunday: 0,+ mon: 1,+ monday: 1,+ mndy: 1,+ tue: 2,+ tues: 2,+ tuesday: 2,+ tu: 2,+ wed: 3,+ weds: 3,+ wednes: 3,+ wednesday: 3,+ thu: 4,+ thur: 4,+ thurs: 4,+ thursday: 4,+ fri: 5,+ friday: 5,+ sat: 6,+ saturday: 6,+};+const MONTHS = ['january','february',@@ -50,13 +74,27 @@ const MONTH_ABBR = ['dec',];+const TOMORROW_ALIASES = new Set([+ 'tomorrow',+ 'tom',+ 'tmrw',+ 'tmr',+ 'tomorow',+ 'tomoro',+ 'tmro',+]);++const YESTERDAY_ALIASES = new Set(['yesterday', 'yest', 'ystrdy', 'yday']);++const TODAY_ALIASES = new Set(['today', 'tod']);+function parseDateString(input: string): ParsedDate | null {const normalized = input.toLowerCase().trim();const today = new Date();today.setHours(0, 0, 0, 0);// Today- if (normalized === 'today' || normalized === 'tod') {+ if (TODAY_ALIASES.has(normalized)) {return {date: new Date(today),displayFormat: 'Today',@@ -65,11 +103,7 @@ function parseDateString(input: string): ParsedDate | null {}// Tomorrow- if (- normalized === 'tomorrow' ||- normalized === 'tom' ||- normalized === 'tmrw'- ) {+ if (TOMORROW_ALIASES.has(normalized)) {const tomorrow = new Date(today);tomorrow.setDate(tomorrow.getDate() + 1);return {@@ -80,7 +114,7 @@ function parseDateString(input: string): ParsedDate | null {}// Yesterday- if (normalized === 'yesterday' || normalized === 'yest') {+ if (YESTERDAY_ALIASES.has(normalized)) {const yesterday = new Date(today);yesterday.setDate(yesterday.getDate() - 1);return {@@ -113,14 +147,35 @@ function parseDateString(input: string): ParsedDate | null {};}- // Weekday names+ // Weekday names - use the abbreviation lookup for broader matching+ const weekdayIndex = WEEKDAY_ABBR[normalized];+ if (weekdayIndex !== undefined) {+ const targetDay = weekdayIndex;+ const currentDay = today.getDay();+ let daysToAdd = targetDay - currentDay;++ // If the day has passed this week or it's today, get next week's+ if (daysToAdd <= 0) {+ daysToAdd += 7;+ }++ const targetDate = new Date(today);+ targetDate.setDate(targetDate.getDate() + daysToAdd);++ return {+ date: targetDate,+ displayFormat: formatDate(targetDate),+ confidence: normalized === WEEKDAYS[weekdayIndex] ? 1 : 0.9,+ };+ }++ // Fallback: try prefix matching for weekdays (e.g., "mo" for Monday)for (let i = 0; i < WEEKDAYS.length; i++) {- if (normalized.startsWith(WEEKDAYS[i].slice(0, 3))) {+ if (WEEKDAYS[i].startsWith(normalized) && normalized.length >= 2) {const targetDay = i;const currentDay = today.getDay();let daysToAdd = targetDay - currentDay;- // If the day has passed this week, get next week'sif (daysToAdd <= 0) {daysToAdd += 7;}@@ -131,7 +186,7 @@ function parseDateString(input: string): ParsedDate | null {return {date: targetDate,displayFormat: formatDate(targetDate),- confidence: normalized === WEEKDAYS[i] ? 1 : 0.8,+ confidence: 0.8,};}}@@ -360,21 +415,27 @@ export function formatTooltipDate(date: Date): string {function _getDateSuggestions(input: string): ParsedDate[] {const suggestions: ParsedDate[] = [];const normalized = input.toLowerCase().trim();+ const today = new Date();+ today.setHours(0, 0, 0, 0);- // Always suggest today and tomorrow if they match- if ('today'.startsWith(normalized) && normalized.length > 0) {- const today = new Date();- today.setHours(0, 0, 0, 0);+ // Suggest today if query matches any alias or prefix+ const todayMatches =+ [...TODAY_ALIASES].some((alias) => alias.startsWith(normalized)) ||+ 'today'.startsWith(normalized);+ if (todayMatches && normalized.length > 0) {suggestions.push({- date: today,+ date: new Date(today),displayFormat: 'Today',confidence: 1,});}- if ('tomorrow'.startsWith(normalized) && normalized.length > 0) {- const tomorrow = new Date();- tomorrow.setHours(0, 0, 0, 0);+ // Suggest tomorrow if query matches any alias or prefix+ const tomorrowMatches =+ [...TOMORROW_ALIASES].some((alias) => alias.startsWith(normalized)) ||+ 'tomorrow'.startsWith(normalized);+ if (tomorrowMatches && normalized.length > 0) {+ const tomorrow = new Date(today);tomorrow.setDate(tomorrow.getDate() + 1);suggestions.push({date: tomorrow,@@ -383,28 +444,39 @@ function _getDateSuggestions(input: string): ParsedDate[] {});}- // Weekday suggestions- const today = new Date();+ // Weekday suggestions - check both full names and abbreviations+ const matchedWeekdays = new Set<number>();++ // Check against abbreviation lookup+ for (const [abbr, dayIndex] of Object.entries(WEEKDAY_ABBR)) {+ if (abbr.startsWith(normalized) && normalized.length > 0) {+ matchedWeekdays.add(dayIndex);+ }+ }++ // Also check prefix matching on full weekday namesfor (let i = 0; i < WEEKDAYS.length; i++) {if (WEEKDAYS[i].startsWith(normalized) && normalized.length > 1) {- const targetDay = i;- const currentDay = today.getDay();- let daysToAdd = targetDay - currentDay;+ matchedWeekdays.add(i);+ }+ }- if (daysToAdd <= 0) {- daysToAdd += 7;- }+ for (const targetDay of matchedWeekdays) {+ const currentDay = today.getDay();+ let daysToAdd = targetDay - currentDay;- const targetDate = new Date(today);- targetDate.setHours(0, 0, 0, 0);- targetDate.setDate(targetDate.getDate() + daysToAdd);-- suggestions.push({- date: targetDate,- displayFormat: formatDate(targetDate),- confidence: 0.8,- });+ if (daysToAdd <= 0) {+ daysToAdd += 7;}++ const targetDate = new Date(today);+ targetDate.setDate(targetDate.getDate() + daysToAdd);++ suggestions.push({+ date: targetDate,+ displayFormat: formatDate(targetDate),+ confidence: 0.8,+ });}// Month suggestionsdiff --git a/apps/web/src/lib/core/util/dateSearch/parseTime.ts b/apps/web/src/lib/core/util/dateSearch/parseTime.tsindex 0c80a7688f..153b9866d3 100644--- a/apps/web/src/lib/core/util/dateSearch/parseTime.ts+++ b/apps/web/src/lib/core/util/dateSearch/parseTime.ts@@ -3,8 +3,150 @@ export interface ParsedTime {minutes: number; // 0-59}+type Meridiem = 'am' | 'pm';++const MONTH_WORDS = new Set([+ 'jan',+ 'january',+ 'feb',+ 'february',+ 'mar',+ 'march',+ 'apr',+ 'april',+ 'may',+ 'jun',+ 'june',+ 'jul',+ 'july',+ 'aug',+ 'august',+ 'sep',+ 'sept',+ 'september',+ 'oct',+ 'october',+ 'nov',+ 'november',+ 'dec',+ 'december',+]);++/** Tokens that can stand alone as a date before a bare hour like "tmrw 8". */+const DATE_WORD_PREFIXES = new Set([+ 'today',+ 'tod',+ 'tomorrow',+ 'tmrw',+ 'tmr',+ 'tom',+ 'tomorow',+ 'tomoro',+ 'tmro',+ 'yesterday',+ 'yest',+ 'ystrdy',+ 'yday',+ 'sun',+ 'sunday',+ 'mon',+ 'monday',+ 'mndy',+ 'tue',+ 'tues',+ 'tuesday',+ 'tu',+ 'wed',+ 'weds',+ 'wednes',+ 'wednesday',+ 'thu',+ 'thur',+ 'thurs',+ 'thursday',+ 'fri',+ 'friday',+ 'sat',+ 'saturday',+]);++function normalizeMeridiem(raw: string): Meridiem | null {+ const value = raw.toLowerCase();+ if (value === 'a' || value === 'am') return 'am';+ if (value === 'p' || value === 'pm') return 'pm';+ return null;+}++function applyMeridiem(hours: number, meridiem: Meridiem): number | null {+ if (hours < 1 || hours > 12) return null;+ if (meridiem === 'pm' && hours !== 12) return hours + 12;+ if (meridiem === 'am' && hours === 12) return 0;+ return hours;+}++function parseHourMinute(+ hourRaw: string,+ minuteRaw: string | undefined,+ meridiemRaw: string | undefined+): ParsedTime | null {+ const hours = parseInt(hourRaw, 10);+ const minutes = parseInt(minuteRaw || '0', 10);+ if (Number.isNaN(hours) || Number.isNaN(minutes) || minutes > 59) return null;++ if (meridiemRaw) {+ const meridiem = normalizeMeridiem(meridiemRaw);+ if (!meridiem) return null;+ const converted = applyMeridiem(hours, meridiem);+ if (converted === null) return null;+ return { hours: converted, minutes };+ }++ if (hours > 23) return null;+ return { hours, minutes };+}+/**- * Parse time strings like "9am", "9 AM", "3:30pm", "14:00", "noon", "midnight"+ * Parse compact clock forms like "830p" / "1230am" into hour + minute.+ * Only used when a meridiem is present so "830" alone is not treated as a time.+ */+function parseCompactTime(+ digits: string,+ meridiemRaw: string+): ParsedTime | null {+ if (digits.length === 3) {+ return parseHourMinute(digits[0], digits.slice(1), meridiemRaw);+ }+ if (digits.length === 4) {+ return parseHourMinute(digits.slice(0, 2), digits.slice(2), meridiemRaw);+ }+ return null;+}++function isBareHourDatePrefix(rest: string): boolean {+ const tokens = rest.trim().toLowerCase().split(/\s+/).filter(Boolean);+ if (tokens.length === 0) return false;+ // "feb 17" / "17 feb" day-of-month forms must not be treated as hours+ if (tokens.some((token) => MONTH_WORDS.has(token))) return false;+ const last = tokens[tokens.length - 1]!;+ if (DATE_WORD_PREFIXES.has(last)) return true;+ // Allow short weekday prefixes while typing ("mo", "fr")+ return (+ last.length >= 2 &&+ [+ 'sunday',+ 'monday',+ 'tuesday',+ 'wednesday',+ 'thursday',+ 'friday',+ 'saturday',+ ].some((day) => day.startsWith(last))+ );+}++/**+ * Parse time strings like "9am", "9a", "8p", "3:30pm", "14:00", "noon",+ * "midnight", and date+time composites like "tmrw 8", "friday 8p".* Returns the parsed time and the remaining input with the time portion removed.*/export function parseTime(@@ -22,50 +164,65 @@ export function parseTime(return { time: { hours: 0, minutes: 0 }, rest: '' };}- // Try matching time at end of string: "tomorrow 9am", "feb 17 3:30 PM"- // Also matches standalone: "9am", "3:30pm", "14:00"- const timeAtEnd = /^(.*?)\s*(\d{1,2})(?::(\d{2}))?\s*(am|pm)\s*$/i;- const time24AtEnd = /^(.*?)\s*(\d{1,2}):(\d{2})\s*$/;-- let match = trimmed.match(timeAtEnd);+ // Compact meridiem forms first so "830p" is not misread as hour 30+ const compactAtEnd = /^(.*?)\s*(\d{3,4})\s*(a|am|p|pm)\s*$/i;+ let match = trimmed.match(compactAtEnd);if (match) {- let hours = parseInt(match[2]);- const minutes = parseInt(match[3] || '0');- const meridiem = match[4].toLowerCase();-- if (hours < 1 || hours > 12 || minutes > 59) return null;-- if (meridiem === 'pm' && hours !== 12) hours += 12;- if (meridiem === 'am' && hours === 12) hours = 0;+ const time = parseCompactTime(match[2], match[3]);+ if (time) return { time, rest: match[1].trim() };+ }- return { time: { hours, minutes }, rest: match[1].trim() };+ // Time at end with meridiem: "tomorrow 9am", "tmrw 8p", "feb 17 3:30 PM"+ // Also matches standalone: "9am", "8p", "3:30pm"+ const timeAtEnd = /^(.*?)\s*(\d{1,2})(?::(\d{2}))?\s*(a|am|p|pm)\s*$/i;+ match = trimmed.match(timeAtEnd);+ if (match) {+ const time = parseHourMinute(match[2], match[3], match[4]);+ if (time) return { time, rest: match[1].trim() };}- // 24-hour format: "14:00", "tomorrow 14:00"+ // 24-hour format with colon: "14:00", "tomorrow 14:00"+ const time24AtEnd = /^(.*?)\s*(\d{1,2}):(\d{2})\s*$/;match = trimmed.match(time24AtEnd);if (match) {- const hours = parseInt(match[2]);- const minutes = parseInt(match[3]);+ const time = parseHourMinute(match[2], match[3], undefined);+ if (time) return { time, rest: match[1].trim() };+ }- if (hours > 23 || minutes > 59) return null;+ // Bare hour at end when prefix is a relative/weekday word: "tmrw 8", "friday 9"+ const bareHourAtEnd = /^(.*?[^\d\s])\s+(\d{1,2})\s*$/;+ match = trimmed.match(bareHourAtEnd);+ if (match && isBareHourDatePrefix(match[1])) {+ const time = parseHourMinute(match[2], undefined, undefined);+ if (time && time.hours >= 1 && time.hours <= 23) {+ return { time, rest: match[1].trim() };+ }+ }- return { time: { hours, minutes }, rest: match[1].trim() };+ // Compact meridiem at start: "830p tomorrow"+ const compactAtStart = /^(\d{3,4})\s*(a|am|p|pm)\s+(.+)$/i;+ match = trimmed.match(compactAtStart);+ if (match) {+ const time = parseCompactTime(match[1], match[2]);+ if (time) return { time, rest: match[3].trim() };}- // Time at start: "9am tomorrow", "3:30 PM feb 17"- const timeAtStart = /^(\d{1,2})(?::(\d{2}))?\s*(am|pm)\s+(.+)$/i;+ // Time at start with meridiem: "9am tomorrow", "8p friday", "3:30 PM feb 17"+ const timeAtStart = /^(\d{1,2})(?::(\d{2}))?\s*(a|am|p|pm)\s+(.+)$/i;match = trimmed.match(timeAtStart);if (match) {- let hours = parseInt(match[1]);- const minutes = parseInt(match[2] || '0');- const meridiem = match[3].toLowerCase();-- if (hours < 1 || hours > 12 || minutes > 59) return null;-- if (meridiem === 'pm' && hours !== 12) hours += 12;- if (meridiem === 'am' && hours === 12) hours = 0;+ const time = parseHourMinute(match[1], match[2], match[3]);+ if (time) return { time, rest: match[4].trim() };+ }- return { time: { hours, minutes }, rest: match[4].trim() };+ // Bare hour at start with date-word suffix: "8 tmrw", "9 friday"+ const bareHourAtStart = /^(\d{1,2})\s+(.+)$/;+ match = trimmed.match(bareHourAtStart);+ if (match && isBareHourDatePrefix(match[2])) {+ const time = parseHourMinute(match[1], undefined, undefined);+ if (time && time.hours >= 1 && time.hours <= 23) {+ return { time, rest: match[2].trim() };+ }}return null;diff --git a/apps/web/src/lib/core/util/dateSearch/presets.ts b/apps/web/src/lib/core/util/dateSearch/presets.tsindex 68e93bfe1e..3ddceb6c1b 100644--- a/apps/web/src/lib/core/util/dateSearch/presets.ts+++ b/apps/web/src/lib/core/util/dateSearch/presets.ts@@ -1,4 +1,4 @@-import { addDays, addWeeks, endOfDay, endOfWeek } from 'date-fns';+import { addDays, addWeeks, endOfDay, endOfWeek, nextDay } from 'date-fns';interface DatePreset {id: string;@@ -6,7 +6,15 @@ interface DatePreset {shortLabel?: string;keywords: string[];getDate: (baseDate?: Date) => Date;- category?: 'quick' | 'week' | 'month' | 'year';+ category?: 'quick' | 'week' | 'month' | 'year' | 'weekday';+}++function getNextWeekday(weekday: 0 | 1 | 2 | 3 | 4 | 5 | 6, baseDate: Date) {+ const today = baseDate.getDay();+ if (today === weekday) {+ return addDays(endOfDay(baseDate), 7);+ }+ return endOfDay(nextDay(baseDate, weekday));}const DATE_PRESETS: DatePreset[] = [@@ -14,7 +22,7 @@ const DATE_PRESETS: DatePreset[] = [id: 'today',label: 'Today',shortLabel: 'Today',- keywords: ['today', 'end', 'end of day', 'eod'],+ keywords: ['today', 'tod', 'end', 'end of day', 'eod'],getDate: (baseDate = new Date()) => endOfDay(baseDate),category: 'quick',},@@ -22,7 +30,7 @@ const DATE_PRESETS: DatePreset[] = [id: 'tomorrow',label: 'Tomorrow',shortLabel: 'Tom',- keywords: ['tomorrow', 'tmrw', 'tom'],+ keywords: ['tomorrow', 'tmrw', 'tmr', 'tom', 'tomorow', 'tomoro', 'tmro'],getDate: (baseDate = new Date()) => addDays(endOfDay(baseDate), 1),category: 'quick',},@@ -30,7 +38,7 @@ const DATE_PRESETS: DatePreset[] = [id: 'yesterday',label: 'Yesterday',shortLabel: 'Yest',- keywords: ['yesterday', 'yest'],+ keywords: ['yesterday', 'yest', 'ystrdy', 'yday'],getDate: (baseDate = new Date()) => addDays(endOfDay(baseDate), -1),category: 'quick',},@@ -46,7 +54,7 @@ const DATE_PRESETS: DatePreset[] = [id: 'end-of-week',label: 'End of week',shortLabel: 'EOW',- keywords: ['end of week', 'eow', 'weekend', 'friday'],+ keywords: ['end of week', 'eow', 'weekend'],getDate: (baseDate = new Date()) =>endOfWeek(baseDate, { weekStartsOn: 1 }),category: 'week',@@ -55,7 +63,7 @@ const DATE_PRESETS: DatePreset[] = [id: 'in-1-week',label: 'In 1 week',shortLabel: '1w',- keywords: ['1 week', '1w', 'one week', 'week'],+ keywords: ['1 week', '1w', 'one week', 'week', 'next week', 'nw'],getDate: (baseDate = new Date()) => addWeeks(baseDate, 1),category: 'week',},@@ -67,13 +75,71 @@ const DATE_PRESETS: DatePreset[] = [getDate: (baseDate = new Date()) => addWeeks(baseDate, 2),category: 'week',},+ {+ id: 'monday',+ label: 'Monday',+ shortLabel: 'Mon',+ keywords: ['monday', 'mon', 'mndy'],+ getDate: (baseDate = new Date()) => getNextWeekday(1, baseDate),+ category: 'weekday',+ },+ {+ id: 'tuesday',+ label: 'Tuesday',+ shortLabel: 'Tue',+ keywords: ['tuesday', 'tue', 'tues', 'tu'],+ getDate: (baseDate = new Date()) => getNextWeekday(2, baseDate),+ category: 'weekday',+ },+ {+ id: 'wednesday',+ label: 'Wednesday',+ shortLabel: 'Wed',+ keywords: ['wednesday', 'wed', 'weds', 'wednes'],+ getDate: (baseDate = new Date()) => getNextWeekday(3, baseDate),+ category: 'weekday',+ },+ {+ id: 'thursday',+ label: 'Thursday',+ shortLabel: 'Thu',+ keywords: ['thursday', 'thu', 'thur', 'thurs'],+ getDate: (baseDate = new Date()) => getNextWeekday(4, baseDate),+ category: 'weekday',+ },+ {+ id: 'friday',+ label: 'Friday',+ shortLabel: 'Fri',+ keywords: ['friday', 'fri'],+ getDate: (baseDate = new Date()) => getNextWeekday(5, baseDate),+ category: 'weekday',+ },+ {+ id: 'saturday',+ label: 'Saturday',+ shortLabel: 'Sat',+ keywords: ['saturday', 'sat'],+ getDate: (baseDate = new Date()) => getNextWeekday(6, baseDate),+ category: 'weekday',+ },+ {+ id: 'sunday',+ label: 'Sunday',+ shortLabel: 'Sun',+ keywords: ['sunday', 'sun'],+ getDate: (baseDate = new Date()) => getNextWeekday(0, baseDate),+ category: 'weekday',+ },];+export type { DatePreset };+export function searchPresets(query: string): DatePreset[] {const normalizedQuery = query.toLowerCase().trim();if (!normalizedQuery) {- return DATE_PRESETS;+ return DATE_PRESETS.filter((p) => p.category !== 'weekday');}return DATE_PRESETS.filter((preset) => {@@ -85,8 +151,10 @@ export function searchPresets(query: string): DatePreset[] {return true;}- return preset.keywords.some((keyword) =>- keyword.toLowerCase().includes(normalizedQuery)+ return preset.keywords.some(+ (keyword) =>+ keyword.toLowerCase().includes(normalizedQuery) ||+ normalizedQuery.includes(keyword.toLowerCase()));});}diff --git a/apps/web/src/lib/core/util/dateSearch/useDateSearch.test.ts b/apps/web/src/lib/core/util/dateSearch/useDateSearch.test.tsindex fb91f744f9..f6ef4f8617 100644--- a/apps/web/src/lib/core/util/dateSearch/useDateSearch.test.ts+++ b/apps/web/src/lib/core/util/dateSearch/useDateSearch.test.ts@@ -99,6 +99,30 @@ describe('parseNaturalDate', () => {expect(fri?.getDate()).toBe(21);});+ it('should parse day of week abbreviations', () => {+ // Base date is Saturday June 15, 2024+ // Test common abbreviations+ expect(parseNaturalDate('mon', baseDate)?.getDate()).toBe(17);+ expect(parseNaturalDate('tue', baseDate)?.getDate()).toBe(18);+ expect(parseNaturalDate('tues', baseDate)?.getDate()).toBe(18);+ expect(parseNaturalDate('wed', baseDate)?.getDate()).toBe(19);+ expect(parseNaturalDate('weds', baseDate)?.getDate()).toBe(19);+ expect(parseNaturalDate('thu', baseDate)?.getDate()).toBe(20);+ expect(parseNaturalDate('thur', baseDate)?.getDate()).toBe(20);+ expect(parseNaturalDate('thurs', baseDate)?.getDate()).toBe(20);+ expect(parseNaturalDate('fri', baseDate)?.getDate()).toBe(21);+ expect(parseNaturalDate('sat', baseDate)?.getDate()).toBe(22);+ expect(parseNaturalDate('sun', baseDate)?.getDate()).toBe(16);+ });++ it('should be case insensitive for day abbreviations', () => {+ // Base date is Saturday June 15, 2024+ expect(parseNaturalDate('MON', baseDate)?.getDate()).toBe(17);+ expect(parseNaturalDate('Mon', baseDate)?.getDate()).toBe(17);+ expect(parseNaturalDate('THU', baseDate)?.getDate()).toBe(20);+ expect(parseNaturalDate('FRI', baseDate)?.getDate()).toBe(21);+ });+it('should handle case insensitivity', () => {const date1 = parseNaturalDate('FEB 17', baseDate);const date2 = parseNaturalDate('feb 17', baseDate);@@ -256,6 +280,112 @@ describe('useDateSearch', () => {});});+ it('should find tomorrow with shorthand "tmrw"', () => {+ createRoot((dispose) => {+ const [query] = createSignal('tmrw');+ const options = useDateSearch({ query });++ const result = options();+ const tomorrowOption = result.find((opt) =>+ opt.displayText.toLowerCase().includes('tomorrow')+ );+ expect(tomorrowOption).toBeTruthy();++ dispose();+ });+ });++ it('should resolve "tmrw 8" and "tmrw 8p" with times', () => {+ createRoot((dispose) => {+ const baseDate = new Date('2024-06-15T10:00:00');++ const morning = useDateSearch({+ query: () => 'tmrw 8',+ baseDate,+ })();+ const morningOption = morning.find((opt) =>+ opt.displayText.toLowerCase().includes('tomorrow')+ );+ expect(morningOption).toBeTruthy();+ expect(morningOption?.date.getDate()).toBe(16);+ expect(morningOption?.date.getHours()).toBe(8);++ const evening = useDateSearch({+ query: () => 'tmrw 8p',+ baseDate,+ })();+ const eveningOption = evening.find((opt) =>+ opt.displayText.toLowerCase().includes('tomorrow')+ );+ expect(eveningOption).toBeTruthy();+ expect(eveningOption?.displayText).toContain('at 8 PM');+ expect(eveningOption?.date.getHours()).toBe(20);++ dispose();+ });+ });++ it('should find tomorrow with various aliases', () => {+ createRoot((dispose) => {+ const aliases = ['tmrw', 'tmr', 'tom'];+ aliases.forEach((alias) => {+ const [query] = createSignal(alias);+ const options = useDateSearch({ query });++ const result = options();+ const tomorrowOption = result.find((opt) =>+ opt.displayText.toLowerCase().includes('tomorrow')+ );+ expect(tomorrowOption).toBeTruthy();+ });++ dispose();+ });+ });++ it('should find weekday presets by abbreviation', () => {+ createRoot((dispose) => {+ const [query] = createSignal('mon');+ const options = useDateSearch({ query });++ const result = options();+ const mondayOption = result.find((opt) =>+ opt.displayText.toLowerCase().includes('monday')+ );+ expect(mondayOption).toBeTruthy();++ dispose();+ });+ });++ it('should find weekday presets by various abbreviations', () => {+ createRoot((dispose) => {+ const testCases = [+ { abbr: 'thu', day: 'thursday' },+ { abbr: 'thur', day: 'thursday' },+ { abbr: 'thurs', day: 'thursday' },+ { abbr: 'fri', day: 'friday' },+ { abbr: 'wed', day: 'wednesday' },+ { abbr: 'weds', day: 'wednesday' },+ { abbr: 'tue', day: 'tuesday' },+ { abbr: 'tues', day: 'tuesday' },+ ];++ testCases.forEach(({ abbr, day }) => {+ const [query] = createSignal(abbr);+ const options = useDateSearch({ query });++ const result = options();+ const dayOption = result.find((opt) =>+ opt.displayText.toLowerCase().includes(day)+ );+ expect(dayOption).toBeTruthy();+ });++ dispose();+ });+ });+it('should handle relative date queries', () => {createRoot((dispose) => {const [query] = createSignal('week');@@ -405,6 +535,59 @@ describe('parseTime', () => {expect(result2?.rest).toBe('');});+ it('should parse short meridiem forms like 8p and 8a', () => {+ expect(parseTime('8p')).toEqual({+ time: { hours: 20, minutes: 0 },+ rest: '',+ });+ expect(parseTime('8a')).toEqual({+ time: { hours: 8, minutes: 0 },+ rest: '',+ });+ expect(parseTime('12p')).toEqual({+ time: { hours: 12, minutes: 0 },+ rest: '',+ });+ expect(parseTime('12a')).toEqual({+ time: { hours: 0, minutes: 0 },+ rest: '',+ });+ expect(parseTime('3:30p')).toEqual({+ time: { hours: 15, minutes: 30 },+ rest: '',+ });+ });++ it('should parse compact times like 830p', () => {+ expect(parseTime('830p')).toEqual({+ time: { hours: 20, minutes: 30 },+ rest: '',+ });+ expect(parseTime('1230am')).toEqual({+ time: { hours: 0, minutes: 30 },+ rest: '',+ });+ });++ it('should parse bare hours after a date word like tmrw 8', () => {+ expect(parseTime('tmrw 8')).toEqual({+ time: { hours: 8, minutes: 0 },+ rest: 'tmrw',+ });+ expect(parseTime('tmrw 8p')).toEqual({+ time: { hours: 20, minutes: 0 },+ rest: 'tmrw',+ });+ expect(parseTime('friday 9')).toEqual({+ time: { hours: 9, minutes: 0 },+ rest: 'friday',+ });+ expect(parseTime('8 tmrw')).toEqual({+ time: { hours: 8, minutes: 0 },+ rest: 'tmrw',+ });+ });+it('should parse times with spaces before meridiem', () => {const result = parseTime('9 AM');expect(result).toBeTruthy();diff --git a/apps/web/src/lib/core/util/dateSearch/useDateSearch.ts b/apps/web/src/lib/core/util/dateSearch/useDateSearch.tsindex e53021aa60..b63ee72ce5 100644--- a/apps/web/src/lib/core/util/dateSearch/useDateSearch.ts+++ b/apps/web/src/lib/core/util/dateSearch/useDateSearch.ts@@ -120,11 +120,42 @@ function parseNaturalDate('saturday',];- const dayIndex = daysOfWeek.findIndex(- (day) => lowerInput === day || lowerInput === day.slice(0, 3)- );+ // Map of common abbreviations and misspellings to day index+ const dayAbbreviations: Record<string, number> = {+ sun: 0,+ sunday: 0,+ mon: 1,+ monday: 1,+ mndy: 1,+ tue: 2,+ tues: 2,+ tuesday: 2,+ tu: 2,+ wed: 3,+ weds: 3,+ wednes: 3,+ wednesday: 3,+ thu: 4,+ thur: 4,+ thurs: 4,+ thursday: 4,+ fri: 5,+ friday: 5,+ sat: 6,+ saturday: 6,+ };++ // Check against the abbreviation map first+ let dayIndex = dayAbbreviations[lowerInput];++ // Fallback to prefix matching if no exact match+ if (dayIndex === undefined) {+ dayIndex = daysOfWeek.findIndex(+ (day) => day.startsWith(lowerInput) && lowerInput.length >= 2+ );+ }- if (dayIndex !== -1) {+ if (dayIndex !== undefined && dayIndex !== -1) {const currentDay = now.getDay();let daysToAdd = dayIndex - currentDay;@@ -143,13 +174,33 @@ function parseNaturalDate(/*** Score how well an option matches the query*/-function scoreMatch(option: DateOption, query: string): number {+function scoreMatch(+ option: DateOption,+ query: string,+ keywords?: string[]+): number {const lowerQuery = query.toLowerCase();const lowerDisplay = option.displayText.toLowerCase();if (lowerDisplay === lowerQuery) return 100;if (lowerDisplay.startsWith(lowerQuery)) return 90;if (lowerDisplay.includes(lowerQuery)) return 70;++ // Keyword matches: exact, prefix while typing, or leading token ("tmrw 8")+ if (keywords) {+ const queryTokens = lowerQuery.split(/\s+/).filter(Boolean);+ const queryMatchesKeyword = keywords.some((kw) => {+ const lowerKw = kw.toLowerCase();+ return (+ lowerKw === lowerQuery ||+ lowerKw.startsWith(lowerQuery) ||+ lowerQuery.startsWith(`${lowerKw} `) ||+ queryTokens.includes(lowerKw)+ );+ });+ if (queryMatchesKeyword) return 85;+ }+if (option.secondaryText) {const lowerSecondary = option.secondaryText.toLowerCase();if (lowerSecondary.includes(lowerQuery)) return 50;@@ -338,7 +389,7 @@ export function useDateSearch(params: {score: 0,};- option.score = scoreMatch(option, presetQuery);+ option.score = scoreMatch(option, presetQuery, preset.keywords);if (option.score > 0) {options.push(option);