Thanks Zefram. To combat this issue in the future, should we be storing our customer's event information in our DB in GMT and doing all calculations using GMT? or store in their local TZ and calculate with local TZ? Our servers are all GMT if that makes any difference.

Thanks,
Matthew

Zefram wrote:
Matthew wrote:
$dt->set_time_zone("US/Central");

print "+9weeks CST: " . $dt->epoch . " - " . $dt->datetime . "\n";

This is wrong.  "US/Central" doesn't refer to CST specifically.  It refers
to the US central timezone *including DST switches*.  The date it's
showing is in CDT, not CST.  Try displaying $dt->time_zone_short_name
as well, which will show what's going on.

Many of these events were created before the DST switch. How should I be calculating these event dates so that 4PM 2 weeks ago still shows as 4PM tomorrow?

Do the ->add with the timezone already set.  Thus:

#!/usr/bin/perl
use DateTime;
my $dt = DateTime->from_epoch(epoch => 1168812000, time_zone => 'GMT');
print "Date in GMT: " . $dt->epoch . " - " . $dt->datetime . " " . 
$dt->time_zone_short_name . "\n";
$dt->set_time_zone("US/Central");
print "Date in cen: " . $dt->epoch . " - " . $dt->datetime . " " . 
$dt->time_zone_short_name . "\n";
$dt->add(weeks => 9);
print "+9weeks cen: " . $dt->epoch . " - " . $dt->datetime . " " . 
$dt->time_zone_short_name . "\n";
$dt->set_time_zone("GMT");
print "+9weeks GMT: " . $dt->epoch . " - " . $dt->datetime . " " . 
$dt->time_zone_short_name . "\n";

yields:

Date in GMT: 1168812000 - 2007-01-14T22:00:00 UTC
Date in cen: 1168812000 - 2007-01-14T16:00:00 CST
+9weeks cen: 1174251600 - 2007-03-18T16:00:00 CDT
+9weeks GMT: 1174251600 - 2007-03-18T21:00:00 UTC

-zefram

Reply via email to