in reply to Re: Sun Never Sets
in thread Sun Never Sets

It appears to be failing in DateTime::Event::Sunrise.pm because:
if ( $cost >= 1.0 ) { carp "Sun never rises!!\n"; $t = 0.0; # Sun always below altit } elsif ( $cost <= -1.0 ) { carp "Sun never sets!!\n"; $t = 12.0; # Sun always above altit } else {

I might have to submit this as a potential module bug if no one else has encountered this.

Replies are listed 'Best First'.
Re^3: Sun Never Sets
by Anonymous Monk on Mar 17, 2012 at 03:20 UTC

    This is a very old thread, but I found it by googling after I ran into the same bug. I believe that I have found the source of the bug, and a fix.

    In the routine _sunrise_sunset, these lines appear:

    my $sradius = 0.2666 / $sRA; if ($upper_limb) { $altit -= $sradius; }

    Apparently the intent here is to shift the calculation from being referenced to the Sun's midpoint, to its upper limb, by subtracting the angular radius from the desired altitude. However, for some reason the radius variable is divided by the Sun's RA. Near the equinox, this can be arbitrarily close to zero, and so the altitude can become an arbitrarily large negative number, causing the calculation to fail. The fix is to remove the division by $sRA, i.e. just to write

    my $sradius = 0.2666;

    instead. In my test case, that fixed the problem, even with iteration enabled.