Welcome Guest, Not a member yet? Register   Sign In
Timezone Confussion -> convert_to_gmt -> daylight saving zones / Am I right ? Or wrong

Hello guys, I'm pretty new in PhP and the question I'm asking is discussed in some other post
as well. Maybe the solution is quite simple but this timezone stuff drives me crazy, and I don't know what is right or wrong anymore. First of all I explain what i want to have and then what I got. The idea:

User (EVENTCREATORS) in a Timezone (mostly UM5) can add events and user (EVENTVIWERS) in an other Timezone (mostly UP1) should see these Events in their own time (Timezone).

Example: User adds an Event at 1 PM in New York (UM5) and the user in Berlin (UP1) should see this Event at 7 PM in his calendar. (NewYork-Berlin 6 hours at the moment)

My solution approach:

1)Every user can set his own Timezone
2)Store Event dates in Database in UTC (GMT) and in unix format.
3) If an Event is created in UM5 Timezone, I take this Eventdate, make it to GMT and save it to data base.
4) If an User in UP1 Timezone views this Event i take the GMT Date out of the database and convert the date in UP1, so that the EVENTVIEWER see the Eventdate in his right time.

Here is what i got so far.

Somebody creats an Event in New York (UM5) which is saved in the variable $xy in sql format.
I make $xy to unix. I set the timezone UM5 and use the convert_to_gmt Funktion (http://codeigniter.com/wiki/convert_to_gmt) to convert it to GMT time (I dont save it in databse so far).
Then i take this GMT converted date $gmt_conversion and use the gmt_to_local function with the UP1 timezone to bring it in the right format for the Eventviewers in Berlin.
In my example below I don't use any daylight settings. So far everything works perfect.

For my introducing example: 1PM in New York - 7 PM in Berlin I get the right result(6 hours between New York and Berlin), but when i now use the Daylight_Saving Settings -> TRUE, my result turns into wrong (8 hours between New York and Berlin) !!!!!

But thinking about it daylight_saving settings can't be neglected, or can they ????.
Maybe i miss sth. here. Is my approach right or totally wrong ? Can sb. give me a kick ?

My servers (local) timezone is set Europe/Berlin but also changing this to in the php.ini to GMT didn't have any effects (I think it shouldnt because my solution doesnt need the servers time !?) I also set the config.php to $config['time_reference'] = 'GMT';

Here my code:

// $xy => the Event Date sth. like this : $xy='2009061123000'
            $xy = $mydatum.$this->input->post('stunde').$this->input->post('minute').'00';
            echo'----> Input Event time for Timezone UM5 :  ';
            echo $xy.'<br />';
            // make $xy to unix format
            $xy_unix = mysql_to_unix($xy);          
            // define timezone for $xy
            $event_timezone = 'UM5';
            // define daylight for $xy (isnt used in this example)
            $daylight_saving = TRUE;
            // use convert_to_gmt() function --&gt; http://codeigniter.com/wiki/convert_to_gmt
            // convert $xy to gmt Time
            $gmt_conversion = convert_to_gmt($xy_unix, $event_timezone);

            // define Users Timezone UP1
            $user_timezone = 'UP1';
            // define daylight(isnt used in this example)
            $daylight_saving = TRUE;
            // convert Event in GMT Time to timezone UP1
            $xu = gmt_to_local($gmt_conversion, $user_timezone);
            echo'----&gt; Output Time in Users Timezone UP1:  ';
            echo unix_to_human($xu);

Messages In This Thread
Timezone Confussion -> convert_to_gmt -> daylight saving zones / Am I right ? Or wrong - by El Forum - 06-16-2009, 11:58 AM

Theme © iAndrew 2016 - Forum software by © MyBB