in reply to Re: Date::Manip and daylight savings
in thread Date::Manip and daylight savings
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Date::Manip and daylight savings
by SBECK (Chaplain) on Nov 07, 2011 at 15:42 UTC | |
I'm afraid I have to disagree here. I fail to see why 'switch to DateTime' is the correct answer. The fact of the matter is that 1 hour before 1:00 AM on a certain date was also 1:00 AM. Date::Manip is doing it right. The reason that the information doesn't look right is that the date is only partially being printed out (i.e. no timezone information). You could always print out the dates as timestamps (seconds since the epoch) or you could print the date in UTC time (which doesn't use daylight saving time), or there are alternate answers depending on what you're really trying to do. As for the second question (i.e. subtract one day), the answer is a bit trickier. The problem really is 'what do you mean by 1 day ago'. If you say 'the same time the day before', that's ambiguous twice a year. When you move the clock back (as we just did), the time 1:00 AM to 2:00 AM happens twice, so if you start at 1:30 AM the day after and move back 1 day, do you mean 1:30 AM in standard time or saving time? Worse, when you move the clock forward, you bypass 1:00 AM to 2:00 AM, so if you start at 1:30 AM the following day and move back 1 day, if you specify 1:30 AM, you have an invalid date. Date::Manip defines a day as 24 hours which DOES lead to unexpected results... but it DOES lead to unambiguous and correct results. It would be possible to come up with another definition for '1 day'... and I'm definitely considering it (just as soon as I have a definition which is meaningful and useful).. So, again, I'm sorry. The correct answer is NOT to switch to DateTime. The correct answer is to figure out what you really want, and then do it. I assure you that both Date::Manip and DateTime are flexible enough to do what you want. | [reply] |
by BrowserUk (Patriarch) on Nov 07, 2011 at 16:02 UTC | |
Bravo! More simply put, if the OP uses DateTime and does the same thing, he'll get the same result. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
by ikegami (Patriarch) on Nov 07, 2011 at 21:41 UTC | |
For those interested, DateTime has no such false equivalences. DateTime can On the other hand, The passage I quoted makes it sound like Date::Manip doesn't correctly handle some or all of those. Please let me know if it can. | [reply] |
by Anonymous Monk on Nov 07, 2011 at 22:03 UTC | |
From DateTime docs.
| [reply] [d/l] [select] |
by ikegami (Patriarch) on Nov 07, 2011 at 22:08 UTC | |
by SBECK (Chaplain) on Nov 08, 2011 at 12:45 UTC | |
| |
by ChrisDennis (Sexton) on Nov 07, 2011 at 17:28 UTC | |
Yes, a full date/time needs to include the timezone. So why does Date::Manip just return a string that has no timezone in it? Is there a way to make it append the timezone? And yes, the second question depends on what I mean by 'one day ago'. In this case, I mean 'the same time yesterday'. I don't think that's ambiguous: if I'm supposed to turn up to work at 8am on Friday, and do the same on Monday after the change to or from summer time, it's up to me to make the adjustment. In both cases, it's assumed that we're talking about 'local time'. I hoped that Date::Manip would do that if I used 'approximate' mode, but apparently not. Is there another option to get Date::Manip to do what I want? My definition of '1 day' is: 24 hours, unless the period spans the change to/from daylight saving, in which case it's either 23 or 25 hours (in most countries). If I want to go back 24 hours, I can use a delta such as '-0:0:-0:0:24:0:0'. But if I want to go back 1 day, then I feel that '-0:0:-0:1:0:0:0' should do the right thing. cheers Chris | [reply] |
by SBECK (Chaplain) on Nov 07, 2011 at 17:58 UTC | |
If you'll switch to using the Object Oriented interface of Date::Manip, there won't be any problem. The functional interface is limited by being backward compatible with the old version of Date::Manip (which didn't work well with timezones). Look at the man page for Date::Manip for information on how to use it. Then, you would write:
If you want different information, use different printf formats. The 'one day ago' question cannot be defined to be 'the same time yesterday' because that's not guaranteed to exist. The definition that I'm leaning to (when/if I implement it) is:
A definition like that is the only way to handle all of the daylight saving time changes, and I'm strongly considering implementing it (in approximate mode only). It probably gives the results that people expect most of the time (though that one time when the third case kicks in is going to confuse people... but daylight saving time is by definition confusing :-). I won't use the 23/24/25 hour definition because that's even less well defined unless you're strictly talking about midnight to midnight calculations. If you do a 1:30 AM to 1:30 AM day, the rules would be non-intuitive (though you could certainly express the calculation in those terms). One way to get what you want is to do the calculation and then explicitly set the time... but be careful. You can't set the time if to an invalid time in your timezone. | [reply] [d/l] [select] |
by ChrisDennis (Sexton) on Nov 07, 2011 at 18:34 UTC | |