Skip to Content
Former Member

# Leap year

Hi Experts,

Could you please help me write a rule for identifying a leap year?

I could find some details in google that a leap year is evenly divisible by 4, 100 and 400 if not then it is not a leap year.

How to identify via a PCR that a number is evenly divisible. Is there a way?

Rgds,

Arun

##### Add a comment
10|10000 characters needed characters exceeded

### 4 Answers

• Best Answer
Posted on Sep 16, 2015 at 04:19 AM

2 points:

- you should doubke check your logic. This one doesn't make sense (every number divisible by 400 is automatically divisible by 4 and 100 - if your logic was right, the last condition alone would be enough and we had leap years once every 400 years only

- it would probably help, if you share the full business requirement, as it may well be yo don't need to implement such a generic algorithm to achieve your purpose

Kind regards

Sven

##### Add a comment
10|10000 characters needed characters exceeded
• Posted on Sep 15, 2015 at 11:28 PM

Hi Arun

PCR's are like program routines or data flow diagrams with calculations.

Flow will be as below:

[Set Leap Year Flag = NO]

I

v

[Get year part of the date]

I

v

<Year divided year by 4 has a remainder?> -> Exit

I No Yes

v

<Year divided year by 100 has a remainder?> -> Exit

I No Yes

v

<Year divided year by 400 has a remainder?> -> Exit

I No Yes

v

[Set Leap Year Flag = Yes]

Corresponding PCR will need an operation to obtain the year part of a date. DATES is an operation to manipulate dates. If this is not suitable you can adapt the operation to suit your requirements. After getting the year in the NUM (or HRS for a time eval PCR), following will do to find the leap year.

Note here, I have no used any NEXTR. This is just to show the calculation and logic

SCOND=F IF Set leap year lag to NO

ZERO=&YEAR Clear year variable

AMT=1 Set amt = 1

ADDWT&YEAR Add current w/t to year var

NUM\$4 Integral division of year (in NUM filed) by 4

NUM*4 Multiply by 4 to get back original value (if it is divisible)

D NUM? &YEAR Result same as before? (to check for remainder in division)

*

= D NUM\$100 NUM*100 NUM? &YEAR -No;Remainder after division by 100?

= *

= = D NUM\$400 NUM*400 NUM? &YEAR - -No;Remainder after division by 400?

= = *

= = = SCOND=T IF Set leap year flag to yes

In Time eval, you can do similarly using time types instead of variable and operation ADDDB instead of ADDWT. ADDDBxxxxZ sets time type to zero.

Hope this helps.

TAKE A BREAK, IF YOU NEED! THINK!! YOU WILL FIND A SOLUTION!!!

br, JG

Message was edited by: Jagan Gunja

##### Add a comment
10|10000 characters needed characters exceeded
• Former Member

HI Jagan,

Thank you very much for your time And for a detailed explanation.

I Will check this and come back.

Rgds,

Arun

• Posted on Sep 16, 2015 at 09:37 AM

Hi every one

As Sven pointed out, the leap year rules which Arun provided is not correct. I did not look at the veracity of the rules when I posted a solution earlier. The rule is:

In the Gregorian calendar 3 criteria must be taken into account to identify leap years:

• The year is evenly divisible by 4;
• If the year can be evenly divided by 100, it is NOT a leap year, unless;
• The year is also evenly divisible by 400. Then it is a leap year.

See links below

- This is not correct I think.

regards, JG

##### Add a comment
10|10000 characters needed characters exceeded
• Posted on Sep 16, 2015 at 05:15 PM

Hi Arun,

Based upon the Leap Year would you like to give any benefit to the employee after completion of the year.

Please share your business scenario then could be possible give some alternative solutions.

Regards, Sankarsan

##### Add a comment
10|10000 characters needed characters exceeded

### Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.