Add error handling for date parsing and remove debug logs

- Added try-catch for sale end date parsing
- Removed console.log debug statements
- Fallback to Sunday countdown if date parsing fails
This commit is contained in:
DaX
2025-07-11 12:41:04 +02:00
parent 04b7ab9b55
commit 34e9885a29

View File

@@ -32,15 +32,21 @@ export function SaleCountdown({ hasActiveSale, maxSalePercentage = 5, saleEndDat
if (saleEndDate) { if (saleEndDate) {
// Use the sale end date from admin // Use the sale end date from admin
targetDate = new Date(saleEndDate); try {
const saleDate = new Date(saleEndDate);
// Always set to end of day for proper countdown display // Always set to end of day for proper countdown display
const saleDate = new Date(saleEndDate); targetDate = new Date(saleDate.getFullYear(), saleDate.getMonth(), saleDate.getDate(), 23, 59, 59, 999);
targetDate = new Date(saleDate.getFullYear(), saleDate.getMonth(), saleDate.getDate(), 23, 59, 59, 999); } catch (error) {
console.error('Error parsing sale end date:', error);
console.log('Sale end date from DB:', saleEndDate); // Fallback to next Sunday if date parsing fails
console.log('Parsed target date:', targetDate); const nextSunday = new Date();
console.log('Current time:', now); const daysUntilSunday = (7 - now.getDay()) % 7;
const targetDay = daysUntilSunday === 0 ? 7 : daysUntilSunday;
nextSunday.setDate(now.getDate() + targetDay);
nextSunday.setHours(23, 59, 59, 999);
targetDate = nextSunday;
}
} else { } else {
// Fallback to next Sunday at 23:59:59 // Fallback to next Sunday at 23:59:59
const nextSunday = new Date(); const nextSunday = new Date();
@@ -53,8 +59,6 @@ export function SaleCountdown({ hasActiveSale, maxSalePercentage = 5, saleEndDat
} }
const difference = targetDate.getTime() - now.getTime(); const difference = targetDate.getTime() - now.getTime();
console.log('Time difference (ms):', difference);
console.log('Days:', Math.floor(difference / (1000 * 60 * 60 * 24)));
if (difference > 0) { if (difference > 0) {
return { return {