Post Reply 
Leap Year Test
10-13-2017, 06:37 PM (This post was last modified: 10-13-2017 10:38 PM by StephenG1CMZ.)
Post: #5
RE: Leap Year Test
Although years are often considered integer, sometimes it is useful in astronomy to use a real value. Both of the above suggestions fail with 1984.2 (representing 2/10 of the way through 1984) and 1984.1122 (in YYYY.MMDD format).

To avoid this I'd take the integer part of a year.
This works for YYYY, YYYY.decimal and YY.MMDD.

Code:


 EXPORT IsLeapYear(Year)
 BEGIN
  LOCAL YY:=IP(Year);

  IF FP(YY/4) ≠ 0 OR (FP(YY/100) == 0 AND FP(YY/400) ≠ 0)
  THEN 
   RETURN 0;
  ELSE
   RETURN 1;
  END;
 END;

And can be simplified to:
Code:

 

 EXPORT IsLeapYear(Year)
 BEGIN
  LOCAL YY:=IP(Year);
  RETURN NOT(FP(YY/4) ≠ 0 OR (FP(YY/100) == 0 AND FP(YY/400) ≠ 0));
 END;

I've also avoided DDAYS, which is more complicated (to calculate days it must evaluate a calendar), and might not work with years in real format rather than Prime format.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Leap Year Test - Eddie W. Shore - 10-13-2017, 01:36 AM
RE: Leap Year Test - Didier Lachieze - 10-13-2017, 03:06 AM
RE: Leap Year Test - chromos - 10-13-2017, 08:33 AM
RE: Leap Year Test - Didier Lachieze - 10-13-2017, 11:31 AM
RE: Leap Year Test - StephenG1CMZ - 10-13-2017 06:37 PM
RE: Leap Year Test - chromos - 10-13-2017, 08:32 PM
RE: Leap Year Test - StephenG1CMZ - 10-13-2017, 10:35 PM
RE: Leap Year Test - David Hayden - 10-13-2017, 09:06 PM
RE: Leap Year Test - ggauny@live.fr - 10-14-2017, 09:33 AM
RE: Leap Year Test - StephenG1CMZ - 10-15-2017, 07:45 PM



User(s) browsing this thread: 1 Guest(s)