From ab0721881af053654647ec9e4aa397c2ed415c77 Mon Sep 17 00:00:00 2001 From: Chop <28534054+RChopin@users.noreply.github.com> Date: Thu, 19 Jun 2025 23:29:17 +0200 Subject: [PATCH] feat: Add test script for date formatting functions --- test-date-formatting.js | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test-date-formatting.js diff --git a/test-date-formatting.js b/test-date-formatting.js new file mode 100644 index 0000000..0a7703d --- /dev/null +++ b/test-date-formatting.js @@ -0,0 +1,56 @@ +// Test script to verify date formatting +import { formatDate, formatDateForInput } from "./src/lib/utils.js"; + +console.log("Testing Date Formatting Functions...\n"); + +// Test cases +const testDates = [ + "2024-01-15", + "2024-12-25T14:30:00", + "2024-06-01", + new Date("2024-03-10"), + new Date("2024-09-22T09:15:30"), + null, + undefined, + "invalid-date", +]; + +console.log("formatDate() tests (DD.MM.YYYY format):"); +testDates.forEach((date, index) => { + try { + const result = formatDate(date); + console.log(`${index + 1}. ${JSON.stringify(date)} -> "${result}"`); + } catch (error) { + console.log( + `${index + 1}. ${JSON.stringify(date)} -> ERROR: ${error.message}` + ); + } +}); + +console.log("\nformatDate() with time tests (DD.MM.YYYY HH:MM format):"); +testDates.forEach((date, index) => { + try { + const result = formatDate(date, { includeTime: true }); + console.log(`${index + 1}. ${JSON.stringify(date)} -> "${result}"`); + } catch (error) { + console.log( + `${index + 1}. ${JSON.stringify(date)} -> ERROR: ${error.message}` + ); + } +}); + +console.log( + "\nformatDateForInput() tests (YYYY-MM-DD format for HTML inputs):" +); +testDates.forEach((date, index) => { + try { + const result = formatDateForInput(date); + console.log(`${index + 1}. ${JSON.stringify(date)} -> "${result}"`); + } catch (error) { + console.log( + `${index + 1}. ${JSON.stringify(date)} -> ERROR: ${error.message}` + ); + } +}); + +console.log("\nDate formatting verification complete!");