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

Function getDatePart

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

Source from the content-addressed store, hash-verified

871 * Extract just the date part from a date or datetime string
872 */
873export function getDatePart(dateString: string): string {
874 if (!dateString) return "";
875
876 try {
877 // If it's already a date-only string (YYYY-MM-DD), return as-is
878 if (/^\d{4}-\d{2}-\d{2}$/.test(dateString)) {
879 return dateString;
880 }
881
882 // For datetime strings, extract just the date part
883 const tIndex = dateString.indexOf("T");
884 if (tIndex > -1) {
885 return dateString.substring(0, tIndex);
886 }
887
888 // For other formats, parse and format using UTC anchor for consistency
889 const parsed = parseDateToUTC(dateString);
890 return formatDateForStorage(parsed);
891 } catch (error) {
892 tasknotesLogger.error("Error extracting date part:", {
893 category: "validation",
894 operation: "extracting-date-part",
895 details: { dateString },
896 error: error,
897 });
898 return dateString;
899 }
900}
901
902/**
903 * Extract just the time part from a datetime string, returns null if no time

Callers 15

renderSuggestionMethod · 0.90
isOnOrBeforeMethod · 0.90
isOnOrAfterMethod · 0.90
isEqualDateMethod · 0.90
normalizeDateValueMethod · 0.90
getTasksForDateMethod · 0.90

Calls 3

parseDateToUTCFunction · 0.85
formatDateForStorageFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected