I have a problem where I need to calculate the time in a particular place in the world. The calculation should happen and the only information I have in hand is GMT of the site. EX: -1, 2, -3, etc.
I've created a class to calculate GMT-based hours. Following:
<?php
class Data{
private $dateFormat;
private $data;
public function __construct($dateFormat = "Y-m-d H:i:s e I") {
$this->dateFormat = $dateFormat;
}
public function getHoraUsingGmt($gmt)
{
if($gmt < 0)
{
$segundos = ($gmt * 60 * 60) * -1;
$this->data = gmdate($this->dateFormat, time() - $segundos);
}
elseif($gmt == 0)
{
$this->data = gmdate($this->dateFormat, time());
}
else{
$segundos = $gmt * 60 * 60;
$this->data = gmdate($this->dateFormat, time()+$segundos);
}
return $this->data;
}
}
?>
If I use the getHoraUsingGmt method and pass a value such as '-1' or '-2' the correct time is reported. But is there any way I can figure this out and know if GMT is using daylight saving time or not? And if so, tell me the correct time?
For example, the Brasilia GMT is -3 (when it's not in daylight saving time). But now it's summer time and it's -2. Is there a function of the PHP DateTime class for this calculation?