Serhioromano / bootstrap-calendar

Full view calendar with year, month, week and day views based on templates with Twitter Bootstrap.
http://bootstrap-calendar.eivissapp.com/
MIT License
3.02k stars 1.29k forks source link

Time zone conversion #67

Closed Serhioromano closed 10 years ago

Serhioromano commented 11 years ago

Would be useful to have 2 new parameters

timezone: {
    convert: true,
    original: '+4'
}

This will convers server time to local according to server time zone and local time zone difference.

Reference #65

mlocati commented 10 years ago

Handling time zones is not so easy. For instance, here in Italy we are on CET: it means that we are at +0100 (1 hour later that GMT). But on the last Sunday of March, at 2 a.m. we switch to DST, and we are at +0200. On the last Sunday of October, at 3 a.m. we switch back to standard time.

Handling all the cases is quite a mess: there's a lot of time zones out there, with a lot of special cases.

Furthermore IMHO we shouldn't do that: all the time zone stuff is already handled by the JavaScript Date object...

Let's make an example: Let's suppose that I scheduled a phone call with you on September 25, 2013 at 16:30:00, local Italian time (it's 14:30 in UTC). When I load events, the server returns the timestamp, that is 1380119400000, and my browser (and consequently Bootstrap Calendar) correctly shows it to me as "September 25, 2013 at 16:30:00". If you are in Kyrgyzstan and you look at the same event, you still receive the timestamp 1380119400000 (it's absolute), but your browser shows it to you as "September 25, 2013 at 20:30:00". And that's correct, the phone call is always at the same time, that's 16:30 in Italy and 20:30 in Kyrgyzstan.

So, for me it's not a big problem, we can forget about the timezone: everything's working fine at the moment...

The only problem I can see is for some kind of events, like for instance birthdays. They should be shown as starting from 00:00 and ending to 24:00 everywhere you are. To solve this we could tell the server the current timezone. We can't tell the server we're at +0200 or at at +0600, since in the same day the time offset can change (see the switch from DST to standard time I described above). Instead, we can tell the server the name of the current time zone (to determine it there's the great jsTimezoneDetect). This value can then be used server-side. For instance, jsTimezoneDetect tells me that now I'm in time zone Europe/Berlin. We can pass it to the server when we load events (for instance in a GET parameter called timezone). On the server side we can do the following:

date_default_timezone_set($_GET['timezone']);

From now on, the time offset of the server is the same as the time offset of the client, and the server can send the special events like birthdays... So, to have a timestamp that's shown as midnight for the browser it's enough to use the standard date() function.

mlocati commented 10 years ago

We can add optional support for time zones in the following way:

If all this discussion makes a sense for you, I can create a pull request...

Serhioromano commented 10 years ago

I was thinking on timezone offset. By default it is 0. You can adjust dates returned by server + or - . That is all I though to add.

mlocati commented 10 years ago

Well, as I said, we may not have a fixed timezone offset: it may vary during the year and it may vary during a day. But what about telling to the server the timezone name of the client while we request the events?

Serhioromano commented 10 years ago

But what about telling to the server the timezone name of the client while we request the events?

This is ok. Easy. We tell timezone to the server and let developer decide how to affect even dates. I just though we can do it so that it is more simple for developer.

:white_check_mark:

mlocati commented 10 years ago

@Serhioromano Ok, I will create a new pull request about it. But before I think that we should fix the bootstrap 3 support, so that we can move all the commit from the bs3 branch to the master branch... Unfortunately I've not much time these days...

mlocati commented 10 years ago

See https://github.com/Serhioromano/bootstrap-calendar/pull/110

mlocati commented 10 years ago

Ok, now the calendar sends the browser_timezone to the server when fetching events.