dgaramond2 has asked for the wisdom of the Perl Monks concerning the following question:
Having spent some time yesterday creating a simple web application which has some date/time stuffs in it, I realized how horrible the Unix API (and thus, PHP's API) and MySQL's date/time handling are. Conversion between month that starts from 0 and 1, year that needs to be substracted/added with 1900, these certainly have bitten (and will continue to bite) people's behind on a regular basis.
Luckily Perl 5.10 will include Time::Piece which will make localtime/gmtime become saner and more straightforward. It even includes many bonuses like leap year- and DST checking, strftime(), simple date calculation, etc.
Unfortunately we can't modify date/time elements in a Time::Piece object, e.g. $t->mon(1) (setting the month to January).
Now on to the quiz question: what would be the simplest and most straightforward way in Perl to, given a Unix timestamp t, returns two Unix timestamps t1 and t2 that are the start and end of day (or week, or month, or year) where t1 <= t <= t2.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Date calculation: start and end of period
by gamache (Friar) on Nov 03, 2007 at 12:57 UTC | |
|
Re: Date calculation: start and end of period
by johngg (Canon) on Nov 04, 2007 at 10:53 UTC | |
|
Re: Date calculation: start and end of period
by Krambambuli (Curate) on Nov 04, 2007 at 19:49 UTC |