Created
February 9, 2013 00:11
-
-
Save mshock/4743082 to your computer and use it in GitHub Desktop.
Convert a Gregorian calendar date to Julian date number (JDN) in Perl
faster, less overhead than using any Date packages from CPAN
straight from the Wikipedia algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub julianify { | |
my ( $year, $month, $day ) = @_; | |
my $a = int( ( 14 - $month ) / 12 ); | |
my $y = $year + 4800 - $a; | |
my $m = $month + 12 * $a - 3; | |
return | |
$day | |
+ int( ( 153 * $m + 2 ) / 5 ) | |
+ 365 * $y | |
+ int( $y / 4 ) | |
- int( $y / 100 ) | |
+ int( $y / 400 ) | |
- 32045; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment