Ok. I've been hammering my head against the wall on this one for hours now and can't figure it out. Thank you to the frackin United States Government for changing time before everyone else.

---BEGIN SNIPLET---
#!/usr/bin/perl

use DateTime;

# Jan 14th 16:00 CST = Jan 14th 22:00 GMT
#
# Jan 14th 22:00 GMT = 1168812000

my $dt = DateTime->from_epoch(epoch => 1168812000, time_zone => 'GMT');

print "Date in GMT: " . $dt->epoch . " - " . $dt->datetime . "\n";

$dt->add(weeks => 9);

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

$dt->set_time_zone("US/Central");

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

OUTPUT:
Date in GMT: 1168812000 - 2007-01-14T22:00:00
+9weeks GMT: 1174255200 - 2007-03-18T22:00:00
+9weeks CST: 1174255200 - 2007-03-18T17:00:00

Isn't that wrong? Why isn't it showing 16:00 for CST?

A better question would be: What's the correct procedure for doing these date/time calculations with respect of DST? I've got a database table full of customer's events that are stored in their local time zone. I also have their local time zone stored.

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?

Running DateTime 0.36.

Thanks,
Matthew

Reply via email to