note
parv
<p><i>You should have mentioned "phasehunt" function is from "Astro::MoonPhase" module explicitly for anyone casually following the questions. I found it on a first guess.</i>
</p>
<p>[doc://Astro::MoonPhase#phasehunt()] is documented to accept ...
</p>
<blockquote>
...
the time, expressed as a time returned by the <c>time</c> function. If <c>$seconds_since_1970</C> is omitted, it does <c>phasehunt(time)</c>.
</blockquote>
<p>
... does not list argument of DateTime object. So get the [doc://DateTime#$dt->epoch|epoch] from it to pass to &phasehunt. Can't say if that would actually solve any of your issues.
</p>
<p><i>Updated much later.</i> Adjusted code in case anybody else care to run the original logic|algorithm without Log::Log4perl or its configuration not supplied in OP ...
</p>
<readmore>
<c>
use v5.26; use strict;
use feature qw[ signatures ]; no warnings qw[ experimental::signatures ];
# From https://perlmonks.org/index.pl?node_id=11137457
use Astro::Coords;
use Astro::MoonPhase qw[ phasehunt ];
use DateTime;
use DateTime::Format::ISO8601;
# Not want to divine the configuration file for Log::Log4perl, module used in
# the query.
{
package Log::Log4perl;
sub get_logger( $pkg ) { return bless [], $pkg; }
sub show( @arg ) { warn @arg, "\n"; }
sub debug( $ignore, @rest ) { show( 'DEBUG: ', @rest ); }
sub info( $ignore, @rest ) { show( 'INFO: ', @rest ); }
sub warn( $ignore, @rest ) { show( 'WARNING: ', @rest ); }
sub error( $ignore, @rest ) { die 'ERROR: ', @rest, "\n"; }
}
my $logger = Log::Log4perl->get_logger();
my $now = DateTime->now( time_zone => 'UTC' );
$logger->info( "$0 start time: $now" );
# Juilan date: 2459496.96802.
my $isostr = '2021-10-09T11:13:57';
my $dt = DateTime::Format::ISO8601->parse_datetime($isostr);
show_moon_phases( $dt );
show_moon_venus_travel( $dt, my $show_march = 0 );
my $later = DateTime->now( time_zone => 'UTC' );
my $seconds_dur = $later->subtract_datetime_absolute($now )->in_units( q[seconds] );
my $mess = sprintf q[program run time: %d s], $seconds_dur;
$logger->info( $mess );
exit;
sub show_moon_venus_travel( $dt, $show_travel = undef ) {
my $moon_coord = Astro::Coords->new( planet => 'Moon' );
my $venus_coord = Astro::Coords->new( planet => 'Venus' );
my $jup_coord = Astro::Coords->new( planet => 'Jupiter' );
# NOTE: Need to get the RA based on time, so $coord->datetime_is_unsafe() is
# not called.
for ( $moon_coord, $venus_coord, $jup_coord ) {
# Observation is location dependent.
$_->telescope( 'JCMT' );
}
# values make initial while condition true
my $moon_ra = 4.15;
my $venus_ra = 4.2;
my $jup_ra = 7;
my $adjust_ra = sub { my ( $dt, $coord ) = @_;
$coord->datetime( $dt );
return $coord->ra( 'format' => q[deg] );
};
my @march;
while ( $moon_ra < $venus_ra ) {
( $moon_ra, $venus_ra ) = map $adjust_ra->( $dt, $_ ),
$moon_coord, $venus_coord;
if ( $show_travel ) {
my $random = rand();
if ( $random > .99 ) {
push @march, sprintf qq[- dt: %s Moon RA: %f Venus RA: %f],
$dt,
$moon_ra, $venus_ra ;
}
}
$dt->add( seconds => 1 );
}
my $et = $dt->clone->subtract( seconds => 1 );
my @mess = ( q[March of Moon & Venus ...],
@march,
sprintf( qq[final dt: $dt et: $et Julian equality: %f], $et->jd() ),
sprintf( q[final Moon RA: %f Venus RA: %f], $moon_ra, $venus_ra )
);
$logger->info( join qq[\n ], @mess );
return;
}
sub show_moon_phases( $dt ) {
my @phases = phasehunt( $dt->epoch() );
my ( $start_epoch, $end_epoch ) = @phases[0,4];
my $diff = $end_epoch - $start_epoch;
my $lunation = $diff / ( 24 * 60 * 60 );
my $deg_covered_per_day = 360 / ( $diff / ( 24 * 60 * 60 ) );
my @mess = ( qq[Phasing of the Moon ...],
sprintf( "phase epoch: %s", join q[, ], @phases ),
sprintf( "integer bottom of first phase: %d", int( $start_epoch ) ),
sprintf( "lunation: %f days", $lunation ),
sprintf( "degrees covered per day: %f", $deg_covered_per_day )
);
$logger->info( join qq[\n ], @mess );
return;
}
__END__
INFO: 11137457-program.pl start time: 2021-10-14T05:55:20
INFO: Phasing of the Moon ...
phase epoch: 1633518344.15928, 1634095655.87543, 1634741861.07993, 1635451604.37235, 1636060526.50686
integer bottom of first phase: 1633518344
lunation: 29.423407 days
degrees covered per day: 12.235157
INFO: March of Moon & Venus ...
final dt: 2021-10-09T20:25:47 et: 2021-10-09T20:25:46 Julian equality: 2459497.351227
final Moon RA: 239.630096 Venus RA: 239.630026
INFO: program run time: 59 s
</c>
</readmore>
11137457
11137457