Menu

Unlocking a door at midnight in someone else's time zone, with nothing but Intl
📰

Unlocking a door at midnight in someone else's time zone, with nothing but Intl

DEV Community: serverless·work wll·3 days ago
#FJvL6dkN
#devtoserverless#devto#dev#calendar#doors
Long article (813 words) — no AI summary yet.
Reading 0:00
15s threshold

I built a small Christmas side project this year: an online advent calendar that friends fill. You create a calendar, share one link, and each friend hides a note, photo, song or voice message behind one of 24 doors. The owner opens one door a day until Christmas Eve.

The rule that sounds trivial is "door 9 opens on December 9". The question is: December 9 where ? The friends filling the doors are in different countries, the server runs on Cloudflare's edge in whatever data centre is closest, and the person opening the doors expects their own midnight. Here's how that ended up working, with no date library at all.

Store the owner's time zone, not an offset

When a calendar is created, the browser sends its IANA time zone:

let tz = "UTC" ; try { tz = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ; } catch ( e ) { } // "Europe/London" await fetch ( "/api/calendars" , { method : "POST" , headers : { "content-type" : "application/json" } , body : JSON .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.