(dateString: string)
| 871 | * Extract just the date part from a date or datetime string |
| 872 | */ |
| 873 | export 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 |
no test coverage detected