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

Hi jedd,
first i want to say thank you for your fast reply. I appreciate that :exclaim:
I'm very happy to here that the idea of my approach is correct, so all these days reading and banging my head against a wall wasn't useless ;-P

Before I tell you about my database construction I have to make some adaption to my description about the problem, that I want to solve. I mean the problem is the same but my description wasn't quite correct.

What i want to do is to build a memorization tool for users (Europe Timezone UP1). European users can add events (online events, for example: Multiplayer Games) from a other timezone which are mostly in ET (Eastern Time, which I think is UM5 Timezone). The European user add the event in UM5, and my tool should display this event in the Eurpean Time --> UP1.

Example: There is an online event in UM5 timezone. The Eurpean user adds the event and my tool should give him the correct time in his timezone, so he knows exactly when to meet up online.

I uploaded a version to my server, where you can log in, add an event and see the result.
(I think this way is more easy to explain ......... :coolsmile: ) That's the link
username: dude2 password: dude2

Everything works perfectly so far. The user adds the event date which is in UM5 and the date displayed for him is in UP1. (Eventdate UM5 which is saved in DB in GMT and which is converted to users timezone .....) If there weren't any Day Saving Times on globe, this post here would be unnecessary :lol: , I come to that part later.

The table for a user look like this:

userid[bigint(20)]<- Primary key <- auto increment, username[varchar(50)], password[varchar(50)], email[varchar(50)], key[varchar(50)], timezone[varchar(5)]

The table for the events look like this:

eventid[bigint(20)]<- Primary key <- auto increment, userid[bigint(20)], name[varchar(50)], desc[varchar(50)], date[datetime], client[varchar(50)];

There is also an client table. By adding an event the user chooses a client in which the information about the timezone is saved (in my case usually UM5). The client table looks like this:

clientid[bigint(20)]<- Primary key <- auto increment, name[varchar(50)], timezone[varchar(50)]

I also give you acces to my database, that you can log in and see how I build it:

Here is the link to my database

Username: sql7940_990243
Password: afterglow

Here is what I do in my controller, when a user adds an event the date and the event information is added to the database. Please don't laugh about my code, I'm still new in PHP (programming) and I have a feeling that what I do can be made much more elegant, but it works.... :coolsmirk:

$xy = $mydatum.$stunde.$minute.'00'; //
            $xy_unix = mysql_to_unix($xy); // here I make the date unix
            // know I need to know what timezone this date is in
            //I pull this information out of the client table in database
            $client = $this->input->post('client');      
            $this->db->where('name', $client);
            $query = $this->db->get('client')->row();
            // here i got the timezone information from the event
            $event_timezone = $query->timezone;
            // now I convert my date to GMT
            $gmt_conversion = convert_to_gmt($xy_unix, $event_timezone);
            // I make this unix timestamp in SQL format again
            // that I can save it in SQL datetime
            $date = unix_to_human($gmt_conversion, TRUE, 'eu');
            // other varibles from the form input
            $eventname = $this->input->post('eventname');
            $client = $this->input->post('client');
            $desc = $this->input->post('desc');
            $data = array(
               'userid' => $this->session->userdata['userid'] ,
               'name' => $eventname ,
               'desc' => $desc,
               'date' => $date,
               'client' => $client
            // I update event table in database with the event information
            $this->db->insert('event', $data);
            redirect ('home');


Here is what I do in my controller when the users shows the events.

function index()
        $uid = $this->session->userdata['userid'];
        $this->db->where('userid', $uid);
        $this->db->order_by("date", "asc");
        $data['eventdata'] = $this->db->get('event');
        $this->load->view('home', $data);

Here is my view to show the events. I do a little controller stuff here (Take the GMT date and make it to UP1). I know I shouldn't do this in the view but I don't know better at the moment. :roll:

&lt;?php foreach($eventdata->result() as $row):
// get all Eventdates from table Event from the User and make them unix
$date_unix = human_to_unix($row->date);
// Timezone From the User from session
$timezone = $this->session->userdata['timezone'];
// make the GMT Eventdates from Database to users Timezone
$date_timezone = gmt_to_local($date_unix, $timezone);
// make the Eventdate Human again
$date = unix_to_human($date_timezone, TRUE, 'eu');

// ----&gt; View the date
<div class="event">
<div class="event_dmy">
<div class="event_m">&lt;?php echo date("M",strtotime($date));?&gt;</div>
<div class="event_d">&lt;?php echo date("d",strtotime($date));?&gt;</div>
<div class="event_y">&lt;?php echo date("Y",strtotime($date));?&gt;</div>
<div class="event_time">&lt;?php echo date("H:i",strtotime($date));?&gt;</div>
<div class="event_details">
<div class="event_name">&lt;?=$date?&gt;</div>
<div class="event_name">&lt;?=$row->name?&gt;</div>
<div class="event_client">&lt;?=$row->client?&gt;</div>
<div class="event_desc">&lt;?=$row->desc?&gt;</div>
&lt;?php endforeach; ?&gt;

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

Theme © iAndrew 2016 - Forum software by © MyBB