compile subroutine rds_date_valid(ConvType, DataIo, Branch, ReturnedValue)
begin condition
pre:
post:
end condition

$insert logical
$insert msg_equates
declare function msg, get_property, set_property
equ valid$         to 0    ;* successful
equ invalid_msg$   to 1    ;* bad data       -   print error message window
equ invalid_conv$  to 2    ;* bad conversion -          "         "
equ invalid_nomsg$ to 3    ;* bad but do not print the error message window
equ CrLf$          to char(13):char(10)
* this is used so the date_in and date_out entries must be today
* this has been changed so many times
* it should really just stamp it but we need to talk it over with production

ReturnedValue = DataIo       
status() = Valid$
*
Today = date()
begin case
   case ConvType = 'ICONV'
      Edate = iconv( DataIo, 'D' )
      if Edate then
         if ( Edate > Today ) or ( Edate < Today ) then
            Odate = oconv( Edate, 'D2/' )
            MsgInfo = ''
            MsgInfo<mtext$> = "Today is not ":Odate:"...Please verify your date entry."
            MsgInfo<micon$> = 'H'
            Void = msg( '', MsgInfo ) 
            *status() = invalid_nomsg$
         end   
      end else
         * did not pass (D) conversion present error
         MsgInfo = ''
         MsgInfo<mtext$> = 'The data must be a valid date in the format:':Crlf$:'[Month][Day][Year]'
         MsgInfo<micon$> = '!'
         Void = msg( '', MsgInfo )
         status() = invalid_nomsg$
      end
   case ConvType = 'OCONV'
      * no output
      ReturnedValue = DataIo
   case otherwise$
      ReturnedValue = ''
      status() = invalid_conv$
end case
return
