triexa
March 5, 2010, 10:14pm
1
I want to make some changes to my app to make use of the newer DateTime and related classes.
I want to let users select their timezone so we can adjust times to display in their local time.
However, I’m trying to build the actual selection of said timezones for the user and it seems EXHAUSTIVE!
For example, this is JUST the Americas:
http://www.php.net/manual/en/timezones.america.php
That’s a lot on its own. How are you supposed to make use of these and have a user select their zone?
We’re past the point of “pick your GMT offset” - need to account for daylight savings…
Bah! I agree.
If this is purely for presentation, and it should be, let the user select a -24/+24 hour range and be done with it.
A simple select should do the trick.
<label>
Your current time is:-
</label>
<select>
<?php
for($offset = -23; $offset < 24; $offset++){
printf(
'<option>%s</option>',
date('F j, Y, g:i a', strtotime($offset.' hours'))
);
}
?>
</select>
Daylight savings is a real pain. It’s not consistent in when it starts and ends. Certain places don’t obverse dst even though everything surrounding that area does.
I’ve yet to see an answer to this that isn’t summarized by “comprise and accept it’s not perfect”.
I’ve got an always-updated list of timezone offsets (with DST applied) at:
http://api.coronatus.com/clock/read
If you want to use those numbers for DST, go ahead. But cache the JSON.
triexa
March 6, 2010, 3:27pm
5
AnthonySterling:
Bah! I agree.
If this is purely for presentation, and it should be, let the user select a -24/+24 hour range and be done with it.
A simple select should do the trick.
<label>
Your current time is:-
</label>
<select>
<?php
for($offset = -23; $offset < 24; $offset++){
printf(
'<option>%s</option>',
date('F j, Y, g:i a', strtotime($offset.' hours'))
);
}
?>
</select>
Missing some *:30 timezones
But ya, that completely ignores timezones so they would have to be wrong sometimes or adjust it twice a year. I’d really like to be able to natively handle timezone + handling of DST for the user, but as I say - creating that select list of zones would be MASSIVE!