Re: Funcion determinar dias

From: Fernando Romo <pop(at)cofradia(dot)org>
To: Manuel Sugawara <masm(at)fciencias(dot)unam(dot)mx>
Cc: Julio Rivero <jcrmlima(at)gmail(dot)com>, pgsql-es postgresql <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Funcion determinar dias
Date: 2005-04-28 17:43:37
Message-ID: 427120C9.5030507@cofradia.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

ejemplo en perl y argumentacion:

sub Leap_Year {
my ($year) = @_;
if ($year % 400 eq 0) { # Todo año divisible entre 400 sin
remanente
$months[1][0] = 29; # es Bisiesto forzozamente
} elsif ($year % 100 eq 0) { # Todo año divisible entre 100 NO es
bisiesto
$months[1][0] = 28; # a menos que sea divisible entre 400
} elsif ($year % 4 eq 0) { # Todo año divisible entre 4 es
bisiesto a menos
$months[1][0] = 29; # que sea divisible entre 100
}
}

#==========================================================================================#
# Checa año bisiesto conforme al documento de José Soares
(<jose(at)sferacarta(dot)com>) #
#==========================================================================================#
# 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.
#
#
#
# "Julian Day" is different from "Julian Date". The Julian calendar 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 this century. The reform was observed by
Great Britain and #
# Dominions (including what is now the USA) in 1752. Thus 2 Sep 1752 was
followed by 14 #
# Sep 1752. This is why Unix systems have cal 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 #
#
#
# 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. Chinese calendar is used for determining
festivals. #
#==========================================================================================#

Hacerlo en pl_sql debe ser sencillo

Saludos... EL Pop

Manuel Sugawara wrote:

>Julio Rivero <jcrmlima(at)gmail(dot)com> writes:
>
>
>
>>Hola Lista:
>> Una consulta, algo rápida, alguien sabe si PG tiene alguna funcion para
>>determinar si un año es bisciesto???,
>>
>>
>
>No creo, pero es trivial de hacer, algo como
>
>create or replace function bisisesto(int) returns boolean as $$
>begin
> if (((($1 % 4) = 0) AND (($1 % 100) <> 0)) OR (($1 % 400) = 0)) THEN
> return true;
> end if;
> return false;
>end;
>$$ language 'plpgsql';
>
>
>Saludos,
>Manuel.
>
>---------------------------(fin del mensaje)---------------------------
>TIP 9: el optimizador ignorará el uso de recorridos de índice si los
> tipos de datos de las columnas no coinciden
>
>
>

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2005-04-28 18:24:51 Re: Ayuda con Check (listo)
Previous Message Manuel Sugawara 2005-04-28 17:26:02 Re: Ayuda con Check (listo)