My current project involves me figuring out how long an email took to be delivered.

I send the email with perl, so I have the date handy, no problems there.

I check Gmail to see when it was received, and I can get the Received: header from Gmail to see when it was received, now all I need to do is compare those two.

This is where it gets complicated. I'm in Australia, and Google's date header on the email is like this:

Tue, 31 Oct 2017 15:07:32 -0700 (PDT)

So, I send mail at 09:07:05 Sydney time (Wednesday November 1) and it's received at 15:07:32 (Tuesday October 31) PDT a.k.a. thirty seconds later, but in Californian time. How do I normalise those two times?

I put my $sending_datetime into a DateTime object, and I parse the Gmail date, using DateTime::Format::Mail, into another DateTimeObject (I have to strip the "(PDT)" part or it won't parse). I specifically set the timezone of the two dates to Australia/Sydney and America/Los_Angeles.

Then I get the UTC offset of the two dates, to compare, using DateTime's $dt->offset() method which should give me "the offset from UTC, in seconds, of the datetime object according to the time zone."

Those two values should be a few seconds apart, but I get 39600 for the time sent and -25200 for the time received. What am I doing wrong?

In reply to Comparing DateTime objects in different timezones by Cody Fendant

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.