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?
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Comparing DateTime objects in different timezones
by hippo (Bishop) on Oct 31, 2017 at 23:05 UTC | |
Re: Comparing DateTime objects in different timezones
by tangent (Parson) on Oct 31, 2017 at 23:39 UTC | |
by Cody Fendant (Hermit) on Nov 01, 2017 at 00:03 UTC | |
Re: Comparing DateTime objects in different timezones
by haukex (Archbishop) on Nov 01, 2017 at 10:50 UTC | |
Re: Comparing DateTime objects in different timezones
by thanos1983 (Parson) on Nov 01, 2017 at 08:18 UTC |
Back to
Seekers of Perl Wisdom