How to globally set UK date format in Carbon to auto update for BST
I'd like my app.config to have some sort of setting whereby I could just leave one global setting that makes my dates into British Summer Time when required. Is there a way to make Carbon aware globally of what locale my app is for?
@robgeorgeuk I've set it to UTC at the moment, should I turn it to Europe/London ? I'm trying to go for a timezone that would automatically adjust for BST.
Sorry, I think I misread the question. I think the above code will cause all dates (such as the created_at timestamp) to be written in the Europe/London timezone. This might work for your project but I think it's more common to use UTC and then convert when needed using something like:
@robgeorgeuk If I were to set it to London/Europe, do you think it would be GMT? It's just so confusing. BST is GMT+1, so if London/Europe is set to GMT zone, then it wouldn't change to BST once the summer time starts. Or would it?
Dealing with Timezones was tedious in one of my apps and the solution I came up with was...
Store dates in UTC in the database
In View, instead of displaying date, put it in "data-timestamp" attribute of the HTML Element in which you want to display date.
Now use MomentJS to loop through all the element containing "data-timestamp" attribute and display Relative (Humanize) time in that HTML Element.
I put this is setInterval so it gets invokes every 60 seconds and update the relative time.
What I also make sure is that if time difference is more than 24 hrs, I display Day of the Week and if time difference is more than 7 days, I display Date and Month.
I have Europe/London set in my config for my timezone and this seems to be picking up the correct time with no fancy calculations required.
But store all dates as unix timestamps in the database IMO.. it'll save you a whole heap of issues in the future (my worst nightmare was developing a site for Safelite Autoglass a few years ago... UK-based server, US-based company who insisted all dates / times were saved in the datebase in a DateTime field with an EST timezone... argh!!).
@ian_h I'm in a similar position. My client has customers based mostly in the UK, but there's a good number who are based in the continent. It would be great if I could just ask MySQL to convert the time from UTC to CET or whatever, as required.