I am adding to my almanac. Tonight, it is phases of the moon.
I calculate the current lunation cycle (k), then use that to get the dates of the New Moon (0), First Quarter Moon (0.25), Full Moon (0.50), and Last Quarter Moon (0.75). Each of those has a date I want to know.
#!/usr/bin/perl
use Astro::MoonPhase;
package Astro::MoonPhase; use Date::Format;
my $lunation = lunation();
my @dates = map { time2str( "%h %e", $_ ) } map { jdaytosecs( truephase( $lunation, $_ ) ) } ( 0, 0.25, 0.5, 0.75 );
printf "N: %s 1: %s F: %s 3: %s\n", @dates;
sub lunation { my $sdate = jtime( shift || time ); my $k = undef; my $ndate1 = meanphase( $sdate, 0.0, \$k );
$k++ if $ndate < $sdate; return $k; }