Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery fullCalendar: problem with date/event - It's rendering an hour too late!

I have a bit of wierdness that I've just spotted inside my fullCalendar implementation.

Basically, I have a date inside the database "28/04/2011 09:00:00" (dmy), which I convert into a Unix Timestamp, which results in 1303981200.0.

I've checked with http://www.onlineconversion.com/unix_time.htm, and the timestamp is valid.

However, when I pass this JSON into fullCalendar, it renders the event an hour later!

The JSON is:

[{"id":"4a315750666d2f70675241544936762b632f514f51513d3d","title":"Blah blah blah","description":"","start":1303981200,"end":1303983000,"className":"A-16","allDay":false}]

Baffled

Thanks.

like image 488
Oxonhammer Avatar asked Apr 26 '11 16:04

Oxonhammer


2 Answers

Hey amit_g, I also ran into this using timestamps generated by php. The issue occurs because a timestamp does not 'literally' contain a timezone, so when it's converted by javascript with Date() by FC your local timezone is used.

I solved this by simply using the full ISO 8601 date format instead of a timestamp when supplying events to FC.

$startTimestamp = 1303776000; //2011-04-26 at 12am
$startISO = date('c', $startTimestamp);
echo $startISO; //Outputs 2011-04-26T00:00:00+00:00

Supplying FC with just $startTimestamp as the event start displays the event according to my timezone (-4 EST at the time due to DST) since the timestamp is for 12am, javascript Date() subtracts 4 hours, hence showing my event a full day earlier on FC. Using the ISO date now shows all my events at the correct time. Hope this helps someone else!

like image 157
James Avatar answered Sep 24 '22 21:09

James


You might have to try and add timezone locations as your server could have different times.

http://arshaw.com/fullcalendar/docs/event_data/ignoreTimezone/

like image 29
Piotr Kula Avatar answered Sep 22 '22 21:09

Piotr Kula