Kichu
Kichu

Reputation: 3267

Time difference when adding events to Google Calendar

I have code for adding events to Google Calender for a given mailid.

The problem is that, when I am trying to add events there are time difference issues.

For example if I add the following to the calendar 03/21/2012 8:00AM the time in the calendar entry viewed on the web is set to 17:30.

Here's my code:

$gmail = '[email protected]';
$gpwd = '1233';
$datetime1 = strtotime('03/21/2012 8:00AM');
$date1 = date("Y-m-d", $datetime1);
$idg = add_to_calendernow1($gmail,$gpwd,$id,$date1,$datetime1);

function add_to_calendernow1($gmail,$gpwd,$ticket,$date,$timestamp){
    if($gmail){
        /* Change the below path with correct path class1.php and class2.php are in the includes directory */
        include('includes/class1.php');
        include('includes/class2.php');
        $email = $gmail;  
        $password = $gpwd;  
        $altEmail = $gmail; 
        $login = new GoogleClientLogin($email, $password, GoogleClientLogin::$CALENDAR_SERVICE, APP_NAME);  
        $cal = new GoogleCalendar($login);
        $cal->altEmail = $altEmail; 
        $content = "Ticket #".$ticket." scheduled now";
        $entryData = $cal->addEvent(array(  
                        "title"=> "Ticket #".$ticket." Scehduled An Item",  
                        "content"=> $content,
                        "where"=> "",  
                        "startTime"=> $timestamp,
                        "endTime"=> $timestamp
                    ));  
        $id_now = explode('feeds/',$entryData['id']);
        $sec_id = $id_now[1];
        $id_id = explode('/',$sec_id);
        return $id_id[0];
    } 
}

The GoogleClientLogin and GoogleCalendar classes came from this blog post:

http://mark.biek.org/blog/2010/07/addingdeleting-events-with-the-google-calendar-api/

Does anyone have any ideas about what could be causing this?

The timezone of the Google Calendar is set to Eastern Standard Time and the server is in the USA.

Is there something else I need to do in my code to make sure the times are carried over properly?

Upvotes: 4

Views: 724

Answers (1)

h00ligan
h00ligan

Reputation: 1481

You're not setting the timezone anywhere in the example you have so I would guess your timezone setting is wrong, which means PHP is probably using a default setting which could be just about anything.

Try setting the timezone with date_default_timezone_set()

Upvotes: 1

Related Questions