feat: Add test script for date formatting functions
This commit is contained in:
56
test-date-formatting.js
Normal file
56
test-date-formatting.js
Normal file
@@ -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!");
|
||||||
Reference in New Issue
Block a user