For posterity... or as long as these mailing lists are archived.

my $now = DateTime->now(time_zone => 'local');
my $tom = ($now + DateTime::Duration->new(days => 1))->truncate(to =>
'day');
my $seconds_left = $tom->subtract_datetime_absolute($now)->seconds;



On Thu, Jun 19, 2008 at 1:03 PM, Dave Rolsky <[EMAIL PROTECTED]> wrote:

> On Thu, 19 Jun 2008, Jim Spath wrote:
>
>  I'm a bit unclear on how to properly deal with DST when determining the
>> number of seconds left in a day.
>>
>> Here's what I have now:
>>
>> my $now = DateTime->now(time_zone => 'local');
>>
>> my $tom =
>>  ($dt + DateTime::Duration->new(days => 1))->truncate(to => 'day'));
>>
>> my $seconds_left = $tom_dt->epoch() - $dt->epoch();
>>
>> It seems to work fine, but another developer here mentioned that it might
>> not handle DST properly, although he wasn't sure how to do it himself.
>>
>
> There is a method to do subtraction between two datetimes and return the
> difference in seconds, subtract_datetime_absolute(). It handles leap seconds
> and DST properly.
>
> Your method will also work for DST, but it's a little clunky, plus it won't
> work outside the limited range of the epoch.
>
> Generally speaking, you should only use the epoch when you have to interact
> with some non-DateTime module/system that requires epochs. Otherwise stick
> with the DateTime.pm-provided methods for maximum correctness and
> flexibility (and slowness, unfortunately ;)
>
>
> -dave
>
> /*==========================
> VegGuide.Org
> Your guide to all that's veg
> ==========================*/
>

Reply via email to