( timestampString: string, formatString?: string, timeFormat: "12" | "24" = "24" )
| 826 | * @param timeFormat - The user's time format preference ('12' or '24') |
| 827 | */ |
| 828 | export function formatTimestampForDisplay( |
| 829 | timestampString: string, |
| 830 | formatString?: string, |
| 831 | timeFormat: "12" | "24" = "24" |
| 832 | ): string { |
| 833 | if (!timestampString) { |
| 834 | return timestampString; |
| 835 | } |
| 836 | |
| 837 | try { |
| 838 | const parsed = parseTimestamp(timestampString); |
| 839 | if (isValid(parsed)) { |
| 840 | // Use custom format if provided, otherwise use time format preference |
| 841 | const finalFormat = |
| 842 | formatString || (timeFormat === "12" ? "MMM d, yyyy h:mm a" : "MMM d, yyyy HH:mm"); |
| 843 | return format(parsed, finalFormat); |
| 844 | } |
| 845 | return timestampString; |
| 846 | } catch (error) { |
| 847 | tasknotesLogger.error("Error formatting timestamp for display:", { |
| 848 | category: "validation", |
| 849 | operation: "formatting-timestamp-display", |
| 850 | details: { timestampString }, |
| 851 | error: error, |
| 852 | }); |
| 853 | return timestampString; // Return original if formatting fails |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | // ========================================== |
| 858 | // TIME-AWARE DATE UTILITIES |
no test coverage detected