← Back to Demo Hub
Test #14Data Handling

Invalid Date Parsing

Parsing a malformed date string without validation, resulting in Invalid Date.

📋 Demo Instructions

  1. Click the "Trigger Error" button below
  2. Open browser console (F12) to see the error
  3. Wait 5-10 seconds for the error to be captured
  4. Go to Dashboard → Performance Monitoring
  5. Click "Fix with Carla" on the error
  6. Review the generated PR
🌍 Real-World Scenario
API returns date in unexpected format (DD/MM/YYYY instead of ISO), or contains invalid values. The Date constructor doesn't throw an error but creates an Invalid Date object, causing NaN in calculations and broken UI displays.
✅ Expected Fix
Validate date strings before parsing, check if resulting Date is valid using isNaN(date.getTime()), or use a date parsing library like date-fns.
Fix Confidence:MEDIUM

💻 Buggy Code

// Buggy Code
const apiDate = '2024-13-45'; // Invalid date from API
const date = new Date(apiDate);
const daysAgo = Math.floor((Date.now() - date.getTime()) / 86400000);

console.log(daysAgo); // NaN - causes display issues
// No validation - Invalid Date silently breaks calculations

🔴 Error Log

Waiting for error to be triggered...