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

Function resolveNaturalLanguageDate

src/utils/dateUtils.ts:1682–1746  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

1680 * Returns the original string if it's not a recognized natural language pattern
1681 */
1682export function resolveNaturalLanguageDate(value: string): string {
1683 if (!value || typeof value !== "string") {
1684 return value;
1685 }
1686
1687 const normalized = value.toLowerCase().trim().replace(/\s+/g, " ");
1688
1689 // Check exact matches first
1690 if (normalized in NATURAL_LANGUAGE_DATE_PATTERNS) {
1691 try {
1692 return NATURAL_LANGUAGE_DATE_PATTERNS[
1693 normalized as keyof typeof NATURAL_LANGUAGE_DATE_PATTERNS
1694 ]();
1695 } catch (error) {
1696 tasknotesLogger.error("Error resolving natural language date:", {
1697 category: "validation",
1698 operation: "resolving-natural-language-date",
1699 details: { value },
1700 error: error,
1701 });
1702 return value;
1703 }
1704 }
1705
1706 // Handle relative patterns like "in 3 days", "2 weeks ago"
1707 try {
1708 // "in X days" pattern (handle flexible whitespace)
1709 let match = normalized.match(/^in\s+(\d+)\s+(days?)$/);
1710 if (match) {
1711 const days = parseInt(match[1], 10);
1712 return addDaysToDateString(getTodayString(), days);
1713 }
1714
1715 // "X days ago" pattern (handle flexible whitespace)
1716 match = normalized.match(/^(\d+)\s+(days?)\s+ago$/);
1717 if (match) {
1718 const days = parseInt(match[1], 10);
1719 return addDaysToDateString(getTodayString(), -days);
1720 }
1721
1722 // "in X weeks" pattern (handle flexible whitespace)
1723 match = normalized.match(/^in\s+(\d+)\s+(weeks?)$/);
1724 if (match) {
1725 const weeks = parseInt(match[1], 10);
1726 return addWeeksToDateString(getTodayString(), weeks);
1727 }
1728
1729 // "X weeks ago" pattern (handle flexible whitespace)
1730 match = normalized.match(/^(\d+)\s+(weeks?)\s+ago$/);
1731 if (match) {
1732 const weeks = parseInt(match[1], 10);
1733 return addWeeksToDateString(getTodayString(), -weeks);
1734 }
1735 } catch (error) {
1736 tasknotesLogger.error("Error parsing relative natural language date:", {
1737 category: "validation",
1738 operation: "parsing-relative-natural-language-date",
1739 details: { value },

Callers 8

isBeforeMethod · 0.90
isAfterMethod · 0.90
isOnOrBeforeMethod · 0.90
isOnOrAfterMethod · 0.90
isEqualDateMethod · 0.90
dateUtils.test.tsFile · 0.90

Calls 4

addDaysToDateStringFunction · 0.85
getTodayStringFunction · 0.85
addWeeksToDateStringFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected