Obtaining Day-Of-Week
Author Message
Obtaining Day-Of-Week

Could someone explain to me how to obtain the current day-of-week in
an assembler program?  I'm most interested in /370, but just about any
generation would work...

Thanks
Bill

Tue, 05 May 1998 03:00:00 GMT
Obtaining Day-Of-Week

Quote:

>Could someone explain to me how to obtain the current day-of-week in
>an assembler program?  I'm most interested in /370, but just about any
>generation would work...

I saved this message from another universe a long, long time ago.

Quote:

>Try this:

> (year + year/4 + date of month + factor for month) / 7

>(where year is the last two digits)

>factor for month =

>Jan: 1 (0 if leap year)
>Feb: 4 (3 if leap year)
>Mar: 4
>Apr: 0
>May: 2
>Jun: 5
>Jul: 0
>Aug: 3
>Sep: 6
>Oct: 1
>Nov: 4
>Dec: 6

>Now... when you perform the division shown above, the day of the week
>is determined by the remainder. (We don't care about the rest of the answer)

>Remainder of 1 = Sunday
>Remainder of 2 = Monday
>             3 = Tuesday
>             4 = Wednesday
>             5 = Thursday
>             6 = Friday
>             0 = Saturday

+--------------------------------------------+
|              Michael Quinlan               |

|       http://www.primenet.com/~mikeq       |
|     If it doesn't fit, you must acquit!    |
+--------------------------------------------+

Wed, 06 May 1998 03:00:00 GMT
Obtaining Day-Of-Week

Quote:

>Could someone explain to me how to obtain the current day-of-week in
>an assembler program?  I'm most interested in /370, but just about any
>generation would work...
>Thanks
>Bill

This example, from a prograqm called SHOWMVS (Gilbert Saint-flour),
shows how to extract the day of week of last IPL:

DOW  UNPK  WKCELL1(3),SMCAIDTE+1(2)  YY FROM YY.DDD           YY
PACK  WKCELL1,WKCELL1(2)        YY FROM YY.DDD           YY
CVB   R0,WKCELL1              R0=YEAR
LR    R1,R0                   R1=YEAR
BCTR  R1,0                    R1=YEAR-1
SRL   R1,2                    DIVIDE YEAR-1 BY 4
AR    R1,R0                   ADD RESULT TO NUMBER OF YEARS
ZAP   WKCELL1,SMCAIDTE+2(2)   DDD FROM YY.DDD
SLR   R14,R14                 PREPARE DIVISION
CVB   R15,WKCELL1             R15=DAY
BCTR  R15,0                   R15=DAY-1
AR    R15,R1                  ADD NUMBER OF YEARS
D     R14,=F'7'               DIVIDE BY NUM OF DAYS IN WEEK
MH    R14,=H'9'               MULT BY LEN OF DAY-OF-THE-WEEK
LA    R7,TABLEDAY(R14)        POINT TO DAY-OF-THE-WEEK
TABLEDAY DC    C'Monday   Tuesday  WednesdayThursday '
DC    C'Friday   Saturday Sunday   ',0H'0'
WKCELL1  DS    D                       WORK AREA

====================================================

Spain                  ISOC member - OS/2 Team
====================================================

Thu, 07 May 1998 03:00:00 GMT
Obtaining Day-Of-Week
Cute algorithm... but its just another example of what
doesn't work in the *very* near future!

I do remember seeing something not too long ago and I may
have even saved it(!)  Will give a good look after my
stomach "recovers" from Turkey day ;-)

-michael

: >Could someone explain to me how to obtain the current day-of-week in
: >an assembler program?  I'm most interested in /370, but just about any
: >generation would work...
: I saved this message from another universe a long, long time ago.

