FullCalendar daytime error

I have an application built on the basis of a full calendar based on jQuery http://arshaw.com/fullcalendar/

The events of my calendars are loaded by an Ajax call that outputs JSON, it is set to Monday as the first day of the week, and by default it is a week.

It works great, but I noticed that if I go out on the 13th week (starting March 26th), events will not load properly. I immediately realized that this should be due to the change in daylight saving time that occurs on March 25th.

When I click on the next / prev buttons, the calendar makes an ajax call using the automatically generated start and end time, my php script in the background takes the start date, calculates week no and triggers all the events in my database for this week.

For example, in week 12, the following variables are transferred:

?

start = 1332115200 & end = 1332716400 & _ = 1331237729591

PHP script:

$week_no = date('W', $_GET['start']); 

It works like week number 12.

However, the following variables passed in:

?

start = 1332716400 & end = 1333321200 & _ = 1331238038820

 $week_no = date('W',$_GET['start']); == 12 // same as last week 

Further verification of Nn

 echo date("C",1332115200); // == 2012-03-19T00:00:00+00:00 echo date("C",1332716400); //2012-03-25T23:00:00+00:00 (1 hour short of being in week 13) 

Thus, it is obvious that changing daylight causes a problem.

My question is: is this a problem with fullcalander or my PHP logic?

+4
source share
3 answers

First of all: I do not know your code and your settings, so everything that I say is pretty much an assumption.

If you are both set to UTC, the problem (should not) should not be. The same goes for the proper use of the date.getUTC * JavaScript functions (fullCalendar does not use them) with the server installed in UTC. But I think that only your server is actually set to UTC, while your computer is set to "Europe / London" or something like that (it looks like UTC now because it is winter UTC + 0) .

All this leads to the following situation: fullCalendar tries to calculate the timestamp, for example. July 1, 2012 00:00:00 - because the computer is installed in the time zone where DST is applied on this day (UTC + 0 in winter, UTC + 1 in summer → July 1 = UTC + 1), you will get a time stamp at that moment the time when 1 00:00:00 July 1 in LONDON. Since their time is one hour before UTC, you will get 23:00:00 if you interpret this timestamp relative to UTC - and this is what the server does.

The solution may be simple:

 <?php date_default_timezone_set('Europe/London'); 

Thus, the server should interpret the timestamp relative to UTC + 0 if the corresponding date is in winter and relative to UTC + 1 if it is in the summer.

However, if the time zone of visitors is set to something else, for example. "America / Los_Angeles", your application is still confused and will not work properly. The best way, as a rule, is to use UTC timestamps everywhere, but fullCalendar does not currently support this.

+3
source

Maybe it depends on the time zone, because daylight saving time dates differ in different time zones. Make sure the time zone specified in the php.ini file matches the time zone of your country.

Setting the time zone is also possible using date_default_timezone_set .

And here is a list of supported time zones.
http://php.net/manual/en/timezones.php

0
source
0
source

Source: https://habr.com/ru/post/1400457/


All Articles