So I have these variables...
$curtz // Timezone I want to convert to (example "-0600")
$date['TZ'] // Timezone of the time I want to convert to $curtz (example "-0800")
$date['D'] // Day (example "8")
$date['M'] // Month (example "1")
$date['Y'] // Year (example "2009")
$date['H'] // Hour (example "23")
$date['Min'] // Minute (example "59")
$date['S'] //Second (example "59")
And I have this horrible code...
if ($curtz!=$date['TZ'])
{
$direction = substr($date['TZ'], 0, 1);
$hours = substr($date['TZ'], 1, 2);
if ($direction=='+')
{
$date['H'] = $date['H'] - $hours;
if ($date['H']<0)
{
$date['H'] = $date['H'] + 23;
$date['D']--;
}
}
else
{
$date['H'] = $date['H'] + $hours;
if ($date['H']>23)
{
$date['H'] = $date['H'] - 23;
$date['D']++;
}
}
$direction = substr($curtz, 0, 1);
$hours = substr($curtz, 1, 2);
if ($direction=='+')
{
$date['H'] = $date['H'] + $hours;
if ($date['H']>23)
{
$date['H'] = $date['H'] - 23;
$date['D']++;
}
}
else
{
$date['H'] = $date['H'] - $hours;
if ($date['H']<0)
{
$date['H'] = $date['H'] + 23;
$date['D']--;
}
}
if ($date['D']>$this->months[$date['M']][1])
{
$date['M']++;
if ($date['M']>12)
{
$date['M'] = 1;
$date['Y']++;
}
$date['D'] = 1;
}
elseif ($date['D']<=0)
{
$date['M']--;
if ($date['M']<=0)
{
$date['M'] = 12;
$date['Y']--;
}
$date['D'] = $this->months[$date['M']][1];
}
}
Yes, I know, the above code is disgusting, and probably doesn't work right.
Can anyone give me some pointers on how to fix this, or a better way of converting times between timezones?
Thanks!
Chris