I'm creating a web application using cakephp 1.2.6. There is a
functionality that I need to save the time that user is entered in GMT
format. I'm using below method to do this.

function convertDateTimeToGMT($dateTimeStr,$fromTimeZone, $format = 'Y-
m-d H:i:s') {
    if (empty($dateTimeStr))
    return $dateTimeStr;
    else if (empty($fromTimeZone))
    return $dateTimeStr;
    else {
        // Inverse the + or minus. Decimal value should be passed
        //$timeHelper = new TimeHelper();
        $newTZ = -1 * $fromTimeZone;
        return $this->format($format, $dateTimeStr, null, $newTZ) ;
    }
}


function format($format = 'd-m-Y', $date, $invalid = false,
$userOffset = null) {
    $date = $this->fromString($date, $userOffset);
    if ($date === false && $invalid !== false) {
        return $invalid;
    }
    return date($format, $date);
}

function fromString($dateString, $userOffset = null) {
    if (empty($dateString)) {
        return false;
    }
    if (is_int($dateString) || is_numeric($dateString)) {
        $date = intval($dateString);
    } else {
        $date = strtotime($dateString);
    }
    if ($userOffset !== null) {
        return $this->convert($date, $userOffset);
    }
    return $date;
}

function convert($serverTime, $userOffset) {
    $serverOffset = $this->serverOffset();
    $gmtTime = $serverTime - $serverOffset;
    $userTime = $gmtTime + $userOffset * (60*60);
    return $userTime;
}


convertDateTimeToGMT($dateTimeStr,$fromTimeZone, $format = 'Y-m-d
H:i:s') is the method that I'm calling in my code to pass the date
time and time zone. I have a combo box of time zones and if user
select time zone as "Pacific" it will pass the -8 as the value of
$fromTimeZone. But because of the DST this can be changed.

So is there any way in cakephp to find the up to date time zone values
automatically and convert the time to GMT ?

Cheers!!!!

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to