Merge pull request #18 from stevedylandev/fix/pubdate-error-handling 803abbea
fix: handled erronous 2400 time
Steve Simkins · 2025-12-11 19:49 1 file(s) · +34 −1
src/lib/feed-operations.ts +34 −1
436 436
}
437 437
438 438
/**
439 +
 * Normalizes date strings to handle problematic formats like "24:00:00"
440 +
 * which causes errors in WebKit browsers
441 +
 */
442 +
function normalizeDateString(dateString: string): string {
443 +
	if (!dateString || typeof dateString !== 'string') return dateString;
444 +
	
445 +
	// Handle the 24:00:00 time format by converting it to 00:00:00 of the next day
446 +
	if (dateString.includes('24:00:00')) {
447 +
		// Replace 24:00:00 with 00:00:00
448 +
		const normalizedDate = dateString.replace(/24:00:00/, '00:00:00');
449 +
		
450 +
		try {
451 +
			// Parse the normalized date and add one day
452 +
			const tempDate = new Date(normalizedDate);
453 +
			if (!isNaN(tempDate.getTime())) {
454 +
				tempDate.setDate(tempDate.getDate() + 1);
455 +
				return tempDate.toISOString();
456 +
			}
457 +
		} catch {
458 +
			// If parsing fails, continue with the original string replacement
459 +
		}
460 +
		
461 +
		return normalizedDate;
462 +
	}
463 +
	
464 +
	return dateString;
465 +
}
466 +
467 +
/**
439 468
 * Extracts published date from RSS or Atom post entry
440 469
 */
441 470
export function extractPostDate(post: any, isAtom?: boolean): string {
453 482
		if (!dateValue) {
454 483
			return new Date().toISOString(); // Use current date if no date found
455 484
		}
456 -
		const parsedDate = new Date(dateValue);
485 +
		
486 +
		// Normalize the date string to handle problematic formats
487 +
		const normalizedDateValue = normalizeDateString(String(dateValue));
488 +
		
489 +
		const parsedDate = new Date(normalizedDateValue);
457 490
		// Check if date is valid
458 491
		if (isNaN(parsedDate.getTime())) {
459 492
			return new Date().toISOString();