MCPcopy
hub / github.com/callumalpass/tasknotes / parseDateAsLocal

Function parseDateAsLocal

src/utils/dateUtils.ts:403–430  ·  view source on GitHub ↗
(dateString: string)

Source from the content-addressed store, hash-verified

401 * creates a date at midnight local time to ensure consistent behavior.
402 */
403export function parseDateAsLocal(dateString: string): Date {
404 if (!dateString) {
405 throw new Error("Date string cannot be empty");
406 }
407
408 const trimmed = dateString.trim();
409
410 // For date-only strings, create a date at midnight local time
411 const dateMatch = trimmed.match(/^(\d{4})-(\d{2})-(\d{2})$/);
412 if (dateMatch) {
413 const [, year, month, day] = dateMatch;
414 const parsed = new Date(parseInt(year, 10), parseInt(month, 10) - 1, parseInt(day, 10));
415
416 if (
417 !isValid(parsed) ||
418 parsed.getFullYear() !== parseInt(year, 10) ||
419 parsed.getMonth() !== parseInt(month, 10) - 1 ||
420 parsed.getDate() !== parseInt(day, 10)
421 ) {
422 throw new Error(`Invalid date values: ${dateString}`);
423 }
424
425 return parsed;
426 }
427
428 // For datetime strings, use the shared local-date parser
429 return parseDateToLocalInternal(dateString);
430}
431
432/**
433 * Normalize a date string to YYYY-MM-DD format for storage/comparison

Callers 5

onOpenMethod · 0.90
createRecurringCalendarFunction · 0.90
isTodayFunction · 0.85
isTodayTimeAwareFunction · 0.85

Calls 2

parseDateToLocalInternalFunction · 0.85
getDateMethod · 0.65

Tested by

no test coverage detected