Why storing future times in timestamps is not good
A collection of articles and videos explaining timezone intricacies, including storing future events, and a list of libraries for PHP and JS.
I’m not going to write my own words, but will link to a bunch of articles, but the tldr:
Storing a future event in UTC timezone carries the risk of the place changing timezone rules between now and when it’s scheduled for, thus your future even “shifts” without you having touched anything, as the same UTC datetime will mean something different.
References
How to save datetimes for future events - (when UTC is not the right answer)
The above goes into detail through an example of why storing a future event in UTC is not a good idea. Collected here because it’s rather hard to find via the googles all the time. The article is awesome and go and read it.
UTC is Enough for Everyone, Right?
This one is a long, and fascinating history of timekeeping and the frustrations people have had with it throughout the ages.
I absolutely love VSauce videos. This is a look at the orbital mechanics that “cause” some of the discrepancies in timekeeping. Well worth a watch (21:36).
And then a rant by Computerphile on timezones and their awesome awful properties.
Libraries
For PHP, use Carbon: https://carbon.nesbot.com/docs/
For WordPress, use Carbon. If you can’t, use Andrey “Rarst” Savchenko’s wpDateTime
: https://github.com/Rarst/wpdatetime, and the accompanying article: https://www.rarst.net/wordpress/datetime-crash-course/
Javascript
Moment.js - a hefty chonk of a library, but has it all: https://momentjs.com/
Luxon.js - like moment, but slimmer: https://moment.github.io/luxon/
date-fns: newer entry, looks good, haven’t used it yet, but here you go: https://date-fns.org/
spacetime: another library that I didn’t know about (thx Travis!), looks great: https://github.com/spencermountain/spacetime
Photo by Icons8 team on Unsplash