Greetings! Given today's day, i would like to calculate 3 additional dates:
- today - one week
- today - one month
- today - one year
This should be simple enough with
Time::Piece, however i have found that i need to adjust the deltas for one month and one year by some very inconsistent amounts of time. Please consider the following code and its output:
use strict;
use warnings;
use Time::Piece;
use Time::Seconds;
my $now = localtime;
print "Today: $now\n";
print " Week: ", $now - ONE_WEEK, $/;
print " Mon: ", $now - ONE_MONTH, $/;
print " Year: ", $now - ONE_YEAR, $/;
print "\n";
print "Today: $now\n";
print " Week: ", $now - ONE_WEEK, $/;
print " Mon: ", $now - ONE_MONTH + (ONE_HOUR * 10) + (ONE_MINUTE * 29
+) + 4, $/;
print " Year: ", $now - ONE_YEAR + (ONE_HOUR * 6) - (ONE_MINUTE * 11)
+- 10, $/;
__DATA__
Today: Fri Oct 2 12:30:17 2015
Week: Fri Sep 25 12:30:17 2015
Mon: Wed Sep 2 02:01:13 2015
Year: Thu Oct 2 06:41:27 2014
Today: Fri Oct 2 12:30:17 2015
Week: Fri Sep 25 12:30:17 2015
Mon: Wed Sep 2 12:30:17 2015
Year: Thu Oct 2 12:30:17 2014
My specific question is why do i have to add 10 hours, 29 minutes and 4 seconds to the delta for last month, and 6 hours minus 11 minutes, 10 seconds to the delta for last year. Surely i am doing something wrong or not taking something into consideration. I have tested this on three separate Linux servers and received the same results.
Thanks in advance!
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)