Post

I wrote a thing about "Storing time for human events" - how if you're building an events website used by actual human beings the standard advice of "convert times to UTC and just store that" isn't actually the best approach simonwillison.net/2024/Nov/27/...

simonwillison.netStoring times for human eventsI’ve worked on various event websites in the past, and one of the unintuitively difficult problems that inevitably comes up is the best way to store the time that an …

18 reposts154 likes

This makes a lot of sense - you’re prioritizing the design according to the primary users of the system - humans who live in relativistic time zones. The “exact instant when this occurs relative to other events” is a secondary concern and can be derived as UTC when necessary.

Last time I did this I settled on storing UTC + time zone. The app had to be tested across a DST change before I was convinced it would all work 😂

This was for time series capture. We just used the local machine timezone. Display options were capture TZ, current TZ (if it differed) and UTC. The main concern was having graphing working across DST changes so we graphed in UTC and created graph ticks based on display time.

1) User entered the wrong time zone: Nothing will fix this after the fact except the creator themselves, but you can check consistency as they enter info. If they enter a timezone that doesn't match the location, you can warn them about the mismatch (and you can pre-fill the timezone).

If they later update the event with a different time zone (or a new time across a DST change), you can ask them if the entered time should stay the same ("it's still happening at 6:00 PM in the new local time") or change.

2) User entered the wrong location and corrected it later: if the new location is in a different time zone or observes different DST rules that affect that event, you can prompt as with the prior case.

My all-time favourite bug: some of our users would create events on their phone, but couldn't find them afterwards. Those users (in SE Asia) had their phones set to use the Buddhist calendar; we were using the "local" calendar API in iOS. Events were created just fine, but 543 years in the future!

Thanks for writing this! I've always just assumed UTC was a silver bullet (as much as a silver bullet as date/time can get) but your solution makes a lot of sense. One thought as I was reading your solution: what would the UI/UX look like for remote events? I asked Claude to come up with a solution.

This is even more true in situations where the „event“ is a moving target, like a vessel traveling between countries. And when one of those is Morocco, where the king can decide to change summer time rules on short notice. It really helps to store the original local times…

I don't think you mentioned this, but one more thing to be careful of *if* you're storing events in the future: the time zone rules for the user's locale may change (e.g., DST might be abolished).

You can mitigate this by not only storing the local time and time zone, but also the UTC offset of the future time using the present rules. Then when you go to use it, you can detect if the rules changed the offset in the interim and decide how to handle the conflict.

Yup, we learned a lot of this when building Sōsh back in the day. The task of figuring out what activities to show to users involved almost no time-zone calculations because we were recommending to a user physically in the same timezone as the venue/event.

Definitely challenging. But storing based on old time zone is not sufficient. If the person changes time zones when traveling you want the app to show their new timezone. Likewise you probably want to keep the old timezone for engagement metrics of events.

Ah gotcha. Storing timezone and utc makes sense there as long as you change it with a venue change 😅 I was thinking more broadly of how to store future and past date times as I recently had to make this decision on multiple occasions and it gets annoying.

Nice observations. I schedule a lot of international zoom meetings with regular recurrences. I'd love a UI that shows me the consequences of my scheduling choices (e.g., which attendees will be inconvenienced by DST changes)

Some of my attendees are in a region without DST. We decided to make their location the "place", so that the meeting time would never change for them. People living in DST locations are expecting a change, whereas the others were being caught by surprise.

I wrote a booking app for Shopify. How hard could it be I thought :-) 10K+ merchants across multiple tz's. All sorts of corner cases especially when dealing TZ changes and future recurrences. Definitely agree with the idea of keeping local time as well as UTC - its the only way to deal with it.

Here's an example of a much better timezone picker from the Fastmail calendar: the timezone abbreviation is easily identified, and you can search by city or timezone.

I don't really like the GMT abbreviation for London, since that's only applicable in winter. But I don't know what else to suggest, I don't know know any abbreviation for the UK timezone throughout the year.

I believe all the cities listed in that screenshot would be similar: Los Angeles is PDT in the summer, while Sydney is AEST in the winter. In June I think you'd see BST for London.