Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FullCalendar - eventDrop UTC Date

I've set up this demo of FullCalendar:

http://jsfiddle.net/k5de79b3/

           eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {
                var eventData = {};
                eventData.event_id = event.id;
                eventData.start = event.start.toDate();

                var year = eventData.start.getUTCFullYear();
                var month = eventData.start.getUTCMonth() + 1;
                var day = eventData.start.getUTCDate();
                var hours = eventData.start.getUTCHours();
                var minutes = eventData.start.getUTCMinutes();
                var seconds = eventData.start.getUTCSeconds();
                if(month < 10){ month = '0' + month; }
                if(day < 10){ day = '0' + day; }
                if(hours < 10){ hours = '0' + hours; }
                if(minutes < 10){ minutes = '0' + minutes; }
                if(seconds < 10){ seconds = '0' + seconds; }

                eventData.start = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
                alert(eventData.start);
            }

to show how the date/time being returned for the dropped event is misleading.

The drop handler is setup to return the UTC datetime of the dropped event. Yet you'll notice that if you drop an event on 11/10/2014 08:00:00, that is the time that is returned.

I am in Pacific time zone (-8) so if I'm using the calendar and drop an event on 2pm (my local time) shouldn't the UTC time returned be 10pm?

Has anyone else noticed this behavior?

like image 732
A.O. Avatar asked Nov 12 '14 01:11

A.O.


1 Answers

To get the results you want, you need to add timezone:'local' when you initialize the calendar.

The default for timezone in FullCalendar is "no timezone", as specified in the docs. So no, it isn't accounting for your local time.

View the differences using this more-readable version of your code as you posted (no timezone) against a version where it will use your local timezone.

like image 101
MikeSmithDev Avatar answered Nov 10 '22 10:11

MikeSmithDev