My script is far from polished, but I wanted to get it out there before this thing goes down.
Going by the second was slow. Also, I pull back several seconds randomly, so program execution is always different.
#!/usr/bin/perl
use v5.030;
use warnings;
use Astro::Coords;
use Astro::MoonPhase;
use DateTime;
use DateTime::Duration;
use DateTime::Format::ISO8601;
use Log::Log4perl;
my $file = '/home/hogan/Documents/hogan/logs/3.log4perl.txt';
unlink $file or warn "Could not unlink $file: $!";
my $log_conf4 = "/home/hogan/Documents/hogan/logs/conf_files/3.conf";
Log::Log4perl::init($log_conf4); #info
my $logger = Log::Log4perl->get_logger();
## time program
my $now = DateTime->now( time_zone => 'UTC' );
$logger->info("$0 executed at $now");
my $secs_day = 24 * 60 * 60;
# create a DateTime object from an ISO timestring
my $isostr = '2021-10-09T11:13:57'; # jd 2459496.96802
my $dt = DateTime::Format::ISO8601->parse_datetime($isostr);
my @phases = phasehunt( $dt->epoch );
$logger->info("@phases");
my $start_epoch = $phases[0];
my $end_epoch = $phases[4];
my $diff = $end_epoch - $start_epoch;
$logger->info( "lunation is " . $diff / ($secs_day) . " days" );
$logger->info(
"degrees covered per day is " . 360 / ( $diff / ($secs_day) ) . " de
+grees" );
## end prelims for moonphase
## prelims for planets
my $traveler1 = Astro::Coords->new( planet => 'Moon' );
my $traveler2 = Astro::Coords->new( planet => 'Venus' );
my $traveler3 = Astro::Coords->new( planet => 'Jupiter' );
my $moon_ra = 4.15; # values make initial while condition true
my $venus_ra = 4.2; # values make initial while condition true
while ( $moon_ra < $venus_ra ) {
## moon
$traveler1->datetime($dt);
$moon_ra = $traveler1->ra( format => q/deg/ );
## venus
$traveler2->datetime($dt);
$venus_ra = $traveler2->ra( format => q/deg/ );
my $random = rand();
if ( $random > .99 ) {
$logger->info("dt is $dt");
$logger->info("Moon ra is $moon_ra");
$logger->info("venus ra is $venus_ra");
my $rand_seconds = int( 10 * $random );
$dt->subtract( seconds => $rand_seconds );
}
## add a second to what $dt currently holds
$dt->add( minutes => 1 );
}
$dt->subtract( seconds => 30 );
my $hard_bottom = int( $dt->epoch );
$logger->info("integer bottom is $hard_bottom");
$logger->info("Venus conjuntion is at $dt");
$logger->info("Moon ra is $moon_ra");
$logger->info("venus ra is $venus_ra");
my $jt = $dt->clone; #begin where we left off
my $jup_ra = $moon_ra + .03; # kludge to make initial while condition
+true: uff!
$logger->info("jt is $jt");
while ( $moon_ra < $jup_ra ) {
## moon
$traveler1->datetime($jt);
$moon_ra = $traveler1->ra( format => q/deg/ );
## jupiter
$traveler3->datetime($jt);
$jup_ra = $traveler3->ra( format => q/deg/ );
my $random = rand();
if ( $random > .999 ) {
$logger->info("jt is $jt");
$logger->info("Moon ra is $moon_ra");
$logger->info("Jup ra is $jup_ra");
my $rand_seconds = int( 10 * $random );
$dt->subtract( seconds => $rand_seconds );
}
## add a second
$jt->add( minutes => 1 );
}
$jt->subtract( seconds => 30 );
$logger->info("After while loop, jt is $jt");
$logger->info("Moon ra is $moon_ra");
$logger->info("Jup ra is $jup_ra");
my $hard_cap = int( $jt->epoch ) + 1;
my $closed_length = $hard_cap - $hard_bottom;
$logger->info("Closed length is $closed_length");
$logger->info( ", corresponding to " . $closed_length / $secs_day . "
+days" );
## calculate and print Duration object
my $dur2 = DateTime::Duration->new();
$dur2 = $jt->subtract_datetime_absolute($dt);
my $seconds_dur2 = $dur2->seconds;
$logger->info("Transit duration is $seconds_dur2 seconds");
$logger->info( "Transit duration is " . $seconds_dur2 / $secs_day . "
+days" );
my ( $days, $hours, $seconds ) = $dur2->in_units( 'days', 'hours', 'se
+conds' );
$logger->info("DHS is $days days, $hours hours, $seconds seconds");
#$logger->info(
# "DHS is $dur2->days days, $dur2->hours hours, $dur2->seconds second
+s"); failed
use DateTime::Format::Duration;
my $g = DateTime::Format::Duration->new(
pattern => '%Y years, %m months, %e days, '
. '%H hours, %M minutes, %S seconds' );
my $string = $g->format_duration($dur2);
$logger->info("Transit duration is $string");
my ( $days2, $minutes2, $seconds2 ) = map { $dur2->in_units( $_ ) } qw
+[ days minutes seconds ];
#$day_duration = $day + ( $min/60 + $sec/3600 ) /24;
$logger->info("DMS is $days2 days, $minutes2 minutes, $seconds2 second
+s");
## timing for program
my $later = DateTime->now( time_zone => 'UTC' );
my $dur1 = DateTime::Duration->new();
$dur1 = $later->subtract_datetime_absolute($now);
my $seconds_dur = $dur1->seconds;
$logger->info("Program duration is $seconds_dur seconds");
__END__
Results are within 2 minutes of each other. $closed_length used to be just larger than the result, but now I would say it's at the bottom of the interval I think is correct. Typical abridged output
2021/10/14 20:41:23 INFO ./5.vj.pl executed at 2021-10-15T02:41:23
2021/10/14 20:41:23 INFO 1633518344.15928 1634095655.87543 1634741861.
+07993 1635451604.37235 1636060526.50686
2021/10/14 20:41:23 INFO lunation is 29.4234068007215 days
2021/10/14 20:41:23 INFO degrees covered per day is 12.235156942845 de
+grees
2021/10/14 20:41:23 INFO dt is 2021-10-09T11:48:57
2021/10/14 20:41:23 INFO Moon ra is 236.042558888394
2021/10/14 20:41:23 INFO venus ra is 239.223847322906
2021/10/14 20:41:23 INFO dt is 2021-10-09T12:27:48
...
2021/10/14 20:41:24 INFO integer bottom is 1633811226
2021/10/14 20:41:24 INFO Venus conjuntion is at 2021-10-09T20:27:06
2021/10/14 20:41:24 INFO Moon ra is 239.638476569647
2021/10/14 20:41:24 INFO venus ra is 239.630688393583
2021/10/14 20:41:24 INFO jt is 2021-10-09T20:27:06
2021/10/14 20:41:27 INFO jt is 2021-10-11T10:01:06
2021/10/14 20:41:27 INFO Moon ra is 266.010318825404
2021/10/14 20:41:27 INFO Jup ra is 324.860537540057
...
2021/10/14 20:41:33 INFO Moon ra is 315.368348542905
2021/10/14 20:41:33 INFO Jup ra is 324.803321804111
2021/10/14 20:41:35 INFO After while loop, jt is 2021-10-15T09:26:36
2021/10/14 20:41:35 INFO Moon ra is 324.80046766724
2021/10/14 20:41:35 INFO Jup ra is 324.794909591958
2021/10/14 20:41:35 INFO Closed length is 478771
2021/10/14 20:41:35 INFO , corresponding to 5.54133101851852 days
2021/10/14 20:41:35 INFO Transit duration is 478842 seconds
2021/10/14 20:41:35 INFO Transit duration is 5.54215277777778 days
2021/10/14 20:41:35 INFO DHS is 0 days, 0 hours, 478842 seconds
2021/10/14 20:41:35 INFO Transit duration is 0 years, 00 months, 0 day
+s, 00 hours, 00 minutes, 478842 seconds
2021/10/14 20:41:35 INFO DMS is 0 days, 0 minutes, 478842 seconds
2021/10/14 20:41:35 INFO Program duration is 12 seconds
Again one faces questions of validity. A typical value for the conjunction of the moon and jupiter is
I tried to work it up in python, but it could not find the ephem module after I had snapd it in, so I don't know how to check it other than waiting for the values in Stellarium. (Thx karlgoethebier)
Q1) Have we agreed that I'm gonna end up with seconds from DateTime::Duration*, and I might as well roll my own days, hours, minutes, seconds from that? I don't think DateTime can do it because of the vagaries of losing a second in the 70's, for example. (?)
I will be traveling under this moon tomorrow, and I love to watch it from different perspectives as I cross mountian ranges. It rose and set a couple times relative to me the last time I drove this stretch, like a yoyo....