I'm curious to know if what I'm considering is bad practice, or if since this is a specific and deliberate choice it is actually a decent idea.
I want to store information for dates for events that occur in specific cities. I want to store that data as UTC timestamps.
Wouldn't it be a good idea to simply store the timestamp and the city id/country id (which is associated with a specific timezone), rather than storing the timezone for each event?
I ask because timezones can change, but city IDs would never change in the DB. Once the server is synced with the latest timezone in the (unlikely) event of a timezone change, the event would be independent and unaffected by that change. However, say a timezone changes its boundaries, then events that occurred in that timezone previously could be outside of it.
Does it seem unwise to do this? I'm just wondering, and I've been scouring for best practices but in this case this actually seems like an OK idea. This works particularly because the application design model would never change- events will ALWAYS be associated with a specific city.
The basic flow would be:
Event data with date/location comes into the system in a standard format like ISO-8601 YYYY-MM-DD string.
System converts date to UTC timestamp and stores the date with the event using that timestamp and the city ID for the event.
When a user requests to view that event, the system pulls the timestamp and city information associated with that event, and uses the city's timezone to format the date accordingly on display.
Is this a terrible idea? Is there a benefit to this, and is the concept of storing the TZ Offset the same idea to eliminate this issue?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…