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:
@@ -32,15 +32,21 @@ export function SaleCountdown({ hasActiveSale, maxSalePercentage = 5, saleEndDat
|
||||
|
||||
if (saleEndDate) {
|
||||
// Use the sale end date from admin
|
||||
targetDate = new Date(saleEndDate);
|
||||
|
||||
// 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);
|
||||
|
||||
console.log('Sale end date from DB:', saleEndDate);
|
||||
console.log('Parsed target date:', targetDate);
|
||||
console.log('Current time:', now);
|
||||
try {
|
||||
const saleDate = new Date(saleEndDate);
|
||||
// Always set to end of day for proper countdown display
|
||||
targetDate = new Date(saleDate.getFullYear(), saleDate.getMonth(), saleDate.getDate(), 23, 59, 59, 999);
|
||||
} catch (error) {
|
||||
console.error('Error parsing sale end date:', error);
|
||||
// Fallback to next Sunday if date parsing fails
|
||||
const nextSunday = new Date();
|
||||
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 {
|
||||
// Fallback to next Sunday at 23:59:59
|
||||
const nextSunday = new Date();
|
||||
@@ -53,8 +59,6 @@ export function SaleCountdown({ hasActiveSale, maxSalePercentage = 5, saleEndDat
|
||||
}
|
||||
|
||||
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) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user