good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: figuring difference in times?by BigLug (Chaplain) |
on Aug 20, 2005 at 11:12 UTC ( [id://485371]=note: print w/replies, xml ) | Need Help?? |
I'm one of the DateTime developers, so it may surprise you that in this case I'd wonder if you need the entire swiss army knife that is DateTime, or if all you need is a butter knife... DateTime can do many things beside simple duration formatting. It can manipulate dates and time and convert them between timezones to most points in history. You can even convert your dates to the Julian calendar or even Tolkien's shire calendar. But if you don't need all that don't bother with DateTime (but think about it carefully, will you be writing some other code in the future to work with these dates? If so, then use DateTime)
The Butter Knife Start with finding out how many of the largest period (weeks) are in the duration, then subtract that from the duration and move to the next level of precision. In the end you'll be left with seconds.
(Disclaimer: The above code is not golf. There are more compact ways to do it without declaring the constants, but this is to illustrate the procedure)
In Section
Seekers of Perl Wisdom
|
|