Skip to content

Instantly share code, notes, and snippets.

@mshock
Created February 9, 2013 00:11
Show Gist options
  • Save mshock/4743082 to your computer and use it in GitHub Desktop.
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
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