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

Function formatTimestampForDisplay

src/utils/dateUtils.ts:828–855  ·  view source on GitHub ↗
(
	timestampString: string,
	formatString?: string,
	timeFormat: "12" | "24" = "24"
)

Source from the content-addressed store, hash-verified

826 * @param timeFormat - The user's time format preference ('12' or '24')
827 */
828export 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

Callers 2

createMetadataSectionMethod · 0.90
dateUtils.test.tsFile · 0.90

Calls 2

parseTimestampFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected