If you run a UK based Magento store you probably already know that the store times are wrong for half of the year as the timezone switches between GMT and BST.
Unfortunately, Magento doesn’t support BST at all and the only thing for store owners in the UK, is to use standard GMT for the whole year – obviously, not great.
Magento uses UTC to store all times in the DB and works out the offset from that to whichever timezone you have selected in the admin area. The idea behind this is to allow you to set different timezones per store and have them all work together because of how the dates are stored.
So what can I do?
Unfortunately the only way to allow support for BST is to change the default timezone from UTC to Europe/London. This means creating local override files, so if you’re wanting to use timezones other than Europe/London for a store in your installation, you’re probably just going to have to live with the issue.
1) Any existing data will be stored in UTC (GMT), so it will always be an hour behind during BST. This is a useful amend to make at the beginning of a new build rather than to a store that already exists, but if you can live with it, then go ahead any way.
2) You’ll need to make a single core file change to
What steps should I take?
Firstly, you need to ensure that your server is set up as
Europe/London, otherwise altering Magento isn’t really going to have any baring on getting things working. To fix this, depending on your Linux OS, you want to be doing something like: this handy guide.
What to change with Magento
Start by copying the following files into their respective “local” folder.
app/code/core/Mage/Core/Model/Locale.php app/code/core/Mage/Core/Model/Date.php app/code/core/Mage/Cron/Model/Schedule.php
app/code/local/Mage/Core/Model/Locale.php app/code/local/Mage/Core/Model/Date.php app/code/local/Mage/Cron/Model/Schedule.php
Open the first file –
app/code/local/Mage/Core/Model/Locale.php and replace the following lines (note these lines aren’t together):
const DEFAULT_TIMEZONE = 'UTC'; @date_default_timezone_set($timezone); $date = date('Y-m-d H:i:s'); @date_default_timezone_set($currentTimezone);
const DEFAULT_TIMEZONE = 'Europe/London'; @date_default_timezone_set(Mage_Core_Model_Locale::DEFAULT_TIMEZONE); $date = date('Y-m-d H:i:s'); @date_default_timezone_set(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
What we’re doing here is altering the default timezone, and then calling that setting when we call
date_default_timezone_set. You could use
self::DEFAULT_TIMEZONE instead of
Mage_Core_Model_Locale::DEFAULT_TIMEZONE if you were so inclined.
Nex, you should open up the
app/code/local/Mage/Core/Model/Date.php file and locate the
Change the following two occurances – again, making reference to the constant we’ve just set up:
$result = date_default_timezone_set($timezone); date_default_timezone_set($oldzone);
$result = date_default_timezone_set(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
The only other amend left to do is to make sure that the cron system still knows what time it is! To do this, we edit
app/code/core/Mage/Cron/Model/Schedule.php and change the following line:
$d = getdate(Mage::getSingleton('core/date')->timestamp($time));
$d = getdate();
Unfortunately – and I’m not quite sure why I’ve left this till last, but… – you need to make a core Magento change. Fortunately, this is straight forward and only requires one change. For some reason, the guys that made Magento decided to hard-code in a UTC call within the main
app/mage.php. It’s not a good idea to make core changes, as when you come to update Magento (if you ever do), you’ll have to re-make this change, but it needs to be done.
app/mage.php and find the line:
And that’s it! Your store should now be working to BST/GMT. Congratulations!