CL Using CEE Date APIs

Using CEE date APIs

The CEE date APIs can simplify date conversion for CL programs.The CEEDAYS API translates a date into a numeric value--a Lilian date. The beginning of the Lilian date range is set to 15 October 1582. This is defined as Lilian day 1. Lilian day zero is defined as 14 October 1582, and is used for calculation purposes in several of the APIs. Lilian second 1 is defined as 00:00:01 on 14 October 1582, and is used for calculation purposes in several of the APIs. Only Lilian dates greater than or equal to 1 are valid as input or produced as output in the date and time APIs. This is the date of adoption of the Gregorian calendar. Lilian dates preceding this date are undefined.

    Pgm        Parm(&YYMDGreg) 

    Dcl        Var(&YYMDGreg)   Type(*Char) Len(8)  
    Dcl        Var(&CurLilDate) Type(*Int)  
    Dcl        Var(&NewLilDate) Type(*Int) 
    Dcl        Var(&NewGregDt)  Type(*Char) Len(32)

    CallPrc    Prc(CEEDAYS) Parm((&YYMDGreg) ('YYYYMMDD') +  
    (&CurLilDate) (*Omit))    

   /*--------------------------------*/
   /* Add 60 days to the Lilian date */
   /*--------------------------------*/

    ChgVar     Var(&NewLilDate) Value(&CurLilDate + 60) 

  /*---------------------------------------------*/                
  /* convert Lilian to Gregorian MM/DD/YY format */
  /*---------------------------------------------*/

    CallPrc    Prc(CEEDATE) Parm((&NewLilDate) +             
                 ('MM/DD/YYYY') (&NewGregDt) (*Omit))        

    SndPgmMsg  Msg(&NewGregDt) ToPgmQ(*Ext)                  

    EndPgm 


CEEDAYS allows the program to translate a Gegorian date, in the example, having an ISO format, (YYYYMMDD) such as 20210701. The procedure call to the API translates the date into a Lilian value. Adding 60 days to the value is simple. The procedure call to CEEDATE translates the new Lilian value into a Gregorian calendar date in the MM/DD/YYYY format.

    Pgm        Parm(&YYMDGreg)                               
    Dcl        Var(&YYMDGreg)   Type(*Char) Len(8)
    Dcl        Var(&CurLilDate) Type(*Int)
    Dcl        Var(&NewLilDate) Type(*Int)                   
    Dcl        Var(&DayOfWeek)  Type(*Int) 
    Dcl        Var(&NewGregDt)  Type(*Char) Len(32)  

   /*---------------------------------------------*/
   /* Create the Lilian date and then add 60 days */
   /*---------------------------------------------*/

    CallPrc    Prc(CEEDAYS) Parm((&YYMDGreg) ('YYYYMMDD') +  
                 (&CurLilDate) (*Omit))   
    ChgVar     Var(&NewLilDate) Value(&CurLilDate + 60)  
    
   /*--------------------------------*/
   /* Get the day of the week        */
   /*--------------------------------*/

    CallPrc    Prc(CEEDYWK) Parm((&NewLilDate) (&DayOfWeek) + 
                 (*Omit))                                    

   /*---------------------------------------------*/    
   /* test the new date. If the day of the week   */
   /* is 1 (Sunday) add 1. If the day of the week */
   /* is 7 (Saturday) add 2 and get the new  date */                                                        

    If         Cond(&DayOfWeek = 1) Then(ChgVar +            
                 Var(&NewLilDate) Value(&NewLilDate + 1))   
    If         Cond(&DayOfWeek = 7) Then(ChgVar +           
                 Var(&NewLilDate) Value(&NewLilDate + 2)) 
  
    CallPrc    Prc(CEEDATE) Parm((&NewLilDate) +            
                 ('MM/DD/YYYY') (&NewGregDt) (*Omit))       

    SndPgmMsg  Msg(&NewGregDt) ToPgmQ(*Ext)                  

    EndPgm                               


This sample shows the same basic process. CEEDAYS translates a Gegorian date, (YYYYMMDD) into a Lilian date. Adding 60 days to the value, a procedure call to CEEDYWK determines if the day of the week is a Saturday or Sunday. The date is then adjusted by adding 1 or 2 days. The procedure call to CEEDATE translates the new Lilian value into a Monday, Gregorian calendar date in MM/DD/YYYY format.