NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Other Way Round? (Score:1)
Suppose that
DateTimewere the other way round, and defaulted to the local timezone. Then somebody could've made an equivalent blog post to yours but comparingDateTime->nowwithgmtimeand complaining that they are different!There are 2 different possible behaviours. Obviously the module can only do 1 of them by default.
I've been inconvenienced the other way round, when I discovered that our MySQL database was storing timestamps in local time rather than UTC and not storing the timezone.
Re:Other Way Round? (Score:2)
Sure, that doesn't mean that everyone should expect that or that the developers of DateTime are morons. They ju
Re:Other Way Round? (Score:1)
Except that it isn't — it's more like floating time, because it doesn't also note the timezone. That's just wrong, because it means that MySQL's timestamps don't map to a particular moment in time, but to several possible moments. And even if you know the physical location, because of daylight-saving time that isn't good enough.
I don't mind at all which timezone MySQL uses to display its times. And I certainly don't care how it stores them internally. But I do care that if I tell it to note an event as having just occurred that it records sufficient information about when 'now' is such that when I later ask it for when that event happened it can give me an answer which unambiguously refers to just 1 moment in time.
So in practice that means you have to know the timezone of stored times. That can either be explicit (by storing a timezone with every time) or by being documented that all times are in UTC (or some other ‘standard’).
But it is doing the same! Calling
DateTime->nowis constructing an object which unambiguously refers to the current moment in time. There are lots of ways of displaying that. By default it happens to display in UTC, but that's to do with how the data is displayed, not which moment is being represented. (And it doesn't seem fair to blame a constructor for the output!) You could also note that it displays the date by default in ISO8601 format, which has the fields in an order that most humans don't use in their day-to-day lives. Perhaps it should display the date in a more familiar format? But even so that wouldn't affect which date is being displayed.Consider this one-liner:
Note how the time initially stored is in UTC, but is (internally) labelled as such — because when you tell it which timezone you wish to view the time in you are not merely applying a timezone label to an existing floating time (which would result in the time staying the same in the subsequent
printstatement), but telling it which view of the already-stored moment you are interested in.This isn't unusual behaviour. If you do
my $num = 0x10then Perl stores the actual integer to which you're referring (sixteen), not the digits one and zero. If you try to print it you'll get 16 by default. If you want that integer displayed in a different base then there are ways of specifying that. But 0x10 and 16 are undoubtedly the same integer. And now is undoubtedly now, regardless of the number of ways of writing it.Do you know where in the world I am? If not you might find it confusing if I just gave you a time in my local timezone (which is different from yours) without telling you what that was.
And while most of the time if somebody asked me the time I wouldn't give them the timezone (because I'd presume they know which timezone I'm in), if somebody happened to ask me the time on the day that the clocks change for daylight saving then I'd probably clarify my answer by stating explicitly which time I was referring to.
I'd be satisfied if MySQL only stored timezone information with times that are potentially ambiguous (that hour when the clocks go back every autumn); that's the minimum required. But surely it's better to be consistent, and simpler for everybody involved, if it always included it?
Exactly — whichever you pick, somebody's going to prefer t'other. So
DateTimecan be seen as having arbitrarily chosen one of several ways which would be correct; it's straightforward to get any behaviour you want.Whereas MySQL has chosen a way which is definitely wrong, because if it isn't doing what you want it forgets vital information and there's no way of getting back out of it the information you put in. Which, when you think about it, is a pretty fundamental requirement for a database.
Smylers
Reply to This
Parent
Re:Other Way Round? (Score:2)
You could also note that it displays the date by default in ISO8601 format, which has the fields in an order that most humans don't use in their day-to-day lives.
I do, now, ever since I first used DateTime and thought, "What is that weird format, and why do they use it?"
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers