2 ms·
It seems most people resort to storing time in UTC, but this isn't your only option: any fixed time zone will do. If you're in a corporate setting and the major
by taylodl 13y ago
It seems most people resort to storing time in UTC, but this isn't your only option: any fixed time zone will do. If you're in a corporate setting and the majority of your users are in the same time zone as your servers, then it makes sense to use that time zone. There's fewer date conversions that way. For half the year there will be basically no conversions and for the other half it's a 1 hour DST conversion - which many time handling libraries have optimized (I'm in the United States in an area that observes DST for half the year).
- TazeTSchnitzel 13y ago>any fixed time zone will do. Theoretically, yes. In practice, you should just use UTC. >If you're in a corporate setting and the majority of your users are in the same time zone as your servers, then it makes sense to use that time zone. No it doesn't. Use UTC. The Internet does not have a time zone. >There's fewer date conversions that way. Your library is probably "converting" the date anyway, UTC or not. >for the other half it's a 1 hour DST conversion - which many time handling libraries have optimized Is it really that slow to convert a date?
- apaprocki 13y agoStoring datetimes in fixed timezones that do not observe DST will do (but it is still not recommended), but you can't say any fixed timezone will do. Say you're storing datetimes in EST/EDT and you have a global audience. On the day the US goes back to standard time, how do you know whether 1:30AM in your database is the "first" 1:30AM or the "second" 1:30AM when you need to display the event to someone in Dubai? Are you going to store some extra metadata to indicate whether DST was in effect beside the datetime? Just store UTC.
- taylodl 13y agoA fixed time zone doesn't shift for DST, otherwise it wouldn't be fixed - by definition. All you need is a fixed reference point. There's nothing sacrosanct about UTC.
- apaprocki 13y agoIt wasn't clear what 'fixed' was, since that isn't normal terminology. I took 'fixed' to mean "pick a single timezone and stick to it". If you need to pick a timezone which does not observe DST, that rules out (generally speaking) most of North America and Europe and a lot of other places. So maybe you want your new time base to be Asia/Tokyo, Asia/Shanghai, Asia/Kolkata, Europe/Moscow? You're still at the whim of governments who constantly tinker with DST -- sure Europe/Moscow is "fixed" now, but it wasn't as close as 2 years ago. To each their own, but I would not get into the business of depending on any particular zone in tzdata staying as it is currently defined for any amount of time in the future.
- taylodl 13y agoI meant fixed as in unvarying. So we store our time data in EST (UTC-05:00), instead of UTC. For half the year the stored time matches the local time it's to be displayed in and so no conversion is required. The other half of the year when local time is UTC-04:00 we only need to shift the stored time by one hour to display it properly. Many time handling libraries are extremely efficient at adding/subtracting an hour from time. This is important because we have many legacy systems using this data (think mainframe COBOL to today's latest technologies with a smattering of everything in between). So it's not just a single time handling library in use.