Board index » delphi » Leap year function
Mark Shapir
![]() Delphi Developer |
Sat, 24 May 2003 03:00:00 GMT
|
Mark Shapir
![]() Delphi Developer |
Sat, 24 May 2003 03:00:00 GMT
Leap year function
Can someone please provide a function that determines whether the
current year is a leap year. |
Gary Darb
![]() Delphi Developer |
Sat, 24 May 2003 03:00:00 GMT
Re:Leap year functionWell, leap years are every 4 years, except every 100 years which are not, except every 400 years which are. So I think this should do it? function LeapYear(year:integer):boolean; "mod 4=0" is true for every 4th year, "mod 100>0" is true except for 100 ________________________ Quote"Mark Shapiro" <info...@swbell.net> wrote in message Quote> Can someone please provide a function that determines whether the |
Stephen Pos
![]() Delphi Developer |
Sun, 25 May 2003 11:35:32 GMT
Re:Leap year functionOn Tue, 05 Dec 2000 17:49:30 -0600, Mark Shapiro <info...@swbell.net> wrote: Quote>Can someone please provide a function that determines whether the SysUtils, to find out if THIS year is a leap year you can use (copied from the on-line help): function IsThisLeapYear: Boolean; If you're using pre-D3 then the algorithm is pretty straightforward: If the year is divisible by 4, and not divisible by 100; unless it's function IsLeapYear(Year: Word): Boolean; HTH Stephen Posey |
Rob Sto
![]() Delphi Developer |
Sun, 25 May 2003 13:50:48 GMT
Re:Leap year functionQuoteStephen Posey wrote: And I've always been a little curious about the range of years for which Rob |
Eddie O'Brie
![]() Delphi Developer |
Sun, 25 May 2003 03:00:00 GMT
Re:Leap year functionHere is some code I've just copied from one of my C++ files (sorry about the cultural clash). I'll try a translation into Delphi on the fly Boolean Date::leapYear(short y) Quote} function isLeapYear(const year : integer) : boolean QuoteMark Shapiro <info...@swbell.net> wrote in message Quote> Can someone please provide a function that determines whether the |
M.H. Avegaar
![]() Delphi Developer |
Sun, 25 May 2003 03:00:00 GMT
Re:Leap year functionWhy would you want to know if any date BC was a leap year? The Georgian calendar was introduced in the 16th century (not sure), so calculating leap years before that time is purely hypothetical. "Rob Stow" <rob.s...@cnnsimail.com> schreef in bericht Quote> Stephen Posey wrote: |
Kent Brigg
![]() Delphi Developer |
Sun, 25 May 2003 03:00:00 GMT
Re:Leap year functionQuoteMark Shapiro wrote: begin leapyear:=(y mod 4=0) and ((y mod 100<>0) or (y mod 400=0)); end; -- |
Dr John Stockto
![]() Delphi Developer |
Sun, 25 May 2003 03:00:00 GMT
Re:Leap year functionJRS: In article <3A2DD48C.E325B...@cnnsimail.com> of Wed, 6 Dec 2000 05:50:48 seen in news:comp.lang.pascal.delphi.misc, Rob Stow Quote<rob.s...@cnnsimail.com> wrote: Leap := (Year and 3) = 0 ; which works for Gregorian and Julian Calendar Years in [1901..2099]. Depending on implementation, "and 3" is likely to equal or beat "mod 4". For UK Inland Revenue Years, and for other financial years which start About the fastest full Gregorian Calendar rule (in BP7) is function Z00(Y : word) : boolean ; FAR ; // "R := false ; if ... then R := true" is an abomination, as is <URL: http://www.merlyn.demon.co.uk/programs/leapyear.pas> tests many Rob et al : for 1804 BC & suchlike, read <URL: http://www.merlyn.demon. Leap Years were invented around DCCXIII a.u.c, which later turned out to The change to the 4/100/400 rule was in 1582 in Rome & nearby, in 1752 See <URL: http://www.tondering.dk/claus/calendar.html> also; and many <URL: http://www.merlyn.demon.co.uk/programs/tz-check.pas> will show -- |
Bruce Robert
![]() Delphi Developer |
Sun, 25 May 2003 03:00:00 GMT
Re:Leap year functionThanks for the explanation. |
Dr John Stockto
![]() Delphi Developer |
Sun, 25 May 2003 03:00:00 GMT
Re:Leap year functionJRS: In article <90ku7u$or...@porthos.nl.uu.net> of Wed, 6 Dec 2000 09:43:12 seen in news:comp.lang.pascal.delphi.misc, M.H. Avegaart Quote<avegaartNOS...@mccomm.nl> wrote: Not Georgian but Gregorian; 1582; but that only added the 100 & 400 year The tests for divisibility by 4, 100, 400 should be performed in that -- |
Stephen Pos
![]() Delphi Developer |
Mon, 26 May 2003 12:00:32 GMT
Re:Leap year functionOn Wed, 06 Dec 2000 05:50:48 GMT, Rob Stow <rob.s...@cnnsimail.com> wrote: Quote>Stephen Posey wrote: thanks for catching that. Quote>And I've always been a little curious about the range of years for which its reconing beyond when it was actually in use. If you're into such things Lance Latham's book "Standard C Date/Time Stephen Posey |
Nicolas Bronk
![]() Delphi Developer |
Mon, 26 May 2003 03:00:00 GMT
Re:Leap year functionWhy everybody programs things again? Why do not simply use { IsLeapYear determines whether the given year is a leap year. } of Borlands Unit SysUtils? Regards |
Michael Winte
![]() Delphi Developer |
Mon, 26 May 2003 03:00:00 GMT
Re:Leap year functionMark Shapiro schrieb: Quote> I needed this function to perform computations based on the number of the value i := MonthDays[IsLeapYear(theYear), theMonth]; -Michael |
Michael Winte
![]() Delphi Developer |
Mon, 26 May 2003 03:00:00 GMT
Re:Leap year functionMark Shapiro schrieb: Quote> I needed this function to perform computations based on the number of i := MonthDays[IsLeapYear(theYear), theMonth]; -Michael |
Dr John Stockto
![]() Delphi Developer |
Mon, 26 May 2003 03:00:00 GMT
Re:Leap year functionJRS: In article <b6fv2tg15ucrg62c8nneniu7c5avlgo...@4ax.com> of Thu, 7 Dec 2000 10:41:34 seen in news:comp.lang.pascal.delphi.misc, Mark QuoteShapiro <info...@swbell.net> wrote: You could compare Round(EncodeDate(Y,3,1)-EncodeDate(Y,2,1)); But Result := 28+Ord((fYear and 3)=0) should be much quicker, and Borland's IsLeapYear implements Result := -- |