1

Im using JQuery Full Calendar Plugin. Code:

     $('#mycalendar').fullCalendar({
        ** options **
        events: function(start, end, callback) {
            $.ajax({
                url: '/myloader/',
                dataType: 'json',
                data: {
                    // our hypothetical feed requires UNIX timestamps
                    start: Math.round(start.getTime() / 1000),
                    end: Math.round(end.getTime() / 1000)
                }
       *** more stuff
     });

now on myloader php side when i try to get start and end dates here is what i get:

var_dump(date('m/d/Y H:i:s', $_GET['start']), date('m/d/Y H:i:s', $_GET['end']));

this returns:

string(19) "01/27/2013 06:00:00"
string(19) "03/10/2013 06:00:00"

why is it 6:00:00 ? i want it to be 00:00:00 for start and 23:59:59 for end

I know i can hack through it using PHP but is there a reason why full calendar returns such date?

If i use PHP i can get desired results using:

$start = strtotime(date('m/d/Y', $start) . ' 00:00:00');
$end = strtotime(date('m/d/Y', $end) . ' 23:59:59');

but i dont want to do it on PHP side is there a way full calendar to give correct time? If its a timezone issue how can it be fixed?

thanks

GGio
  • 7,563
  • 11
  • 44
  • 81
  • time zone differences. what exactly are you sending across in the `start` and `end` parameters? – Marc B Feb 15 '13 at 19:25
  • getTime gets the time from your computer. Probably your local time zone is +6 hours. – Green Black Feb 15 '13 at 19:25
  • no time on my computer is fine – GGio Feb 15 '13 at 19:26
  • FullCalendar isn't returning the 6 hour offset, the PHP date function is by using your server's default timezone. If you just print $_GET['start'], you'll see it's a UNIX timestamp, and you can convert it to see that the time is correct. In other words, JS is already returning a GMT time, so it's not real clear what you mean when you say you want to do it on the JS side . . . – ernie Feb 15 '13 at 19:35
  • To clarify further, .getTime() ignores timezones as it's always with respect to UTC time. See http://stackoverflow.com/questions/4577823/if-javascript-new-date-gettime-is-run-from-2-different-timezones. – ernie Feb 15 '13 at 19:42

1 Answers1

1

How about this:

var_dump(
   date('m/d/Y H:i:s', strtotime(date("m/d/Y",(int)$_GET['start'])), 
   date('m/d/Y H:i:s', strtotime(date("m/d/Y",(int)$_GET['end']))
);
Green Black
  • 5,037
  • 1
  • 17
  • 29