#!/usr/bin/env perl use utf8; ############################################################################### # This program computes the Julian Day Number of a date. # # Copyright © 2020 Richard Lesh. All rights reserved. ############################################################################### use Utils; use strict; use warnings; ############################################################################### # This function computes the Julian Day Number or number of # days since November 24, -2413 in the proleptic Gregorian calendar. # Source: https://en.wikipedia.org/wiki/Julian_day#Converting_Gregorian_calendar_date_to_Julian_Day_Number ############################################################################### sub julian_day_number { my ($M, $D, $Y) = @_; my $JDN = int((1461 * ($Y + 4800 + int(($M - 14) / 12))) / 4) + int((367 * ($M - 2 - 12 * (int(($M - 14) / 12)))) / 12) - int((3 * (int(($Y + 4900 + int(($M - 14) / 12)) / 100))) / 4) + $D - 32075; return $JDN; } MAIN: { my $month = 0; my $day = 0; my $year = 0; if (scalar(@ARGV) == 3) { $month = Utils::stoiWithDefault($ARGV[0], 0); $day = Utils::stoiWithDefault($ARGV[1], 0); $year = Utils::stoiWithDefault($ARGV[2], 0); } else { print Utils::messageFormat("Syntax: \{0:s\} month day year", "JulianDay"), "\n"; exit 1; } my $jdn = julian_day_number($month, $day, $year); print Utils::messageFormat("\{0:d\}/\{1:d\}/\{2:d\} = \{3:d\} Julian", $month, $day, $year, $jdn), "\n"; }