Maintaining timestamps for future dates when you know the associated location
Posted by jpluimers on 2021/04/07
For past timestamps (or date-times), as long as you know the associated location, you always know the time zone rule that applies, no matter if you store them in UTC or local time zone.
For future dates, UTC might not be the best option, as you have no knowledge on future time zone rules. There you need to have at least three fields:
- timestamp
- time zone delta
- time zone
- time zone rules version
Timezone needs to be either in UTC or local time zone; the time zone delta then needs to be applied to either go to local time zone or UTC.
Both John Skeet (Twitter/github/site) and Lau Taarnskov (Twitter/github/site) both wrote great articles explaining this in much greater detail:
- [WayBack] Storing UTC is not a silver bullet | Jon Skeet’s coding blog
- [WayBack] How to save datetimes for future events – (when UTC is not the right answer)
The time zone rules version points to the version of the TimeZone database to apply.
Information on the TimeZone database (also known as tzdb, tzdata, the zoneinfo database or IANA time zone database, and Olson database):
- tz database – Wikipedia
- List of tz database time zones – Wikipedia
- [WayBack] Sources for time zone and daylight saving time data
- [WayBack] IANA — Time Zone Database
- Daylight saving time – Wikipedia
- Time zone – Wikipedia
--jeroen






Leave a comment