Lo que debe aprender Sony y varios programadores sobre el año Bisiesto


Bueno, hace tiempo hice una librería de calendarios y encontré un texto que escribió José Soares (jose at sferacarta.com) respecto a la historia, y el como, calcular el año bisiesto:

The Julian Day was invented by the French scholar Joseph Justus Scaliger (1540-1609) and probably takes its name from the Scaliger’s father, the Italian scholar Julius Caesar Scaliger (1484-1558). Astronomers have used the Julian period to assign a unique number to every day since 1 January 4713 BC. This is the so-called Julian Day (JD). JD 0 designates the 24 hours from noon UTC on 1 January 4713 BC to noon UTC on 2 January 4713 BC.

The “Julian Day” is different from the “Julian Date”. The Julian date refers to the Julian calendar, which was introduced by Julius Caesar in 45 BC. It was in common use until the 1582, when countries started changing to the Gregorian calendar. In the Julian calendar, the tropical year is approximated as 365 1/4 days = 365.25 days. This gives an error of about 1 day in 128 years.

The accumulating calendar error prompted Pope Gregory XIII to reform the calendar in accordance with instructions from the Council of Trent. In the Gregorian calendar, the tropical year is approximated as 365 + 97 / 400 days = 365.2425 days. Thus it takes approximately 3300 years for the tropical year to shift one day with respect to the Gregorian calendar.

The approximation 365+97/400 is achieved by having 97 leap years every 400 years, using the following rules:

Every year divisible by 4 is a leap year.
However, every year divisible by 100 is not a leap year.
However, every year divisible by 400 is a leap year after all.

So, 1700, 1800, 1900, 2100, and 2200 are not leap years. But 1600, 2000, and 2400 are leap years. By contrast, in the older Julian calendar only years divisible by 4 are leap years.

The papal bull of February 1582 decreed that 10 days should be dropped from October 1582 so that 15 October should follow immediately after 4 October. This was observed in Italy, Poland, Portugal, and Spain. Other Catholic countries followed shortly after, but Protestant countries were reluctant to change, and the Greek orthodox countries didn’t change until the start of the 20th century. The reform was observed by Great Britain and Dominions (including what is now the USA) in 1752. Thus 2 September 1752 was followed by 14 September 1752. This is why Unix systems have the cal program produce the following:

$ cal 9 1752
September 1752
S M Tu W Th F S
1 2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Note: The SQL standard states that “Within the definition of a ‘datetime literal’, the ‘datetime value’s are constrained by the natural rules for dates and times according to the Gregorian calendar”. Dates between 1752-09-03 and 1752-09-13, although eliminated in some countries by Papal fiat, conform to “natural rules” and are hence valid dates.

Different calendars have been developed in various parts of the world, many predating the Gregorian system. For example, the beginnings of the Chinese calendar can be traced back to the 14th century BC. Legend has it that the Emperor Huangdi invented the calendar in 2637 BC. The People’s Republic of China uses the Gregorian calendar for civil purposes. The Chinese calendar is used for determining festivals.

Que en Perl se vería así:

sub Leap_Year {
    my $year = shift;
    if ($year % 400 == 0)  {    # Todo año divisible entre 400 sin remanente
        return 'Bisiesto';      # es Bisiesto forzozamente
    elsif ($year % 100 == 0) {  # Todo año divisible entre 100 NO es bisiesto
        return 'Normal';        # a menos que sea divisible entre 400
    elsif ($year % 4 == 0) {    # Todo año divisible entre 4 es bisiesto a menos
        return 'Bisiesto';      # que sea divisible entre 100
    else {
        return 'Normal';
print Leap_Year($ARGV[0]) . "\n";

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

One thought on “Lo que debe aprender Sony y varios programadores sobre el año Bisiesto

  1. Algo menos ortodoxo pero igual creo que les pudo funcionar :

    function isLeap(int year){ 
       if( year%4==0 && (year%100!=0 || year%400==0 ) )
              return true;
        return false;

Leave a Reply