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!");