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
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
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
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:
See links below
1. Leap Year nearly every 4 years
2. https://en.wikipedia.org/wiki/Leap_year
- This is not correct I think.
3. When is a leap year not a leap year? | Science | The Guardian
4. When is Leap Year? When is the next Leap Day?
5. Leap Year -- from Eric Weisstein's World of Astronomy
regards, JG
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