in reply to How do I find the difference in days between two dates, in a cool perl way?
A note on Time::Piece - While I love it, and I use it heavily, the ONE_MONTH constant is fundamentally broken, because there's no such thing as a constant value for a month.
For example:
#!/usr/bin/perl use Time::Piece; use Time::Seconds; my $now = localtime; print sprintf("Now = %s\n", $now->cdate); for (1..12) { $now += ONE_MONTH; print sprintf("Now + %02i months = %s\n", $_, $now->cdate); }
Outputs something like this:
bash-2.05b$ ./broken.pl Now = Mon May 10 15:56:13 2004 Now + 01 months = Thu Jun 10 02:25:17 2004 Now + 02 months = Sat Jul 10 12:54:21 2004 Now + 03 months = Mon Aug 9 23:23:25 2004 Now + 04 months = Thu Sep 9 09:52:29 2004 Now + 05 months = Sat Oct 9 20:21:33 2004 Now + 06 months = Tue Nov 9 05:50:37 2004 Now + 07 months = Thu Dec 9 16:19:41 2004 Now + 08 months = Sun Jan 9 02:48:45 2005 Now + 09 months = Tue Feb 8 13:17:49 2005 Now + 10 months = Thu Mar 10 23:46:53 2005 Now + 11 months = Sun Apr 10 11:15:57 2005 Now + 12 months = Tue May 10 21:45:01 2005
Originally posted as a Categorized Answer.
|
|---|