Thread: Leap Years

Leap Years

From
Atif Jung
Date:
INFORMIX uses the rleapyear(year) ESQLC function to determine if a year is a leap year or not. Does POSTGRES have an equivalent?
 
Thanks to all.
 
Atif

Re: Leap Years

From
"A. Kretschmer"
Date:
In response to Atif Jung :
> INFORMIX uses the rleapyear(year) ESQLC function to determine if a year is a
> leap year or not. Does POSTGRES have an equivalent?
>  
> Thanks to all.
>  
> Atif

You can create such a function:

create or replace function rleapyear(in year int) returns bool as
$$begin
  if extract( month from ($1::text || '-02-28')::date +
'1day'::interval) = 2
  then
    return true;
  else
    return false;
  end if;
end;
$$language plpgsql;


(I don't know how exactly this function works in INFORMIX, my function
is just a guess)


Regards, Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431  2EB0 389D 1DC2 3172 0C99

Re: Leap Years

From
"Rob Richardson"
Date:
If you are worried about your application still being in use 90 years
from now, you have to take into account the fact that 2100 will not be a
leap year.


Robert D. Richardson
Product Engineer Software

RAD-CON, Inc.
TECHNOLOGY: Innovative & Proven
Phone : +1.440.871.5720 ... ext 123
Fax:  +1.440.871.2948
Website:  www.RAD-CON.com
E-mail:  rob.richardson@RAD-CON.com


Re: Leap Years

From
Andreas Kretschmer
Date:
Rob Richardson <Rob.Richardson@rad-con.com> wrote:

> If you are worried about your application still being in use 90 years
> from now, you have to take into account the fact that 2100 will not be a
> leap year.

Right:

test=*# select rleapyear(2100);
 rleapyear
-----------
 f
(1 Zeile)


Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

Re: Leap Years

From
Jasen Betts
Date:
On 2010-02-25, Atif Jung <atifjung@gmail.com> wrote:
> --0016e6daaff9970fd004806fd4d9
> Content-Type: text/plain; charset=ISO-8859-1
>
> INFORMIX uses the rleapyear(year) ESQLC function to determine if a year is a
> leap year or not. Does POSTGRES have an equivalent?

not yet.

CREATE FUNCTION rleapyear(integer) RETURNS BOOLEAN AS $$
 select extract( day from ( $1 || '-02-28' ) :: date + '1 day'::interval) != 1
$$ LANGUAGE SQL;

it does now!  years less than 1900 may give non-useful results locale
dependant, years less that 1600 will not work right.

I can't immagine when a function like that would be more useful than
just doing date arithmetic using intervals.


Re: Leap Years

From
Jasen Betts
Date:
On 2010-02-25, Rob Richardson <Rob.Richardson@rad-con.com> wrote:
> If you are worried about your application still being in use 90 years
> from now, you have to take into account the fact that 2100 will not be a
> leap year.

this is beauty of implementing it using date arithmetic all the
horrible wrinkles are someone elses resposibility, and have been
well tested.