sub get_long_count { my ($dd, $mon, $yyyy, $bc) = split /-/, $_, 4; $yyyy = (0 - $yyyy) if ($bc eq 'BC'); my $feb = 0; if ( int ( $yyyy / 4 ) == ( $yyyy / 4 ) ) { $feb += 29; } else { $feb += 28; } my $months = { 'JAN' => '31', 'FEB' => "$feb", 'MAR' => '31', 'APR' => '30', 'MAY' => '31', 'JUN' => '30', 'JUL' => '31', 'AUG' => '31', 'SEP' => '30', 'OCT' => '31', 'NOV' => '30', 'DEC' => '31', }; my @month_keys = (keys %months); my $tot_days = $dd; for ($i = 0; $month_keys[$i] ne $mon; $i++) { $tot_days += $months{$month_keys[$i]}; } for ($y = $yyyy; $y >= -3114; $y--) { if ( int ( $y / 4 ) == ( $y / 4 ) ) { $tot_days += 366; } else { $tot_days += 365; } } $tot_days -= 223; my $kin = 0; my $uinal = 0; my $tun = 0; my $katun = 0; my $baktun = 0; $baktun = int ( $tot_days / 144000 ) if ( $tot_days >= 144000 ); $tot_days -= ( $baktun * 144000 ); $katun = int ( $tot_days / 7200 ) if ( $tot_days >= 7200 ); $tot_days -= ( $katun * 7200 ); $tun = int ( $tot_days / 360 ) if ( $tot_days >= 360 ); $tot_days -= ( $tun * 360 ); $uinal = int ( $tot_days / 20 ) if ( $tot_days >= 20 ); $tot_days -= ( $uinal * 20 ); $kin = $tot_days; my $long_count; $long_count = "$baktun.$katun.$tun.$uinal.$kin"; }