Context:
I recently setup EE in production and had some templates that were time-sensitive. In these templates I was using JavaScript to countdown to open a feature in case a member accessed the page in advance. The countdown was basically a difference between {current_time}
and an entry's Date field.
This was my introduction or rather re-introduction to EE's DST. In the Admin -> Localization Settings
they literally mean your server's time zone and DST settings, not the settings you want for EE.
Problem I faced:
The timing was off by an hour. I would see the correct time as desired when punching in the Date field, but the epoch time stored in the database was actually an hour behind. Yet {current_time}
in a template was perfectly fine.
Attempted fix:
My server's time is in UTC and at present DST is not in observance (I just assumed this is somehow automatic), despite changing those settings the Date field would be stored as "UM5" (GMT -5 or EST, the time zone for New York which is what I want) and still be an hour behind.
Temporary fix:
Reading up on previous discussions I turned off localization for users and set a Super Admin's setting as the master site default. There is no longer an "Honor the Daylight Saving Time setting associated with each weblog entry?" setting, nor does it seem that anything gets stored associated to a channel or entry (please correct me if I'm wrong here), so this feature seems to be gone altogether. This did the trick for me in the sense I could now put a desired time as seen in YYYY-MM-DD hh:mm [AP]M format and get stored with the desired epoch value....
Problems that remains:
All previous entries' time are now behind by an hour. That is not a problem for me at the moment, but I probably wouldn't want that to happen. If a content editor or manager punches in a datetime, say, November 18th at 9 AM, that time should never later on become something different, whether 8 AM or 10 AM.
What if I want to respect users' localization settings? For now they're off and I couldn't yet determine if they're relevant or not.
I found the following post by post by Ryan Masuga (via this blog entry) which seems very useful for dev/staging/production configs, automating enabling/disabling DST, using a config variable instead of a member's settings (difference between server_timezone
and default_site_timezone
), but it doesn't seem like it will affect retrofitting these settings onto all previous dates when that is not desired.
I haven't been exposed to how else this might be a problem so I guess for now how do you keep fields that were saved whilst DST was observed the same even while DST is no longer observed?
EDIT::
Here's a code sample similar to what I use for my configuration (credit to Steven & Adrian for the Gist)
(note it's $config
, not $conf
, don't know if the latter legacy thing has any effect)
(For timezone codes like UM5
below see: Code Igniter: Date Helper: Timezone Reference):
// @link http://expressionengine.com/forums/viewthread/195956/#922322
$isDst = date('I') ? 'y' : 'n'; // or see discussion below for timezone-specific dst, not sure if it should be done given EE will make up the difference
/* @link https://gist.github.com/3969207
$dateTime = new DateTime();
$dateTime->setTimezone(new DateTimeZone('America/New_York'));
$dateTime->setTimestamp(time());
$isDst = (bool)$dateTime->format('I') ? "y" : "n";
*/
$config['time_format'] = 'us';
$config['server_timezone'] = 'UTC';
$config['server_offset'] = '';
$config['daylight_savings'] = $isDst;
$config['default_site_timezone'] = 'UM5'; // GMT - 5
$config['default_site_dst'] = $isDst;
//$config['honor_entry_dst'] = 'n'; // No longer exists
Any new date fields will be entered properly, however, existing fields will be off by one hour. The problem remains. Entries punched in while DST was on will be off by an hour while DST is off, similarly entries punched in while DST was off will be off by an hour while DST is on (albeit the other direction).
How do we solve the alternating 1-hour off problem? The discussion on the github gist does not solve this except via manual database queries...
Edit:
ExpressionEngine 2.6 will be removing these DST issues altogether, which makes me wonder about upgrade issues... and we'll have to do with these config variables already in use in a bootstrap... here's to hoping their docs on the matter will be thorough/comprehensive...