: >Try this:
: > (year + year/4 + date of month + factor for month) / 7
: >(where year is the last two digits)
: >factor for month =
: >Jan: 1 (0 if leap year)
: >Feb: 4 (3 if leap year)
: >Mar: 4
: >Apr: 0
: >May: 2
: >Jun: 5
: >Jul: 0
: >Aug: 3
: >Sep: 6
: >Oct: 1
: >Nov: 4
: >Dec: 6
: >
: >Now... when you perform the division shown above, the day of the week
: >is determined by the remainder. (We don't care about the rest of the answer)
: >
: >Remainder of 1 = Sunday
: >Remainder of 2 = Monday
: >             3 = Tuesday
: >             4 = Wednesday
: >             5 = Thursday
: >             6 = Friday
: >             0 = Saturday

--
-----------------------------------------------------

"Just because it worked doesn't mean it works." -- me

Mon, 11 May 1998 03:00:00 GMT
Obtaining Day-Of-Week

Quote:
>    Cute algorithm... but its just another example of what
>    doesn't work in the *very* near future!

>   "Just because it worked doesn't mean it works." -- me

Are you referring to the algorithm in SHOWMVS ?
If yes, what do you mean by "it doesn't work in the future" ?

Thu, 14 May 1998 03:00:00 GMT
Obtaining Day-Of-Week
Not that it has anything to do with day-of-week, but I have a nice little bit of BAL code that
converts Julian-to-Gregorian date without use of a table such as:
DC    P'31'
DC    P'28'         CHANGE TO P'29' FOR LEAP YEAR
DC    P'31'
.......    etc.,etc.,
The code is in the form of an MVS macro but can be used in open code with minor modification.
It will need a little work to handle the millenium, but since I just retired, someone else
can handle that.

code and attach the code to my reply.

Fri, 15 May 1998 03:00:00 GMT
Obtaining Day-Of-Week

: >  Cute algorithm... but its just another example of what
: >  doesn't work in the *very* near future!
: >
: >   "Just because it worked doesn't mean it works." -- me

: Are you referring to the algorithm in SHOWMVS ?
: If yes, what do you mean by "it doesn't work in the future" ?

No, I was not referring to SHOWMVS.  I was referring the
algorithm that had been posted, which was also quoted in
my follow-up...
--
-----------------------------------------------------

"Just because it worked doesn't mean it works." -- me

Fri, 15 May 1998 03:00:00 GMT
Obtaining Day-Of-Week
Quote:

>When Pope Gregory XIII ordered reforms in the 16th century to bring the

calendar in sync with the sun and the seasonal holy days, the lag was 10
days. In his decree introducing the corrected calendar, the  Julian  date of Oct. 5, 1582, became Oct. 15 und>r the new style.

Tbat reminds me of a comment in a subroutine in DMSDDL ASSEMBLE:

*    4. This subroutine is named in honor of pope Gregory XIII
*       for his revision (in the 16th century) of our
*       calendric system, which as a result of his efforts
*       rivalled in accuracy the Mayan calendar of some 800
*       years earlier; and also incidentally in honor of his
*       namesake Gregory I for his supposed contribution to
*       the foundations of plainsong (but see reference 3).
*
* References:
*    1. IBM System/370 Principles of Operation
*    2. Whitaker's Almanack
*    3. Concise Oxford Dictionary of Music
*
**************************************************************
SPACE 1
GREGORY  DS    0H
...

Fri, 22 May 1998 03:00:00 GMT
Obtaining Day-Of-Week

|>   Cute algorithm... but its just another example of what
|>   doesn't work in the *very* near future!
|>
|>   I do remember seeing something not too long ago and I may
|>   have even saved it(!)  Will give a good look after my
|>   stomach "recovers" from Turkey day ;-)
|>
|>   -michael
|>

|> : >Could someone explain to me how to obtain the current day-of-week in
|> : >an assembler program?  I'm most interested in /370, but just about any
|> : >generation would work...
|> : I saved this message from another universe a long, long time ago.

|> : >Try this:
|> : > (year + year/4 + date of month + factor for month) / 7
|> : >(where year is the last two digits)
|> : >factor for month =
|> : >Jan: 1 (0 if leap year)
|> : >Feb: 4 (3 if leap year)
|> : >Mar: 4
|> : >Apr: 0
|> : >May: 2
|> : >Jun: 5
|> : >Jul: 0
|> : >Aug: 3
|> : >Sep: 6
|> : >Oct: 1
|> : >Nov: 4
|> : >Dec: 6
|> : >
|> : >Now... when you perform the division shown above, the day of the week
|> : >is determined by the remainder. (We don't care about the rest of the answer)
|> : >
|> : >Remainder of 1 = Sunday
|> : >Remainder of 2 = Monday
|> : >             3 = Tuesday
|> : >             4 = Wednesday
|> : >             5 = Thursday
|> : >             6 = Friday
|> : >             0 = Saturday
|>
|> --
|>    -----------------------------------------------------

|>    "Just because it worked doesn't mean it works." -- me

The algorithm will work in the future - with a few additions.

1. The "year" refers to the last two digits of the full year. For 1945, use 45.

2. Add the following factors:
17nn : + 4
18nn : + 2
19nn : + 0
20nn : + 6 (or - 2)

3. I learned to do this algorithm in my head forty years ago. You can do modulo 7 reductions after the "year + year/4" to make it easier.  I use the folowing clues to help remember the month factors.

Jan: 1  First
Feb: 4  Cold (4 letters)
Mar: 4  Wind (4 letters)
Apr: 6  Shower (6 letters)
May: 2  May Day (two words)
Jun: 5  Bride (5 letters)
Jul: 7  Cracker (7 letters) (7 Mod(7) = 0)
Aug: 3  Hot (3 letters)
Sep: 6  Autumn (6 letters)
Oct: 8  Eighth (8 mod(7) = 1)
Nov: 4  Cool (4 letters)
Dec: 6  Christ (6 Letters)

Note that the the Gregorian Calendar began on Sept. 14, 1752.  Prior to then, the Julian calendar was used in which every century year was a leap year.  In the Gregorian, only century years evenly divisible by 400 are leap years.

The calendars differ because in Julius Caesar's time in the century before Christ, calculations of the solar year were slightly off - 365.5 days rather
than the precise 365.2421999.

Over the centuries those lagging minutes turned into days.

When Pope Gregory XIII ordered reforms in the 16th century to bring the calendar in sync with the sun and the seasonal holy days, the lag was 10 days. In his decree introducing the corrected calendar, the  Julian  date of Oct. 5, 1582, became Oct. 15 under the new style.

When Britain and its empire adopted the Gregorian system, the date Sept. 3, 1752, under the old calendar became Sept. 14 under the new - a lag of 11 days. Occasional conflicts between old style-new style dates occur. For example, Columbus landed in the New World on Oct. 12, 1492, a date celebrated under the
Gregorian calendar. But some authorities say that's a Julian date that was never changed to the new style. They maintain the new-style date should be Oct. 21.

Many more complications exist for dates prior to Sept. 14, 1752.  For example, from the 7th until around the 13th century, the year was reckoned as beginning at Christmas. In the 12th century, however, the Anglican church took a more seminal approach, worked back one human gestation period from 25 December, and arrived at 25 March as the Feast of the Annunciation, or Lady Day, as the true beginning of the year.  Kinda explains why SEPTEMber, OCTOber, NOVEMber and DECEMber are not the 7th to 10th months.

By the 14th century, 25 March had been generally adopted as the first day ofthe civil or legal year. Until 1752, this coexisted with the concept of the historical year, which began on 1 January, so dates in the early months were frequently given in the form 24 March 1694/5, with the final fraction digit showing both legal and historical year.

The January/March problem dated back to Roman days, where the original calendar, supposedly drawn up by Romulus, ran from March to December with January and February ignored. From 222BC, the year ran from March, when the new consul took office, but in 153BC New Year's Day was changed to 1 January.

It's not BAL, but may help explain the algorithm.

Fri, 22 May 1998 03:00:00 GMT
Obtaining Day-Of-Week

Quote:

>|>       Cute algorithm... but its just another example of what
>|>       doesn't work in the *very* near future!

Here is one that does work, AND does not use a table.  All division is integer.

Let
J = year/100
K = year - (year/100)*100
q = day of month
M = month number such that M ranges from 3 to 14; thus
feb of 96 is month 14 of 95

Then day of week =
mod(q + ((M+1)*26)/10) + K + (K/4) + (J/4) - (2*J) , 7)

