3 ms·
There is no such thing as a time without a timezone. There is no such thing as 11:23 am. There are in fact at least 30 11:23ams on any given day. If I was desi
by jerf 17y ago
There is no such thing as a time without a timezone. There is no such thing as 11:23 am. There are in fact at least 30 11:23ams on any given day.
If I was designing a datetime library, it would raise an exception if you tried to give it a time without a timezone. There would be no implicit timezones, no default arguments.
If you think this is being pedantic... you've clearly never worked with times coming from multiple timezones at once, and, as this article shows, you probably live in UTC since even within one timezone you tend to get different defaults between localtime and UTC. And everybody gets incorrectly-set machines with just-flat-wrong timezones and correspondingly skewed clocks.
If you ever parse a time without a timezone, that's a bug. If you have a time and you can't parse it because you don't know the timezone, that's a bug in whatever is emitting the time.
IMNSHO, this is right up there with "there is no such thing as a string without an encoding" in importance.
- mbrubeck 17y agoI agree with the sentiment, but there are a lot of more complicated scenarios in real-world applications. For example, most calendar apps need the concept of a "floating timezone": I may have one item on my schedule called "nap time" with a time of 15:00 (no time zone). I want my computer to tell me to take a nap at 15:00 local time, no matter where in the world I am today. But I have another item on my schedule called "conference call with CEO" with a time of 13:30 PDT. I want that call to happen at a specific absolute time (not local time).
- jerf 17y ago'For example, most calendar apps need the concept of a "floating timezone":' Ok... but that's a timezone, too, at least from the point of view I'm talking about. It's not an ill-defined 11:00am, it's a specific 11:00am. The root problem is specifications that match more than one uniquely-defined time.
- arohner 17y agoJoda time has this concept, it calls it a partial http://joda-time.sourceforge.net/key_partial.html http://joda-time.sourceforge.net/key_partial.html . A partial is a datetime without a time zone, so it only partially specifies a time. You can combine a partial with a timezone to get an instant, a fully specified date time. It's also interesting to note that some operations cannot be performed with partials. For example, you can't add an instant and a partial (because that would be buggy). In order to add them, you have to first convert the partial to an instant (by specifying a timezone). In the parent's example, nap time would be a partial of 15:00, and your calendar app would notify about nap time by specifying the current timezone of the computer.
- kragen 17y agoYou know, when I write down the times of meetings or flights in my paper notebook with a pencil, it doesn't give me error messages because it doesn't know what timezone they're in. Sometimes they're in Argentine time, sometimes they're in California time, sometimes they're somewhere else. Sometimes I do write down a timezone because there's the potential for confusion, and other times I don't. Your comment is a recipe for writing software that is worse than my paper notebook, in the sense that I would prefer to use the paper notebook.
- scott_s 17y agoExcept his comment is about writing a datetime library. An application could provide reasonable defaults.
- kragen 17y agoProviding a default timezone would also be worse than my paper notebook, because it would mean that some of the times I enter would be assigned to the incorrect timezone, which means they'd be assigned to the incorrect absolute time. It's a recipe for automatically falsifying data as soon as it's entered!
- scott_s 17y agoThen your paper notebook is also implicitly incorrect, since you have not recorded complete information anywhere.
- Confusion 17y agoI call bullshit. As you already point out, timezones are only relevant if you have to deal with times from multiple timezones. In practice, most applications and most people do not have to deal with that and it's a pure waste of time to add timezone handling. Dealing with dates and times is enough of a headache without taking care of timezones and daylight saving times. I'll be damned if I make my code harder to understand and more complex than strictly necessary to do it's job and the jobs it may reasonably be expected to do in the future. You're not just being pedantic: your encouraging massive overengineering.
- jerf 17y agoIt's not overengineering. It's easier to deal with times with timezones (probably converting them back to epoch time, but doing so unambiguously). If you've never done date handling correctly before, you may not realize that. It only takes one place where the ambiguity bites you to make up for all the "ease" you got yourself by leaving them off, and you point out the case where the user doesn't even have to change timezones: DST. It doesn't hardly add any lines of code to get it right. It's really no different than arguing "I don't need to know about text encodings"; it's actually easier to do it right the first time than just muddle along. Text encodings and dates are hard because people just muddle along and think they're getting somewhere. Fortunately, it's a lot easier to seal away the pain with datetimes than it is with text encodings.
- arohner 17y ago> most applications and most people do not have to deal with that and it's a pure waste of time to add timezone handling. If your application deals with times at hour resolution or finer, you need to handle timezones, or you will have bugs. Maybe that's ok for your programs, but it's not ok for everyone. >Dealing with dates and times is enough of a headache without taking care of timezones and daylight saving times. You have it exactly backwards. Dates and times are a headache because of timezones and daylight saving times. If everyone worked in UTC time, there would be no corner cases, no converting between timezones, and no half assed timezone implementations. DST causes ambiguity in converting between time representations. > make my code harder to understand and more complex than strictly necessary to do it's job and the jobs it may reasonably be expected to do in the future Time handling is a library problem. The problem is too many library authors think "oh, time handling is easy. I'll just whip this up", when it's really not. I've encountered bugs in the standard libraries of several programming languages and databases. When you have the API properly defined, dealing with timezones is no harder than dealing with timestamps without timezones, because the library only allows you specify things in the correct representation. Joda Time, for Java, http://joda-time.sourceforge.net/ http://joda-time.sourceforge.net/ is the only correct API I've encountered. If you're using a library that hasn't learned the same lessons as Joda, you will have bugs.