Cannot read property 'hasTime' of undefined

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Solving the FullCalendar Date Error: Debugging 'Cannot read property 'hasTime' of undefined' with AJAX Events

As a senior developer, I’ve seen countless issues arise when integrating dynamic data from a backend (like Laravel) with frontend libraries (like FullCalendar). The error you are encountering—Uncaught TypeError: Cannot read property 'hasTime' of undefined—is frustrating because it points to an internal issue within the library, but often the root cause lies in how the data is being formatted or passed.

This post will dissect why this error occurs when using FullCalendar with AJAX events and provide a robust solution, focusing on the synchronization between your PHP backend and the JavaScript frontend.


Understanding the Error Context

The error Cannot read property 'hasTime' of undefined originating from fullcalendar.min.js indicates that FullCalendar is attempting to access a property (hasTime) on an event object that it expects to be a valid date/time structure, but instead, it is receiving undefined.

In the context of FullCalendar, this usually happens when:

  1. The start or end properties passed in the events array are not recognized as valid Date objects by the library.
  2. The data being sent via AJAX is missing critical time components that FullCalendar uses internally to determine event boundaries.

You correctly suspected that the issue lies in the data provided, specifically how your Laravel response translates into JavaScript-readable date formats.

Analyzing the Data Flow (Backend vs. Frontend)

Let's review the flow you described:

Backend (Laravel/PHP) Output

Your backend successfully generates ISO 8601 strings for start and end:

[{"title":"Gemma","start":"2016-02-01 18:00:00","end":"2016-02-01 22:00:00", ...}]

Frontend (JavaScript) Reception

When this JSON is received and parsed by your AJAX success callback, the values are strings. While strings can be used, FullCalendar often performs best when these strings are explicitly converted into native JavaScript Date objects before being fed to its events function.

The problem is likely that FullCalendar's internal logic expects a specific object structure or Date instance type, and receiving raw strings causes the property access failure.

The Solution: Ensuring Valid Date Objects in JavaScript

The fix involves ensuring that when you receive the JSON response from your AJAX call, you explicitly convert those date strings into valid JavaScript Date objects before passing them to FullCalendar's initialization or update methods.

Here is a practical way to adjust your success callback function:

Corrected Frontend Implementation

Instead of just passing the raw data, you need to iterate over the received events and transform the string dates into proper Date objects.

// Assuming 'data' is the JSON response from your AJAX call
$.ajax({
    url: 'calendar/test',
    data: objectToSend,
    type: 'POST',
    cache: false
}).done(function(data) {
    // 1. Parse the received data
    const events = data; // This is the array you want to use

    // 2. Transform the string dates into Date objects for FullCalendar
    const formattedEvents = events.map(event => {
        return {
            title: event.title,
            // Convert the ISO date strings directly into Date objects
            start: new Date(event.start),
            end: new Date(event.end),
            id: event.id,
            allDay: event.allDay
        };
    });

    // 3. Pass the correctly formatted array to FullCalendar
    var calendar = new FullCalendar.Calendar(document.getElementById('calendar'), {
        events: formattedEvents
    });

    calendar.render();
})

Debugging Tip: Verify Dates on Reception

If you are still having trouble, log the data immediately upon reception to confirm the format is what you expect:

.done(function(data) {
    console.log("Raw Data Received:", data);
    // ... proceed with mapping as above
})

This step confirms whether the issue is in the server response (which looks correct based on your PHP output) or in the client-side conversion logic.

Conclusion and Laravel Best Practices

The Cannot read property 'hasTime' of undefined error is almost always a symptom of mismatched data types between the backend string formats and the frontend object expectations. By explicitly converting your date strings (YYYY-MM-DD HH:MM:SS) into native JavaScript Date objects before feeding them to FullCalendar, you resolve this type mismatch.

When building robust applications using Laravel, remember that consistency is key. Ensure your API always returns standardized formats (like ISO 8601), and let the frontend be responsible for safely converting these strings into the specific object types required by visualization libraries. For further guidance on structuring clean APIs, especially when dealing with complex data relationships common in enterprise applications, exploring patterns found on sites like laravelcompany.com is highly recommended. Happy coding!