Greetings! Given today's day, i would like to calculate 3 additional dates:

  1. today - one week
  2. today - one month
  3. 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)

In reply to Arithmetic bug within Time:Piece? by jeffa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.