What is the most effective way to manage time zones in a PHP/MySQL application? -
i'm developing web application involves use of timestamps. timestamps display in user's time zone little configuration possible. facebook , google calendar both update displayed time automatically when logged different time zones.
what effective method you've used deal time zones in web apps? if @ possible, require no additional input user.
here's i'm thinking far:
- store timestamps in database in utc
- keep database table correlates time zones utc offsets, , whether daylight savings time observed in time zone
- given client information (ip address?), find user's current time zone. information can cached in session variable prevent repeated reads table.
- whenever timestamp database displayed, convert using utc offset
i find hard believe there's nothing out there this. if have suggestions, i'd appreciate it.
i'd propose solution:
- store dates in mysql
timestampcolumn type - right after connect mysql - specify current user's timezone
set time_zone='<tz>'<tz>can either+01:00offset or timezone nameasia/vladivostok(for latter special timezones db should imported dba)
the benefit of using timestamp automatically converts date , utc, according time_zone you've specified in current connection.
more details timestamp: http://dev.mysql.com/doc/refman/5.1/en/timestamp.html
about retrieving current user's timezone (even though there lot of answers here on topic, let's once again):
- as long there tz value in cookies (look @ step 4) - use it.
- for registered/authenticated users - can ask specify timezone , store permanently in db.
- for guests can retrieve timezone javascript (
date.gettimezoneoffset()) , send ajax - if first request/nothing passed ajax - guess ip
- for each step (1-3) - save timezone cookie.
Comments
Post a Comment