1 is sunday and 0 is sat.

You must use MOD, not remainder as the value can be negative and there
is a difference.

This algorithm was developed in the 18th century.  I picked it up from a

Mon, 25 May 1998 03:00:00 GMT
Obtaining Day-Of-Week
This looks very usable.  How do you code it in BAL?

Fri, 29 May 1998 03:00:00 GMT
Obtaining Day-Of-Week

Quote:

>This looks very usable.  How do you code it in BAL?

Here is an assembler routine for MVS that calculates
the day of the week:

*
*Convert a packed julian date obtained from the TIME macro
*to an integer that represents the number of days since 1900/12/31.
*
*Input: R1=YYYYDDDF    julian date from TIME macro
*
*         The first byte of R1 is 00 for years 1900-1999
*         and 01 for years 2000-2099.
*
*Output:  R15=day of the week (1=monday, 7=sunday)
*
*         R0=number of days since 1900/12/31
*
*         R1=pointer to a 9-byte character string that
*            represents the day of the week.
*
JUL2DAYS SAVE  (14,1),,*
MVO   32(8,R13),24(2,R13)  00000YYY?
OI    32+7(R13),X'0F'        00000YYYF
CVB   R14,32(,R13)            R14=YEAR
LA    R0,365                  number of days in a year
LR    R1,R14                  R1=years since 1901
MR    R0,R0                   years*365
BCTR  R14,0                   R14=YEAR-1
SRL   R14,2                   number of leap years since 1901
AR    R14,R1                  NUMBER OF DAYS IN PREVIOUS YEARS
XC    20(6,R13),20(R13)   zero YYYY in 00000000YYYYDDDF
CVB   R0,20(,R13)             NUMBER OF DAYS THIS YEAR
AR    R0,R14                  number of days since 1900/12/31
*
*        DETERMINE DAY OF THE WEEK
*
SLR   R14,R14         PREPARE DIVISION
LR    R15,R0                  DAYS SINCE 1900/12/31
BCTR  R15,0                   DAYS-1
LA    R1,7                    NUMBER OF DAYS IN WEEK
DR    R14,R1                  DIVIDE BY NUM OF DAYS IN WEEK
LA    R15,1(,R14)             Day of the week (1=monday)
BALR  R1,0                    local base
USING *,R1
MH    R14,JUL2D_H9       MULT BY LENGTH OF A TABLE ENTRY
LA    R1,JUL2D_TD(R14)   POINT TO DAY-OF-THE-WEEK
RETURN (14)                   goback
*
JUL2D_H9 DC    H'9'                    length of a table entry
JUL2D_TD DC    CL9'Monday'
DC    CL9'Tusday'
DC    CL9'Wednesday'
DC    CL9'Thursday'
DC    CL9'Friday'
DC    CL9'Saturday'
DC    CL9'Sunday'

Sat, 06 Jun 1998 03:00:00 GMT

 Page 1 of 1 [ 12 post ]

Relevant Pages