/* rexx */ /*-------------------------------------------------------------------*/ /* */ /* REXX Exec : ZELLER */ /* */ /* Description : Calculate the day of the week from a date */ /* */ /* Created on : 12 Dec 2010 */ /* Created by : KEVIN FERGUSON */ /* : Userid(MIT001) */ /* : using ABBYDALE.DEVL.REXX(ZELLER) */ /* */ /* Called by : */ /* */ /* Calls : CLEAR, Proper JUL*/ /* */ /* Change Activity : */ /* */ /* MM/DD/YYYY ID Comment */ /* --------------------------------------------------------------- */ /* 05/29/2021 ALG Changed algorithm to correctly account for */ /* January and February dates. */ /* 05/29/2021 TRC Show calculation if required. */ /* 01/11/2022 JUL Allow for the correct date format for dates */ /* prior to 24th March 1752 */ /* */ /* ©Copyright of Abbydale Systems LLC. */ /* */ /*-------------------------------------------------------------------*/ day.0 = Saturday day.1 = Sunday day.2 = Monday day.3 = Tuesday day.4 = Wednesday day.5 = Thursday day.6 = Friday mon.1 = January mon.2 = February mon.3 = March mon.4 = April mon.5 = May mon.6 = June mon.7 = July mon.8 = August mon.9 = September mon.10 = October mon.11 = November mon.12 = December dd = 99 /* set dummy day */ mm = 99 /* set dummy month */ cal = "Gregorian" /*JUL*/ clear /* <-- If you don't have a clearscreen program remove this JUL*/ Say 'Do you want to see the calculation? (Reply y for trace)' /*TRC*/ Pull trc /*TRC*/ do until dd < 31 Say Day? /* Ask for day */ Pull dd end do until mm < 13 Say Month "(1 - 12)" /* Ask for month */ Pull mm end Say Year (yyyy) /* Ask for year */ Pull yyyy monmon = mm entyyyy = yyyy /*ALG*/ If yyyy < 1752 then do /*JUL*/ cal = "Julian" /*JUL*/ end /*JUL*/ If yyyy = 1752 then do /*JUL*/ if mm <= 3 then do /*JUL*/ if dd <= 24 then do /*JUL*/ cal = "Julian" /*JUL*/ end /*JUL*/ end /*JUL*/ end /*JUL*/ if mm < 3 then do if trc = "Y" then do say 'Month is 'mon.monmon , /*TRC*/ ' so subtract 1 from 'yyyy 'giving' yyyy-1 /*TRC*/ say '' /*TRC*/ say 'Also add 12 to the month ('mm') giving' mm+12 /*TRC*/ end mm = mm + 12 yyyy = yyyy - 1 end temp1 = ((mm+1)*13)%5 /*ALG*/ temp2 = yyyy%4 /*ALG*/ temp3 = yyyy%100 /*ALG*/ temp4 = yyyy%400 /*ALG*/ if trc = "Y" then do /*TRC*/ say '*** Calculate the complicated bits! ***' /*TRC*/ say '' /*TRC*/ say 'This date will use the' cal 'calendar calculation' /*JUL*/ say '' /*JUL*/ say 'The INTeger value of (('mm'+1)x13)/5) =' temp1, /*TRC*/ 'Name it V1' /*TRC*/ say ' mm + 1 =' mm + 1 /*TRC*/ say ' (mm + 1)13 =' (mm + 1)*13 /*TRC*/ say ' Int value of (mm + 1)*13/5 =' temp1 ' so V1='temp1 /*TRC*/ say '' /*TRC*/ say 'The INTeger value of year/4 =' temp2 'Name it V2' /*TRC*/ say ' Int value of 'yyyy'/4 =' temp2 ' so V2='temp2/*TRC*/ say '' /*TRC*/ if cal = "Gregorian" then do /*JUL*/ say 'The INTeger value of year/100 =' temp3 'Name it V3' /*TRC*/ say ' INT value of year/100 =' temp3 'so V3='temp3 /*TRC*/ say '' /*TRC*/ say 'The INTeger value of year/400 =' temp4 'Name it V4' /*TRC*/ say ' INT value of year/400 =' temp4 'so V4='temp4 /*TRC*/ end /*JUL*/ v1 = temp1 /*TRC*/ v2 = temp2 /*TRC*/ v3 = temp3 /*TRC*/ v4 = temp4 /*TRC*/ say '' /*TRC*/ say '*** End of complicated bits! ***' /*TRC*/ say '' /*TRC*/ If cal = "Gregorian" then do /*JUL*/ say 'Add day + V1 + Year + V2 - V3 + V4 =' temp1, /*TRC*/ 'Name it TOT1' /*TRC*/ say ' 'dd' +' v1 '+' yyyy '+' V2 '-' V3 '+' V4 '=' temp1 /*TRC*/ say '' /*TRC*/ end /*JUL*/ else do /*JUL*/ say 'Add day + V1 + Year + V2 + 5 =' temp1, /*JUL*/ 'Name it TOT1' /*JUL*/ say ' 'dd' +' v1 '+' yyyy '+' V2 - 5 '=' temp1 /*JUL*/ say '' /*JUL*/ end /*JUL*/ TOT1 = temp1 /*TRC*/ end /*TRC*/ If cal = "Gregorian" then do /*JUL*/ temp1 = dd+temp1+yyyy+temp2-temp3+temp4 /*ALG*/ end /*JUL*/ else do /*JUL*/ temp1 = dd+temp1+yyyy+temp2 + 5 /*JUL*/ end /*JUL*/ /* if yyyy <= 1752 then do if trc = "Y" then do /*TRC*/ Say 'If the date is before 24th March 1752 then add 11 to TOT1'/*TRC*/ say '' /*TRC*/ end /*TRC*/ temp1 = temp1 + 11 end if yyyy = 1752 then do if mm <= 3 then do if mm = 3 then do if dd <= 24 then do temp1 = temp1 - 11 end end temp1 = temp1 + 11 end end */ temp4 = temp1%7 temp2 = temp4*7 temp3 = temp1-temp2 if trc = "Y" then do /*TRC*/ say 'Calculate the remainder (MOD) of' TOT1, /*TRC*/ 'divided by 7 =' temp3 /*TRC*/ say '' /*TRC*/ say 'The remaining number corresponds to the day of the week' /*TRC*/ say '' /*TRC*/ say 'In this case the remaining number is' temp3 /*TRC*/ say '' /*TRC*/ say 'Which corresponds to a 'Proper(day.temp3) /*TRC*/ say '' /*TRC*/ end /*TRC*/ say Proper(day.temp3) dd Proper(mon.monmon) entyyyy /*ALG*/ exit /*-------------------------------------------------------------------*/ /* End of ZELLER */ /*-------------------------------------------------------------------*/