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)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.