
it's keep track of that timezone info.. which country when.. must be a website or something about it somewhere where you could pull that off..
Code: Select all
<?php
//define time zone info
$TZ = array(
'timezone_name' => 'New York/US',
'timzone_normal_offset' => -5,
'timzone_observes_dst' => true,
'timzone_dst_offset' => -4,
'timezone_dst_start' => 'strtotime("Next Sunday", strtotime("April First $year -1 Day"))',
'timezone_dst_end' => 'strtotime("Last Sunday", strtotime("September First $year"))'
);
$timezone_dst_start_cache = array();
$timezone_dst_end_cache = array();
function getAdjustedTimestamp($timestamp)
{
global $TZ;
if($TZ['timzone_observes_dst'])
{
$dst_dates = getDatesForYear(date('Y', $timestamp));
$reverse = ($dst_dates['end'] < $dst_dates['start']);
if ($reverse)
{
$start = $dst_dates['end'];
$end = $dst_dates['start'];
} else {
$start = $dst_dates['start'];
$end = $dst_dates['end'];
}
$in_dst = ($timestamp > $start && $timestamp < $end);
if($reverse) $in_dst = !$in_dst;
if($in_dst)
{
return $timestamp + ($TZ['timzone_dst_offset'] * 3600);
} else {
return $timestamp + ($TZ['timzone_normal_offset'] * 3600);
}
} else {
return $timestamp + ($TZ['timzone_normal_offset'] * 3600);
}
}
function getDatesForYear($year)
{
global $timezone_dst_start_cache, $timezone_dst_end_cache, $TZ;
if (isset($timezone_dst_start_cache[$year]))
{
return array(
'start' => $timezone_dst_start_cache[$year],
'end' => $timezone_dst_end_cache[$year]
);
} else {
$result = array(
'start' => eval($TZ['timezone_dst_start']),
'end' => eval($TZ['timezone_dst_end'])
);
$timezone_dst_start_cache[$year] = $result['start'];
$timezone_dst_end_cache[$year] = $result['end'];
return $result;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Time Zone - Proof Of Concept</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p><strong>Timezone <?=$TZ['timezone_name'] ?> </strong></p>
<p>Generating Random Timestamps:</p>
<?php
//generate a number of random times
$count = 100;
$years_back = 10; //allow timestamps from max X years ago
for($i=0; $i<$count; $i++)
{
$time = rand(time() - $years_back * 31557600, time()); //in universal time zone
echo $time . '<br>';
$times[] = $time;
}
?>
<p><strong>Starting Timer...<?php $startTimer = microtime(); ?>DONE</strong></p>
<p><strong>Rendering Dates</strong></p>
<?php
foreach($times as $time)
{
echo date('l F dS Y h:i:s', getAdjustedTimestamp($time)) . '<br>';
}
?>
<p><strong>...<?php $endTimer = microtime(); ?>DONE</strong></p>
<?php
echo (float)strval($endTimer - $startTimer);
?> seconds elapsed.
</body>
</html>
And then there are individual states that have there own thing too. This is why many feel that auto DST just wont work. You would have to have a list a mile long of locations for each user to select from. Then all the calculating, etc. Add into this what the originall poster wants wich is to show the time based on wherther it was posted during dst and you have a mess on you hands. Each post would haveto have the users setting atthed to it etc. Hence why just letting your users do it works so very well.Mvastango wrote:Well you can't just go by country. I live in the US. There are at least 5 different time zones, so there would have to be a more specific option for some areas. I don't know how it couldn't go fully automatic. The whole point would be to have it render every date based on the time when the post was made. There wouldn't even be a need for the DST selection, since all times are calculated regardless of whether or not you are in DST at the time of viewing.