Skip to content

Instantly share code, notes, and snippets.

@1stevengrant
Created October 28, 2012 17:21
Show Gist options
  • Select an option

  • Save 1stevengrant/3969207 to your computer and use it in GitHub Desktop.

Select an option

Save 1stevengrant/3969207 to your computer and use it in GitHub Desktop.
Fixes the daylight savings issue with EE
var $dateTime = new DateTime();
$dateTime->setTimezone(new DateTimeZone('America/New_york'));
$dateTime->setTimestamp(time());
$isDst = (bool)$dateTime->format('I') ? "y" : "n";
$conf['daylight_savings'] = $isDst;
Copy link
Copy Markdown

ghost commented Oct 29, 2012

Great workaround. (Note this is PHP 5.3+ only, but most hosts are using that now.)

@1stevengrant
Copy link
Copy Markdown
Author

I can't take any credit for this - thanks go to @lowellkitchen for this

@kevinfodness
Copy link
Copy Markdown

If you have control over the server time, and/or the server time is set to what you want (e.g., server timezone set to the same timezone that you want for the website) you can do it in one line:

$config['daylight_savings'] = date('I') ? 'y' : 'n';

@amacneil
Copy link
Copy Markdown

@gregferrell Do you have a reference for this being 5.3 only? All I could find is the DateTime class being 5.2+

@lowellkitchen
Copy link
Copy Markdown

@adrianmacneil the setTimestamp method was added in PHP 5.3: http://www.php.net/manual/en/datetime.settimestamp.php

their are easy work arounds to this for folks not on PHP 5.3 yet.

@cleverlever
Copy link
Copy Markdown

Also set, this recently hosed me.

$config['default_site_dst'] = date('I') ? 'y' : 'n';

@cleverlever
Copy link
Copy Markdown

And you might have to do something like this for your old entries when going from UM6 (CDT) to UM5 (CST) and using "fixed" dates (field_id is 394).

update exp_channel_data SET field_dt_394 = 'UM5';

Or switch everything to localized using (field_id is 394).

update exp_channel_data SET field_dt_394 = '';

@rsanchez
Copy link
Copy Markdown

PHP 5.2 version:

$dateTime = new DateTime();
$dateTime->setTimezone(new DateTimeZone('America/Chicago'));
$date = getdate();
$dateTime->setDate($date['year'], $date['mon'], $date['mday']);
$dateTime->setTime($date['hours'], $date['minutes'], $date['seconds']);
$conf['daylight_savings'] = $dateTime->format('I') ? 'y' : 'n';

@benjamin-smith
Copy link
Copy Markdown

America/New_york should be America/New_York, no? http://www.php.net/manual/en/timezones.america.php

@jayeshjain24
Copy link
Copy Markdown

My website is having a countdown from 23july to current time.I am from india and my timing lag 5.30 hours.The problem is the site is also for pakistan,srilanka,bangladesh.So i need to have respective timezone using php.Any idea?Currently the countdown get deprecated by one day at 5.30 in morning instead of midnight

http://www.tensports.com/event/other/commonwealth-games-2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment