The problem

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.

Issues?

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 app/Mage.php.

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.

to

Open the first file – app/code/local/Mage/Core/Model/Locale.php and replace the following lines (note these lines aren’t together):

with

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 calculateOffset() function.

Change the following two occurances – again, making reference to the constant we’ve just set up:

with

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:

to

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.

Open up app/mage.php and find the line:

to

And that’s it! Your store should now be working to BST/GMT. Congratulations!

Image Credit: magro_kr