DAY OF WEEK FUNCTION - Post if you've got one - Please 
Author Message
 DAY OF WEEK FUNCTION - Post if you've got one - Please

Hello all.  I have an application that calculates the DAY OF THE WEEK
(i.e., Monday, Tuesday, etc...) based on a date entered by the user.
Unfortunately, after February 1997, the days are no longer calculating
correctly (current coding thinks 1997 is a leap year).  I did not
write the original routine, and the programmer that did, obviously did
not write it for others to understand (it's really poor coding).  So -
before I sit down and start hacking one out from scratch, I wanted to
know if anyone out there had one already written.  If you do, could
you please post it to this News Group?  That would be a great help,
and others might be interested in it as well.

Douglas Troy

NOTE: MF 3.1.35 has a DAY OF THE WEEK function in a library, but I
don't want to link in another library because the existing application
is already too big (like I said, poor coding).

Thanks.



Mon, 07 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please

Quote:

> Hello all.  I have an application that calculates the DAY OF THE WEEK
> (i.e., Monday, Tuesday, etc...) based on a date entered by the user.
>  I did not
> write the original routine, and the programmer that did, obviously did
> not write it for others to understand (it's really poor coding). >
> Douglas Troy

> NOTE: MF 3.1.35 has a DAY OF THE WEEK function in a library, but I
> don't want to link in another library because the existing application
> is already too big (like I said, poor coding).

> Thanks.

Doug, if that code is as bad as you say it is, you would be better off
scrapping it for some good code that others down the line will
understand. --


Mon, 07 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please



Quote:
> before I sit down and start hacking one out from scratch, I wanted to
> know if anyone out there had one already written.  If you do, could
> you please post it to this News Group?

---------------------------------------------------------
Set the parameters and CALL "Y2" USING Y2-DATA.
This routine was developed from algorithms kindly supplied by

It has passed all my tests so far but is not guaranteed to be
bug-free or even to work at all.  I know it could be expressed
better and has several periods and GOTOs in it so don't tell me!
Now the legal bit, so no-one else can assert ownership:

"Copyright (c) 1996 by Richard Ross-Langley of Mine of Information
Ltd who hereby asserts his right to be identified as author of
this work, in accordance with the UK Designs and Patents Act,
1988.  This product is not in the public domain.  You may make
copies freely but the author continues to hold all rights in it."
---------------------------------------------------------
* Y2DATA.LIB
       01  Y2-DATA.
*          date in Normal format for correct sort order in files etc
*          note range is artificially restricted to 1/1/1800..31/12/2099
           05  Y2-CCYYMMDD              PIC 9(8).
           05  FILLER REDEFINES Y2-CCYYMMDD.
                10  Y2-CCYY             PIC 9(4).
                10  Y2-MMDD             PIC 9(4).
           05  FILLER REDEFINES Y2-CCYYMMDD.
                10  Y2-CC               PIC 9(2).
                        88 Y2-CC-OK             VALUE 18 THRU 20.
                10  Y2-YYMMDD.
                    15  Y2-YY           PIC 9(2).
                        88  Y2-YY-OK            VALUE 00 THRU 99.
                    15  Y2-MM           PIC 9(2).
                        88  Y2-MM-OK            VALUE 01 THRU 12.
                    15  Y2-DD           PIC 9(2).
                        88  Y2-DD-OK            VALUE 01 THRU 31.
*          date as number of days since.. (monotonic integer)
*          value zero indicates an incorrect display date
*               range 072684 = Wednesday 01/01/1800
*               up to 182556 = Thursday  31/12/2099
*          note that modulo 7 yields day of week (0=Sunday)
           05  Y2-DAYS                  PIC 9(6).
                88  Y2-DAYS-FAIL        VALUE ZERO.
                88  Y2-DAYS-OK          VALUE 072684 THRU 182256.
           05  Y2-WEEKDAY               PIC 9(1).
*          function message
           05  Y2-FUNCTION              PIC X(6).
                88  Y2-ENCODE           VALUE "ENCODE".
                88  Y2-DECODE           VALUE "DECODE".
*
* end of libfile
---------------------------------------------------------
* Y2.CBL        Year 2000 subroutines
*
       IDENTIFICATION DIVISION.
       PROGRAM-ID.  Y2.
       AUTHOR. R ROSS-LANGLEY.
*          from algorithms kindly supplied by JOHN M PERRY.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  FILLER       PIC X           VALUE "Y".
           88  COBOL85-FUNCTIONS        VALUE "Y".
       01  WS-DT1               PIC S9(9) COMP.
       01  WS-DT2               PIC S9(9) COMP.
       01  WS-DT3               PIC S9(9) COMP.
       01  WS-DT4               PIC S9(9) COMP.
       01  WS-DT5               PIC S9(9) COMP.
*
       LINKAGE SECTION.
           COPY "Y2DATA.LIB".
*
       PROCEDURE DIVISION USING Y2-DATA.
       AA-INIT SECTION.
           EVALUATE TRUE
           WHEN Y2-ENCODE
                PERFORM ZZ-Y2-ENCODE
           WHEN Y2-DECODE
                PERFORM ZZ-Y2-DECODE
           WHEN OTHER
*               mark the data as invalid
                MOVE ZERO TO WS-DATE10-DD
                SET Y2-DAYS-FAIL TO TRUE
           END-EVALUATE.
           EXIT PROGRAM.
           STOP RUN.
*
**
*
       ZZ-Y2-ENCODE SECTION.
           SET Y2-DAYS-FAIL TO TRUE.
           IF Y2-CCYYMMDD NOT NUMERIC
                GO TO ZZ-Y2-ENCODE-EXIT.
           IF NOT Y2-DD-OK GO TO ZZ-Y2-ENCODE-EXIT.
           IF NOT Y2-MM-OK GO TO ZZ-Y2-ENCODE-EXIT.
           IF NOT Y2-CC-OK GO TO ZZ-Y2-ENCODE-EXIT.
*          convert to Serial days-since
           IF COBOL85-FUNCTIONS
**              with COBOL-85 functions
                COMPUTE Y2-DAYS =
                        FUNCTION INTEGER-OF-DATE (Y2-CCYYMMDD)
                COMPUTE Y2-WEEKDAY =
                        FUNCTION MOD (Y2-DAYS, 7)
           ELSE
***             without COBOL-85 functions
                COMPUTE WS-DT1 = (Y2-MM - 14) / 12
                COMPUTE WS-DT2 = (Y2-CCYY + 4800 + WS-DT1) * 1461
                COMPUTE WS-DT3 = WS-DT2 / 4
                COMPUTE WS-DT2 = WS-DT1 * 12
                COMPUTE WS-DT2 = (Y2-MM - 2 - WS-DT2) * 367
                COMPUTE WS-DT2 = WS-DT2 / 12
                COMPUTE WS-DT3 = WS-DT2 + WS-DT3
                COMPUTE WS-DT2 = (Y2-CCYY + 4900 + WS-DT1) / 100
                COMPUTE WS-DT2 = WS-DT2 * 3
                COMPUTE WS-DT2 = WS-DT2 / 4
                COMPUTE WS-DT3 = WS-DT3 - WS-DT2 - 2410571
*          from 1/1/1800 as day 1 add more to make it day 072684
                COMPUTE Y2-DAYS = Y2-DD + WS-DT3 + 072683
*          calc the weekday (0=Sunday)
                DIVIDE Y2-DAYS BY 7
                        GIVING WS-DT1 REMAINDER Y2-WEEKDAY
           END-IF.
           CONTINUE.
       ZZ-Y2-ENCODE-EXIT.
           EXIT.
*
**
*
       ZZ-Y2-DECODE SECTION.
*          convert from Serial days-since to Normal date format
*          and ensure that the weekday is correct
           IF Y2-DAYS-OK
             IF COBOL85-FUNCTIONS
                COMPUTE Y2-CCYYMMDD =
                        FUNCTION DATE-OF-INTEGER (Y2-DAYS)
                COMPUTE Y2-WEEKDAY =
                        FUNCTION MOD (Y2-DAYS, 7)
             ELSE
*               number of days is in the correct range (adjust for offset)
                DIVIDE Y2-DAYS BY 7
                        GIVING WS-DT1 REMAINDER Y2-WEEKDAY
                COMPUTE WS-DT1 = Y2-DAYS + 2447065 - 072683
                COMPUTE WS-DT2 = WS-DT1 * 4
                COMPUTE WS-DT2 = WS-DT2 / 146097
                COMPUTE WS-DT3 = WS-DT2 * 146097
                COMPUTE WS-DT3 = (WS-DT3 + 3) / 4
                COMPUTE WS-DT1 = WS-DT1 - WS-DT3
                COMPUTE WS-DT3 = (WS-DT1 + 1) * 4000
                COMPUTE WS-DT3 = WS-DT3 / 1461001
                COMPUTE WS-DT4 = WS-DT3 * 1461
                COMPUTE WS-DT4 = WS-DT4 / 4
                COMPUTE WS-DT1 = WS-DT1 - WS-DT4 + 31
                COMPUTE WS-DT4 = WS-DT1 * 80
                COMPUTE WS-DT4 = WS-DT4 / 2447
                COMPUTE WS-DT5 = WS-DT4 * 2447
                COMPUTE WS-DT5 = WS-DT5 / 80
                COMPUTE Y2-DD    = WS-DT1 - WS-DT5
                COMPUTE WS-DT1 = WS-DT4 / 11
                COMPUTE WS-DT5 = WS-DT1 * 12
                COMPUTE Y2-MM    = WS-DT4 + 2 - WS-DT5
                COMPUTE WS-DT4 = (WS-DT2 - 49) * 100
                COMPUTE Y2-CCYY  = WS-DT1 + WS-DT3 + WS-DT4
             END-IF
           ELSE
                SET Y2-DAYS-FAIL TO TRUE
           END-IF.
*
* ends
---------------------------------------------------------

--

Mine of Information Ltd, PO BOX 1000, St Albans AL3 5NY, GB
* Independent Computer Consultancy    Established in 1977 *



Tue, 08 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please

The intrinsic functions contained in the supplement to the 1985 standard
should allow you to solve the problem forever.

Since the days of the week are always present sequentially, Sunday Monday
Tuesday Wednesday Thursday Friday Saturday.

Use Integer-of-day or Integer-of-date to change the date you have to a so
called "lillian" sequential days format.  You will now have a number from
1 to 3067671.  1 = Jan 01, 1601, 3067671 represents December 31, 9999.  

To find the day of week, simply divide by 7, discard the result, but keep
the remainder.  I beleive that Jan 01, 1601 was a Monday (better check,
memory may be faulty).  So if remainder is 1 the day of week is Monday, 2
= Tuesday,... 6 Saturday, 0 Sunday.

No guarantees on the exact day of the week on Jan 01, 1601,  that was a
long time ago and my memory's kind of fading.  Once the base day of week
is verified, it will work untill they omit a day of week.  Leap years do
not affect this method.

   Move function integer-of-date ( date-input) to temp-numeric
   divide temp-numeric by +7 remainder temp-rem
   move day-of-week-code-table (temp-rem) to the-answer

Rex Widmer
Builder of software archeology tools and other strange programs to help
survive in a legacy based world.



Tue, 08 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please

Quote:

> The intrinsic functions contained in the supplement to the 1985 standard
> should allow you to solve the problem forever.

> Since the days of the week are always present sequentially, Sunday Monday
> Tuesday Wednesday Thursday Friday Saturday.

> Use Integer-of-day or Integer-of-date to change the date you have to a so
> called "lillian" sequential days format.  You will now have a number from
> 1 to 3067671.  1 = Jan 01, 1601, 3067671 represents December 31, 9999.

> To find the day of week, simply divide by 7, discard the result, but keep
> the remainder.

Actually, it is easier to use the MOD function.  Here is a line that
would work:

COMPUTE the-day = FUNCTION MOD (FUNCTION INTEGER-OF-DATE
  (date-as-yyyymmdd) 7)

Sunday will be 0, Monday 1, and so on.

I beleive that Jan 01, 1601 was a Monday (better check,

Quote:
> memory may be faulty).

It was - it says so in the standard so it must be true!

Quote:
>  So if remainder is 1 the day of week is Monday, 2
> = Tuesday,... 6 Saturday, 0 Sunday.

> No guarantees on the exact day of the week on Jan 01, 1601,  that was a
> long time ago and my memory's kind of fading.  Once the base day of week
> is verified, it will work untill they omit a day of week.  Leap years do
> not affect this method.

>    Move function integer-of-date ( date-input) to temp-numeric
>    divide temp-numeric by +7 remainder temp-rem
>    move day-of-week-code-table (temp-rem) to the-answer

Rex's code works fine, it is just that MOD is a little simpler.

In the next standard you could say

   MOVE day-table (FUNCTION MOD (FUNCTION INTEGER-OF-DATE
  (date-as-yyyymmdd) 7) + 1) TO the-answer

The table would be the names starting with "SUNDAY".

--
Don Nelson
COBOL Development, Tandem Computers, Inc.
Member, ANSI X3J4 and ISO/IEC JTC1/SC22 WG4 COBOL Committees

No clever quotes here



Tue, 08 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please



Quote:

> Hello all.  I have an application that calculates the DAY OF THE WEEK
> (i.e., Monday, Tuesday, etc...) based on a date entered by the user.
> Unfortunately, after February 1997, the days are no longer calculating
> correctly (current coding thinks 1997 is a leap year).  I did not
> write the original routine, and the programmer that did, obviously did
> not write it for others to understand (it's really poor coding).  

I have an aweful one.  But it works to 2000 and beyond.  It's not pretty.
I wrote it in my pre-ansi 85 days and it's FUGLY!  I'll see what I can do
this weekend on it.  

E-mail me if you don't see it soon.



Tue, 08 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please

Ok here it is.  It could be cleaner, but you can use it too!

Let me know if you can't read it or something.

It's kinda crudely formatted, it could be a lot neater, but it is also very
old.

begin 600 test1.cbl
<uuencoded_portion_removed>

`
end



Tue, 08 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please

Quote:
>Hello all.  I have an application that calculates the DAY OF THE WEEK
>(i.e., Monday, Tuesday, etc...) based on a date entered by the user.
>Unfortunately, after February 1997, the days are no longer calculating
>correctly (current coding thinks 1997 is a leap year).  I did not
>write the original routine, and the programmer that did, obviously did
>not write it for others to understand (it's really poor coding).  So -

I'd rather debug an existing program than write a new one from scratch, but
that's just me: I can't remember which divison comes after ID division...

-Remo



Wed, 09 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please


Quote:

>Hello all.  I have an application that calculates the DAY OF THE WEEK
>(i.e., Monday, Tuesday, etc...) based on a date entered by the user.
>Unfortunately, after February 1997, the days are no longer calculating
>correctly (current coding thinks 1997 is a leap year).  I did not
>write the original routine, and the programmer that did, obviously did
>not write it for others to understand (it's really poor coding).  So -
>before I sit down and start hacking one out from scratch, I wanted to
>know if anyone out there had one already written.  If you do, could
>you please post it to this News Group?  That would be a great help,
>and others might be interested in it as well.

>Douglas Troy

>NOTE: MF 3.1.35 has a DAY OF THE WEEK function in a library, but I
>don't want to link in another library because the existing application
>is already too big (like I said, poor coding).

>Thanks.

   The packages are from the ETK tool set.  See http://www.toscintl.com
   The stuff was written by Pieter Hintjens and Leif Svalgaard.

            7.                CALRPK

            Type:             Package

            Summary:          Converts dates  between various formats
                              (Gregorian,   Julian,   Lillian),   and
                              computes the  day of the week, and week
                              of the year.

            How to use:       CALRPK  defines   three  date  formats;
                              Gregorian (YYYYMMDD), Julian (YYYYDDD),
                              and  Lillian  (days  since  basedate1).
                              You can  convert  dates  between  these
                              formats, for  example, to  compute  the
                              date 100  days from today.  CALRPK also
                              returns the day of the week or the week
                              of the  year for a date in any of these
                              formats.

            Limitations:      Dates must  not be  earlier than  1 Jan
                              1600.   The algorithm  used to  compute
                              the week of the year is simplified from
                              the normal  standards which  allow week
                              53 to cover the first partial week of a
                              year.

          ____________________
          1 Basedate is 15 October 1582, when the current calendar was
          introduced.

            To call CALRPK, define CALRPK-CONTROL as follows:

            01  CALRPK-CONTROL.
                02  CALRPK-TASK-ID          PIC X(4).
                02  CALRPK-OPERATION        PIC X(2).
                02  CALRPK-FEEDBACK         PIC X.
                02  CALRPK-GREGORIAN-DATE   PIC 9(8).
                02  CALRPK-JULIAN-FORMAT    PIC 9(7).
                02  FILLER                  REDEFINES  CALRPK-JULIAN-FORMAT.
                    03  CALRPK-JULIAN-YYYY  PIC 9(4).
                    03  CALRPK-JULIAN-DDD   PIC 9(3).
                02  CALRPK-LILLIAN-DAYS     PIC 9(7).
                02  CALRPK-DAY-OF-WEEK      PIC 9.
                02  CALRPK-WEEK-OF-YEAR     PIC 9(2).

            Define CALL-CALRPK as follows:

            CALL-CALRPK.
                CALL "CALRPK"
                    USING CALRPK-CONTROL
                .

            CALCPK accepts  a 2-character  operation code.   The first
          character, "G",  "J", or "L" indicates which date format the
          calling program  is supplying.   The second character may be
          one of the following:

            V (validate)      Check that  the date is valid.  If not,
                              return an "E" (error) feedback.

            D (day)           Return the  day of  the week; 1=Monday,
                              7=Sunday.

            W (week)          Return the  week of  the year; 0 to 52,
                              where 1 is the first full week.

            G (Gregorian)     Convert Julian  format or  Lillian days
                              into a Gregorian date.

            J (Julian)        Convert Gregorian  date or Lillian days
                              into the Julian format.

            L (Lillian)       Convert Gregorian date or Julian format
                              into Lillian days.

            CALRPK returns  these feedbacks:  a space means there were
          no errors;  an "E" means that the date supplied was invalid.
          All operations  check that  the supplied  date is valid.  An
          "O" means that the specified operation was invalid.

               History     of     the      radius.       This    bulge
          Calendar                         experiences    a     torque
                                           applied       by        the
            The   history    of   the      gravitational influence  of
          calendar  is   fascinating.      the Moon,  the Sun, and the
          The year of a planet is the      planets.   The result  is a
          time it  takes to orbit the      precessional motion  of the
          Sun.   There are,  however,      Earth's  axis.    This  was
          different  types  of  year.      discovered  by   Hipparchos
          The time it takes the Earth      about 150 BC.
          to   make    one   complete
          revolution with  respect to        The astronomical  motions
          the distant stars is called      of the  Earth and  the Moon
          the siderial year (deriving      provide the  basis for  the
          from the  Latin word sidus,      calendar -  the subdivision
          which meant constellation).      of time into years, months,
          The  siderial  year    (for      weeks,  and   days.     The
          1950)    is     equal    to      problem     with      these
          365.25636566    days     or      subdivisions is  that  they
          31,558,149.993 seconds.          are based on phenomena that
                                           have  different  periods  -
            The time it takes for the      the revolution of the Earth
          Earth to return to the same      around   the    Sun,    the
          point in its seasonal cycle      revolution  of   the   Moon
          (which is  what  counts  as      around the  Earth, and  the
          far  as   the  calendar  is      rotation of the Earth.  The
          concerned)  is  called  the      periods       are       not
          tropical  year  (after  the      commensurate:   there   are
          Greek verb  trepein,  which      about 29.53 days in a lunar
          means  to   turn).      The      month,  4.22   weeks  in  a
          tropical year  is equal  to      lunar  month,   and  365.24
          365.24219342    days     or      days in  a  tropical  year.
          31,556,925.511      seconds      The   development   of   an
          being  about   20  m  25  s      accurate calendar  has been
          shorter than  the  siderial      a  vexing   problem   since
          year.         The    modern      antiquity     (the     name
          definition of  a second  is      calendar derives  from  the
          the       duration       of      Latin name kalendae for the
          9,192,631,770 cycles of the      day  of   the   new   Moon,
          radiation  emitted  by  the      marking  the  beginning  of
          transition between  the two      the lunar month).
          hyperfine  levels   of  the
          ground state  of the  133Cs        The   Egyptians   started
          atom.                            their year  in  the  latter
                                           part of July, when the Nile
            The  tropical   year   is      began flooding  the  delta.
          shorter than  the  siderial      This  was   a  big   event,
          year   because    of    the      because    the     flooding
          precession of  the  Earth's      fertilized the  delta.  The
          axis.   Precession  is  the      Egyptians divided  the year
          motion of  the  axis  of  a      into 12  months of  30 days
          spinning top.   The  Earth,      each, giving a total of 360
          like   a    top,   has   an      days, to  which they  added
          equatorial bulge  caused by      an extra 5 days at the end.
          the  centrifugal  force  of      In the  years  around  4241
          its    rotation    -    the      BC, the  Egyptians  noticed
          equatorial radius is 21.360      that the rising of the Nile
          km longer  than  the  polar      coincided with the day when
          the star  Sirius (known  as      (depending on  which  Greek
          Sothis)    became     again      city).
          visible in the southern sky
          as seen  from  the  capital        According to legend, Rome
          city of Memphis.                 was founded by Romulus, its
                                           first king,  on  April  21,
            The     Roman      author      753 BC.   At that time, the
          Censorinus reported  in his      Romans had a calendar of 10
          work De die natali (written      months (Martius after Mars,
          in 238  AD and dedicated to      the god  of  war,  Aprilis,
          his patron on his birthday)      after Apru,  the  Etruscian
          that in  139 AD  the rising      goddess  of   love,  Maius,
          of Sothis  had occurred  on      after Maia, eldest daughter
          July 20.  Now, the Egyptian      of  Atlas,   Junius,  after
          year  of   365   days   was      Juno,  wife   of   Jupiter,
          shorter by  0.242 day  than      Quintilis,        Sextilis,
          the tropical  year.   As  a      September,         October,
          result,    the     Egyptian      November,
...

read more »



Thu, 10 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please

Agast!!!  my earlier post had an error embedded in the code.

Since temp-rem (remainder from dividing by +7) could be zero, the posted
code could have a subscript out of bounds.  Temp-rem should be increased
by +1 before usage as a subscript.

Oh well.... that's what compilers that test for out-of-range are good for
(not to mention testing code).  Also says something about pounding the
keyboard by the light of the moon.

Rex Widmer
Builder of software archeology tools and other strange programs to help
survive in a legacy based world.



Fri, 11 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please

    move  FUNCTION REM (FUNCTION INTEGER-OF-DATE (MY-DATE), 7 )    
      TO  WO-TAG                                                  

The inner function returns number of days since 31.12.1600 (a sunday),
so
        WO-TAG=  0 -  Sunday
        WO-TAG = 1 - Monday    
        WO-TAG = 2 - Tuesday

Thomas Wolter



Tue, 15 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please

Quote:

>     move  FUNCTION REM (FUNCTION INTEGER-OF-DATE (MY-DATE), 7 )
>       TO  WO-TAG

> The inner function returns number of days since 31.12.1600 (a sunday),
> so
>         WO-TAG=  0 -  Sunday
>         WO-TAG = 1 - Monday
>         WO-TAG = 2 - Tuesday

> Thomas Wolter

        Zeller's congruence will also give you the desired range of w0-tag
values of 0 thru 6. But I think Zeller's gives Sunday as 6, Monday as
0.  The inner function can be easily adjusted to your desired range by
just adding 1 before compute the remainder mod 7.  Input to the routine
is the 4 digit year, month (jan=1, dec=12), and day of month.  The
routine replaces your imnner and outer functions. You may want to check
a good library for other routines listed in the Association of Computing
Machinery journals.  ACM 13 (Oct 1970, 621) lists Zeller's congruence as
well as two other routines for converting julian to and from MMDD
format.  ACM 11 (Oct 1968, 657) and ACM 6 (Aug 1963, 444) may also be of
interest.
        Anyway, Zeller's congruence formula is scary looking when written as a
fortran arithmetic statement function. In theory, a COBOL COMPUTE
statement followed by a DIVIDE WITH REMAINDER will suffice. You may
simplify by noting the common expression (Y+(M-14)/12).  Anyway, the
1960's vintage Fortran reads as follows in the ACM Collected Algorithms:
IZLR(Y,M,D) = MOD((13*(M+10-(M+10)/13*12)-1)/5+D+77
              +5*(Y+(M-14)/12-(Y+(M-14)/12)/100*100)/4
              +(Y+(M-14)/12)/400-(Y+(M-14)/12)/100*2,7)
        Told you it was scary looking!  But I copied the source without
factoring out the common expression for you.  The formula simply uses a
lot of binary arithmetic in which intermediate results such as 12/13 is
zero, 14/13 is one, -2/13 is zero, -14/13 is -1.  The formula should be
YEAR2000 compliant since Y is a four digit year. And the 100 and 400
year quirks for leap years are accounted for in the formula.  Enjoy!


Fri, 18 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please


Quote:


>>     move  FUNCTION REM (FUNCTION INTEGER-OF-DATE (MY-DATE), 7 )
>>       TO  WO-TAG

>> The inner function returns number of days since 31.12.1600 (a sunday),
>> so
>>         WO-TAG=  0 -  Sunday
>>         WO-TAG = 1 - Monday
>>         WO-TAG = 2 - Tuesday

>> Thomas Wolter
>        Zeller's congruence will also give you the desired range of
w0-tag
>values of 0 thru 6. But I think Zeller's gives Sunday as 6, Monday as
>0.  The inner function can be easily adjusted to your desired range by
>just adding 1 before compute the remainder mod 7.  Input to the routine
>is the 4 digit year, month (jan=1, dec=12), and day of month.  The
>routine replaces your imnner and outer functions. You may want to check
>a good library for other routines listed in the Association of Computing
>Machinery journals.  ACM 13 (Oct 1970, 621) lists Zeller's congruence as
>well as two other routines for converting julian to and from MMDD
>format.  ACM 11 (Oct 1968, 657) and ACM 6 (Aug 1963, 444) may also be of
>interest.
>        Anyway, Zeller's congruence formula is scary looking when written
as a
>Fortran arithmetic statement function. In theory, a COBOL COMPUTE
>statement followed by a DIVIDE WITH REMAINDER will suffice. You may
>simplify by noting the common expression (Y+(M-14)/12).  Anyway, the
>1960's vintage Fortran reads as follows in the ACM Collected Algorithms:
>IZLR(Y,M,D) = MOD((13*(M+10-(M+10)/13*12)-1)/5+D+77
>              +5*(Y+(M-14)/12-(Y+(M-14)/12)/100*100)/4
>              +(Y+(M-14)/12)/400-(Y+(M-14)/12)/100*2,7)
>        Told you it was scary looking!  But I copied the source without
>factoring out the common expression for you.  The formula simply uses a
>lot of binary arithmetic in which intermediate results such as 12/13 is
>zero, 14/13 is one, -2/13 is zero, -14/13 is -1.  The formula should be
>YEAR2000 compliant since Y is a four digit year. And the 100 and 400
>year quirks for leap years are accounted for in the formula.  Enjoy!

I don't understand this thread. Every COBOL compiler I've used over the
last twenty years had an "ACCEPT WS-DOW FROM DAY-OF-WEEK" ability.
However, none of these 15 or so compilers were for IBM platforms ... so is
that where my confusion lies? ... do IBM compilers not provide this
intrinsic ability to provide day of week (and force programmers to do the
above cartwheels)?

Peter



Sat, 19 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please

Quote:
> I don't understand this thread. Every COBOL compiler I've used over the
> last twenty years had an "ACCEPT WS-DOW FROM DAY-OF-WEEK" ability.
> However, none of these 15 or so compilers were for IBM platforms ... so
is
> that where my confusion lies? ... do IBM compilers not provide this
> intrinsic ability to provide day of week (and force programmers to do the
> above cartwheels)?

The intrinsic function calls to allow determination of day of week and
other date functions are a fairly recent addition.  While it has nearly
always been possible to determine what day of the week it was TODAY,
sometimes (In my Bowling center software for example) I need to know what
day of the week some FUTURE date is.  I wrote my routine, from research I
did from an encyclopedia, about 8 years ago.  Long before the intrinsic
function calls were available.


Sat, 19 Jun 1999 03:00:00 GMT  
 DAY OF WEEK FUNCTION - Post if you've got one - Please

Quote:

> While it has nearly always been possible to determine what day of the week it was TODAY,
> sometimes (In my Bowling center software for example) I need to know what
> day of the week some FUTURE date is.  I wrote my routine, from research I
> did from an encyclopedia, about 8 years ago.  Long before the intrinsic
> function calls were available.

Given the future date you want is a 4 digit Year, Month(1-12), and Day,
try computing the
variable named Zeller as your inner function.  It's not the number of
days since 1600, but
will return a number ready for reduction mod 7 to give you the desired 0
thru 6 values.  This
should be useful unless you actually have a separate need for the inner
function.  I think
the calculations gives zero for Sunday, but adjusting the '77' in the
formula allows any desired
day of the week to be the zero.  I haven't checked this code out.  But
I've tried to accurately
transcribe Zeller's congruence from Fortran to COBOL.  If transcribed
correctly, the
calculations take into account that the 00 years are not leap years
unless divisible by 400.
01  FebAdjYear   PIC S9(9) COMP VALUE +0.
01  FebAdj100Yr  PIC S9(9) COMP VALUE +0.
01  FebAdj400Yr  PIC S9(9) COMP VALUE +0.
01  Zeller       PIC S9(9) COMP VALUE +0.
...
    COMPUTE FebAdjYear = Year + (Month - 14) / 12.
    COMPUTE FebAdj100Yr = FebAdjYear / 100.
    COMPUTE FebAdj400Yr = FebAdjYear / 400.
    Compute Zeller = (13 * ( Month + 10 - (Month + 10) / 13 * 12) - 1) /
5
        + Day + 77 + 5 * (FebAdjYear - FebAdj100Yr * 100) / 4
        + FebAdj400Yr - FebAdj100Yr * 2.


Sun, 20 Jun 1999 03:00:00 GMT  
 
 [ 19 post ]  Go to page: [1] [2]

 Relevant Pages 

1. DAY OF THE WEEK ROUTINE - day-week.txt (1/1)

2. DAY OF THE WEEK ROUTINE - day-week.txt (0/1)

3. Getting Day of Week

4. Getting Day of Week from a Date

5. The Smalltalk Store: Why we've been slow, and why we're getting better

6. Day of week DATE('w')

7. Anybody have a day-of-the-week function?

8. Long post : Full lists of errorcodes I've found so far (with a few solutions)

9. CW2.003 - day of week functions..

10. Week Day function (UK)

11. Here's a Fuction to Return Number of Week Days in a Month

12. Day of week DATE('w?????

 

 
Powered by phpBB® Forum Software