|laziness, impatience, and hubris|
Re: localtime hour countby nothingmuch (Priest)
|on Apr 09, 2006 at 10:09 UTC||Need Help??|
The problem is that when you subtract $t1 from $t2 you wind up with a number, that is incidentially both the duration that passed, in seconds, *and* a valid epoch number representing a certain date, in this case 5 seconds after the "epoch", which is January 1st, 1970 GMT on UNIX systems. An epoch date is the number of seconds that passed since the epoch (essentially also a form of a duration, but with a well defined base value).
localtime accepts an epoch number representing a date and then calculates that date, converts it to the local time zone, and provides the separate fields (something like the Jan 1, 1970, 1:00:05, that is 5 seconds after the epoch, converted to your timezone). Even if you use gmtime this would still not make sense, because you are talking about a duration, and not a date.
Use DateTime to subtract the two dates, play with duration sanely, and all that, or use simple modular arithmetics:
but note that this conversion is lossy.
You can also use Time::Duration::Object, which is convenient for formatting durations for users as '2 hours, 5 minutes' or '2 minutes, 10 seconds', that is - rounded to a certain number of units.
zz zZ Z Z #!perl