Z009: Calendar Date Conversion

Author(s): O. Hell Library: KERNLIB
Submitter: Submitted: 27.11. 1984
Language: Fortran Revised:

CALDAT converts any calendar date represention in a set of such representations to all other calendar date representations in the set; in addition a few extra bits of information are produced.

Structure:

SUBROUTINE subprogram
User Entry Names: CALDAT
Internal Entry Names: CDMON, CLEAP, CYDIY, CYEARY
External References: DATIME

Usage:

    CALL CALDAT(IINDEX,CHREP,IBNREP,IERR)
IINDEX
(INTEGER) Integer specifying which of the possible date representations is being given as the input representation. This input may either be as type CHARACTER within the CHREP string or as type INTEGER within the IBNREP array.
CHREP
(CHARACTER*119) A character string containing, as substrings, the possible date representations. One such substring may be filled as the input representation, in which case it should be pointed to by IINDEX.
IBNREP
(INTEGER) Array of length 8 containing various binary date representations. One such date representation may be filled as the input representation, in which case it should be pointed to by IINDEX.
IERR
(INTEGER) Error flag. tex2html_wrap_inline149 success, tex2html_wrap_inline151 failure of the conversion.
The substrings of CHREP can be accessed directly, using CHARACTER substring operations. Alternatively all, or part, of the EQUIVALENCE statements below may be used:
    CHARACTER   DMY14*14,DMY11*11,DMY9*9,DMY10*10
    CHARACTER*8 DMY8A,DMY8B,YMD8,MDY8,YDM8
    CHARACTER*6 DMY6,       YMD6,MDY6,YDM6
    CHARACTER   YD5*5,W4*4,W2*2
    EQUIVALENCE
   *   (CHREP(  1: 14), DMY14), (CHREP( 15: 25), DMY11),
   *   (CHREP( 26: 34), DMY9 ), (CHREP( 35: 44), DMY10),
   *   (CHREP( 45: 52), DMY8A), (CHREP( 53: 60), DMY8B),
   *   (CHREP( 61: 66), DMY6 ), (CHREP( 67: 74), YMD8 ),
   *   (CHREP( 75: 80), YMD6 ), (CHREP( 81: 88), MDY8 ),
   *   (CHREP( 89: 94), MDY6 ), (CHREP( 95:102), YDM8 ),
   *   (CHREP(103:108), YDM6 ), (CHREP(109:113), YD5  ),
   *   (CHREP(114:117), W4   ), (CHREP(118:119), W2   )

Details of the substrings in argument CHREP and the corresponding IINDEX values:

            EXAMPLE       IINDEX            EXAMPLE  IINDEX
 
    DMY14   16. APRIL 1982     1      YMD6  820416        9
    DMY11   16 APR 1982        2      MDY8  04/16/82     10
    DMY9    16 APR 82          3      MDY6  041682       11
    DMY10   16. 4.1982         4      YDM8  82/16/04     12
    DMY8A   16. 4.82           5      YDM6  821604       13
    DMY8B   16/04/82           6      YD5   82106        14
    DMY6    160482             7      W4    FRI.
    YMD8    82/04/16           8      W2    FR
Details of the elements in argument IBNREP and the corresponding IINDEX values:
 Element     Contents          Type          Example     IINDEX
   1,2,3        d, m, y             binary        16, 4, 1982    101
       4        day in the year     binary                106    102
       5        00YYDDDC            packed dec       0082106C    103
       6        Julian date         binary             723651    104
       7        weekday, MO=0,...   binary                  4
       8        week in the year    binary                 15
     3,4        y, day in year      binary          1982, 106    105
Notes: Julian date = days since 1/1/1, without Gregory's pause. Week 1 of the year contains the 1st Thursday in the year (ISO).
Names of the months:
3 characters:
'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'

5 characters:
'JAN. ', 'FEB. ', 'MARCH', 'APRIL', 'MAY ', 'JUNE ',
'JULY ', 'AUG. ', 'SEPT.', 'OCT. ', 'NOV. ', 'DEC. '

Names of the week days:
2 characters: 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'.
4 characters: 'MON.', 'TUE.', 'WED.', 'THUR', 'FRI.', 'SAT.', 'SUN.'.

Method:

Two arguments are used for passing the calendar dates: a character string and an array of full words. The various representations are numbered, and an input parameter ('input index') specifies the representation containing the input calendar date.

An extra output parameter receives a return code.
Special cases:

tex2html_wrap_inline155
Input index = 0 designates today which CALDAT will find.
tex2html_wrap_inline157
Input year yy rather than yyyy, designates this century.
tex2html_wrap_inline159
Input index or input data invalid:
- output character string with all '*';
- output numbers all X'81818181' = -2 122 219 135.

Restrictions:

CALDAT will give incorrect dates and weekdays for dates prior to the reformation of the Calendar by pope Gregory (16th century).

Error handling:

IERR Meaning
0 everything fine
4 tex2html_wrap_inline161
8 upper bound for tex2html_wrap_inline163 lower bound for IBNREP
12 upper bound for tex2html_wrap_inline165
16 ddd out of bounds
20 mm | dd out of bounds
24 yyyy out of bounds

Syntax errors:

IERR   in  IINDEX      IERR  in  IINDEX            IERR   in   IINDEX
 
1001   DMY14    1      1006  DMY8B    6            1011   MDY6     11
1002   DMY11    2      1007  DMY6     7            1012   YDM8     12
1003   DMY9     3      1008  YMD8     8            1013   YDM6     13
1004   DMY10    4      1009  YMD6     9            1014   YD5      14
1005   DMY8A    5      1010  MDY8    10            1103   Julian  103

Notes:

Element 5 of IBNREP is not a Fortran type. Nevertheless this calendar date format may show up in data from the 'real world'. Element 7 of IBNREP is especially well suited for arithmetical calculations with dates.

Examples:

 C    Initialize substring CHREP(15:25)
      DMY11='16 APR 1982'
 C    Define this substring to be the input format
      IINDEX=2
      CALL CALDAT(IINDEX,CHREP,IBNREP,IERR)
tex2html_wrap_inline167

Michel Goossens Wed Jun 5 09:49:19 METDST 1996