So, now the trouble is translating a timezone key like EST to a numeric offset (i.e. -5). There are many "special" cases and though PHP seems to have knowledge of these time zones, I'm at loss how to access them. Perhaps it's not worth the trouble: just have them enter numeric offsets?
date("I") appears to work for detecting daylight savings time, but once again, there are many variations across the globe for daylight savings time. Without a lookup table, is it necessary to simply forgo daylight savings and have the user switch it on or off? Or are daylight saving time beginnings and endings uniform enough to just ask the user whether or not to automatically detect DST? Perhaps all two options should be allowed?
I realize I have asked this question before. But I would like to not have to constantly change my time preferences whenever something funky happens (ex. DST on/off). If this is impossible, tell me so, and I'll abandon this idea.
Mediawiki, which runs the extremely international Wikipedia, uses offsets like -5:00. I assume they parse the string into a negative, a 5, and a 0, which can be used to determine seconds without tricky floats. You have to adjust your time when DST kicks in. It uses this code to guess offsets:
Code: Select all
// in [-]HH:MM format...
// won't yet work with non-even tzs
function fetchTimezone() {
// FIXME: work around Safari bug
var localclock = new Date();
// returns negative offset from GMT in minutes
var tzRaw = localclock.getTimezoneOffset();
var tzHour = Math.floor( Math.abs(tzRaw) / 60);
var tzMin = Math.abs(tzRaw) % 60;
var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour +
":" + ((tzMin < 10) ? "0" : "") + tzMin;
return tzString;
}