http://qs321.pair.com?node_id=1202481

Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

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?