Hill, Ronald wrote:
> 
> Hi Flavio,
> 
> [snipped]
> 
> > I agree.
> >
> > I think that this is a better way to do it, because it keeps DateTime
> > object inheritance and it takes care of 'locale' and other internals:
> >
> >     my $tmp_dt1 = $dt->clone->truncate( to => 'day' );
> 
> I don't know why, but this will not work:(
> I added this and the times that were generated were incorrect

Oops. That's my fault.
This truncates to current timezone midnight - it's different from the
UTC midnight!

This is the right way to do it, I think:

    my $tmp_dt1 = $dt->
         clone->
         set_time_zone( 'UTC' )->
         truncate( to => 'day' );
    $tmp_dt1->set_time_zone( $tz ) 
         unless $tz->is_floating;

> >
> >     # $tmp_dt1->set_time_zone( 'UTC' )
> >     #     if $tmp_dt1->time_zone->is_floating;
> >
> >     my $rise_time = $tmp_dt1 + $rise_dur;
> >     my $set_time  = $tmp_dt1 + $set_dur;
> >     return ( $rise_time, $set_time );
> 
> Here is what I ended up doing
> 
>     my $rise_time = $tmp_dt1 + $rise_dur;
>     my $set_time  = $tmp_dt1 + $set_dur;
>     my $tz = $dt->time_zone;
>     $rise_time->set_time_zone($tz) unless $tz->is_floating;
>     $set_time->set_time_zone ($tz) unless $tz->is_floating;
>     return ( $rise_time, $set_time );

That's ok.
Maybe you could set the 'locale' too, just in case.

However, it does not keep the object class, in case you are not using
DateTime.
This may be a problem for DT::Calendar::Hebrew and others.

- Flavio S. Glock

Reply via email to