Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: How to compare date/times in different timezones?

by Jim (Curate)
on Aug 29, 2011 at 15:48 UTC ( [id://923054]=note: print w/replies, xml ) Need Help??


in reply to Re^3: How to compare date/times in different timezones?
in thread How to compare date/times in different timezones?

Excellent!

The rule of thumb for most date and time calculations is to normalize both moments to UTC first, then perform the math. But in this case, it really only makes sense to compare dates from the perspective of a specific local time. It's easy to imagine a practical application for wanting to know if two moments at two different places in the world occurred on the same date reckoned from Sydney, Australia. It's not as easy to imagine a practical application for wanting to know if two moments occurred on the same date reckoned from UTC, which is abstract. Who would care?

Consider this very light refactoring:

#!perl use strict; use warnings; use DateTime; use DateTime::Format::DateParse; @ARGV == 2 or die "Usage: perl $0 <timestamp 1> <timestamp 2>\n"; my $ts1 = shift; my $ts2 = shift; my $tz = 'Australia/Sydney'; my $dt1 = DateTime::Format::DateParse->parse_datetime($ts1) ->set_time_zone($tz); my $dt2 = DateTime::Format::DateParse->parse_datetime($ts2) ->set_time_zone($tz); my $diff = $dt1->delta_days($dt2)->delta_days(); print "$dt1 delta $dt2 is $diff days\n"; exit 0;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://923054]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-19 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found