They left the 30th day in choice because the same logic is either handled on 28th or 29th or 30th or 31st (i.e when the indicator shows 'M').
So they don't need 30th to be marked as 'T'.
i.e each account is being reviewed three times in a month for a reporting purpose since they are reviewing it on month-end, the one or two days will not make any difference.
Joined: 26 Nov 2002 Posts: 12373 Topics: 75 Location: San Jose
Posted: Fri Feb 14, 2020 7:32 pm Post subject:
Nic Clouston wrote:
Hi Kolusu
I found the algorithm in a COBOL student book. This is my current Rexx version:
Nic,
I finally got around to test it a bit. Unfortunately this code only works for years 1900 to 2099. Any year before 1900 or years after 2099 , you get incorrect results.
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
Posted: Sat Feb 15, 2020 6:55 am Post subject:
That's OK - I'll be dead long before then! I only use it for my own purposes. i might, though, out of interest, see if I can find that text and check any caveats on it and search to see if I can get a more accurate algorithm. _________________ Utility and Program control cards are NOT, repeat NOT, JCL.
Joined: 26 Nov 2002 Posts: 12373 Topics: 75 Location: San Jose
Posted: Sat Feb 15, 2020 9:21 am Post subject:
Nic Clouston wrote:
That's OK - I'll be dead long before then! I only use it for my own purposes. i might, though, out of interest, see if I can find that text and check any caveats on it and search to see if I can get a more accurate algorithm.
Nic,
The following seems to be working for all the years.
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
Posted: Mon Feb 17, 2020 5:03 am Post subject:
Hmmm. I don't think it was that COBOL book. Trying other books but so far no luck. I did find that for years beginning 21 that there has to be an adjustment by +1 day - ditto for 18xx (-1) and -2 days for 17xx etc. There is a large and complex discussion on another 'forum' which I am going to try to understand. _________________ Utility and Program control cards are NOT, repeat NOT, JCL.
Joined: 26 Nov 2002 Posts: 12373 Topics: 75 Location: San Jose
Posted: Mon Feb 17, 2020 6:33 pm Post subject:
Nic Clouston,
The math forum formula works and here is the DFSORT version for it
Code:
//**********************************************************************
//* Generate the input file for calculating easter for years 1700 thru *
//* 2299 *
//**********************************************************************
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
ABC
//SORTOUT DD DSN=&&IN,DISP=(,PASS),SPACE=(TRK,(50,10),RLSE)
//SYSIN DD *
OPTION COPY
OUTFIL REPEAT=600,
BUILD=(SEQNUM,4,ZD,START=1700)
/*
//**********************************************************************
//* from math forum : *
//* http://mathforum.org/library/drmath/view/52575.html *
//*Below is shown the formula and its application to the year 1999 *
//* *
//*If k = Integer part of [T/100] k = Int[1999/100] = 19 *
//* a = T (mod 19) a = 1999 (mod 19) = 4 *
//* b = T (mod 4) b = 1999 (mod 4) = 3 *
//* c = T (mod 7) c = 1999 (mod 7) = 4 *
//* q = Integer part of [k/4] q = Int[19/4] = 4 *
//* p = Integer part of [(13+8k)/25] p = Int[165/25] = 6 *
//* m = (15-p+k-q) (mod 30) m = 24 (mod 30) = 24 *
//* d = (19a + m) (mod 30) d = 100 (mod 30) = 10 *
//* n = (4+k-q) (mod 7) n = 19 (mod 7) = 5 *
//* e = (2b+4c+6d+n) (mod(7) e = 87 (mod 7) = 3 *
//* *
//*If d+e <= 9 then D = 22+d+e and M = 3 d+e = 10+3 = 13 *
//* *
//*If d = 29 and e = 6 *
//* then D = 19 and M = 4 (not applicable here) *
//* *
//*If d = 28 and e = 6 and a > 10 *
//* then D = 18 and M = 4 (not applicable here) *
//* *
//*Otherwise D = d+e-9 and M = 4 D = 13-9 = 4, M=4 *
//* *
//*So Easter day in the year 1999 was on April 4th. *
//**********************************************************************
//STEP0200 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DISP=(OLD,DELETE),DSN=&&IN
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
BUILD=(01:1,8)),
IFTHEN=(WHEN=INIT,
OVERLAY=(10:01,4,ZD,DIV,+100,EDIT=(TT), $ k
13:01,4,ZD,MOD,+019,EDIT=(TT), $ a
16:01,4,ZD,MOD,+004,EDIT=(TT), $ b
19:01,4,ZD,MOD,+007,EDIT=(TT), $ c
22:10,2,ZD,DIV,+004,EDIT=(TT), $ q
25:(((10,2,ZD,MUL,+8),ADD, $ p
+13),DIV,+25),EDIT=(TT),
28:((+15,SUB,25,2,ZD,ADD, $ m
10,2,ZD,SUB,22,2,ZD),
MOD,+30),EDIT=(TT),
31:((13,2,ZD,MUL,+19),ADD, $ d
28,2,ZD),
MOD,+30,EDIT=(TT),
34:(+4,ADD,10,2,ZD,SUB, $ n
22,2,ZD),MOD,+07,EDIT=(TT),
37:((+2,MUL,16,2,ZD),ADD, $ e
(+4,MUL,19,2,ZD),ADD,
(+6,MUL,31,2,ZD),ADD,
34,2,ZD),MOD,+07,EDIT=(TT),
40:31,2,ZD,ADD,37,2,ZD,EDIT=(TT))), $ d+e
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
Posted: Tue Feb 18, 2020 10:39 am Post subject:
And here is the updated Rexx version:
Code:
/*- Rexx ------------------------------------------------------------*/
/* */
/* Name : Easter.rex Mode : Interactive */
/* */
/* Author : Nic Clouston Date : February 2020 */
/* */
/* Function : Calculate the date of Easter Sunday for any given year */
/* */
/* Input : Keyboard */
/* */
/* Output : Display of date on screen */
/* */
/* from math forum : */
/* http://mathforum.org/library/drmath/view/52575.html */
/* via https://www.mvsforums.com/helpboards/viewtopic.php?t=12986 */
/* */
/*------------------------------------------------------------ Rexx -*/
Trace 'N'
/* Some constants */
OK = 0
OOPS = 28
/* Program version info */
pgm_version = "10.0" /* OORexx */
this_program = "Easter.rex ("pgm_version")"
exit_msg = this_program" has ended OK"
exit_code = OK
header = "----------------------- Easter Day Calculator -------------------"
Parse Source os .
If Abbrev(os,'W')
Then os = "Win"
Parse Arg year
If year = ''
Then exit_code = getYear()
Else exit_code = editYear()
If exit_code = OK
Then Do
Call doTheMath
Call calcMonthAndDay
Call displayResult
End
end_pgm: NOP
Say exit_msg
Exit edate
/*===================================================================*/
getYear:
/*-------------------------------------------------------------------*/
/* Prompt user for the year that Easter day is to be found for */
/*-------------------------------------------------------------------*/
date_ok = 0
Do While \date_ok
If os = "Win"
Then "CLS"
Else If os = "TSO"
Then "CLEAR"
Say header
Say
Say "Enter year to calculate Easter day for in format ccyy"
Say
Pull year
exit_code = editYear()
End
end_getYear: NOP
Return exit_code
/*===================================================================*/
editYear:
/*-------------------------------------------------------------------*/
/* Prompt user for the year that Easter day is to be found for. */
/*-------------------------------------------------------------------*/
If Datatype(year, 'N') & Length(year) = 4
Then Do
date_ok = 1
exit_code = OK
End
Else
If ¬Datatype(year, 'N')
Then Do
exit_msg = "Error: Year must be numeric"
exit_code = OOPS
End
Else Do
exit_msg = "Error: Year must be 4 digits long"
exit_code = OOPS
End
end_getYear: NOP
Return exit_code
/*===================================================================*/
doTheMath:
/*-------------------------------------------------------------------*/
/* */
/*-------------------------------------------------------------------*/
k = Substr(year,1,2)
a = year // 19
b = year // 4
c = year // 7
q = k % 4
p = (13 + (k * 8)) % 25
m = (15 - p + k - q) // 30
n = (4 + k - q) // 7
d = ((19 * a) + m) // 30
e = ((2 * b) + (4 * c) + (6 * d) + n) // 7
end_doTheMath: NOP
Return
/*===================================================================*/
calcMonthAndDay:
/*-------------------------------------------------------------------*/
/* From the result above calculate the month and day. */
/*-------------------------------------------------------------------*/
Select
When d + e <= 9
Then Do
day = 22 + d + e
month = "March"
End
When d = 29 && e = 6
Then Do
day = 19
month = "April"
End
When d = 28 & e = 6 & a > 10
Then Do
day = 18
month = "April"
End
Otherwise day = d + e - 9
month = "April"
End
edate = month||' '||day
end_calcMonthAndDay: NOP
Return
/*===================================================================*/
displayResult:
/*-------------------------------------------------------------------*/
/* Start generating the output text according to the relation of this*/
/* year to the year being calculated. */
/*-------------------------------------------------------------------*/
this_year = Substr(Date(S),1,4)
If this_year < year
Then time_word = "will be"
Else If this_year = year
Then time_word = "is"
Else time_word = "was"
text = "Easter Sunday "time_word" on:"
If os = "Win"
Then "CLS"
Else If os = "TSO"
Then "CLEAR"
Say header
Say
Say "In "year text edate
Say "***"
Pull .
end_displayResult: NOP
Return
Edited to add windows/TSO screen clear code _________________ Utility and Program control cards are NOT, repeat NOT, JCL.
Last edited by Nic Clouston on Wed Feb 19, 2020 4:01 pm; edited 1 time in total
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
Posted: Wed Feb 19, 2020 5:30 am Post subject:
Ah.
Point 1 - this is rexx on a windows OS hence "CLS". I cut out a load of code that was related as I only use Windows. It is still in the original post.
2 - that would be the NOT symbol (¬) - code page stuff. I cannot edit the code now so could you change it for me please?
3 - I have edate because I have a test harness that calls the routine 100 times uses the date to draw out stats. It would also be used by anything calling the program to get the date. _________________ Utility and Program control cards are NOT, repeat NOT, JCL.
Joined: 26 Nov 2002 Posts: 12373 Topics: 75 Location: San Jose
Posted: Wed Feb 19, 2020 8:12 am Post subject:
Nic Clouston wrote:
2 - that would be the NOT symbol (¬) - code page stuff. I cannot edit the code now so could you change it for me please?
Nic,
Done. I edited the post the reflect the ¬ sign. Btw I checked your profile and you are authorized to edit your posts, so unless you are in a rush or on a mobile device, I don't see the reason for you to not able to edit the posts.
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
Posted: Wed Feb 19, 2020 10:13 am Post subject:
I do see it but didn't look to see if I could - I thought I was only allowed to edit within 10 minutes of posting. Now tht it is mentioned I seem to vaguely remember that this was granted some eons ago in the past.
Anyway - thanks for doing that.
In fact, as I can do the edit myself I may add back the CLS/CLEAR coding. _________________ Utility and Program control cards are NOT, repeat NOT, JCL.
All times are GMT - 5 Hours Goto page Previous1, 2
Page 2 of 2
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum