Class DateTime
*////////////Member Methods/////////////////
* ChrToMiltime  converts 1:15p to 13:15
* NumTime       converts 1:15p to 1315 (for math calculations)
* MilToChrTime  converts 13:15 to 1:15a (miltime to chrtime)
* NumToChrTime  converts 1315  to 1:15a (numtime to chrtime)
* IncrementTime     Increments numeric time to new numeric time
* IncrementChrTime  Increments char time to new char time
* FillTime          Fills out time.dbf with times in specified
*                   increments between start time and end time
*                   in chr format 

function ChrToMilTime(cTime)   && converts 1:15p to 13:15

  local chrTime
  chrTime = cTime
  cHours = substr(cTime,1,at(':',cTime)-1)
  cMinutes = substr(cTime,at(':',cTime)+1,2)
  cSubscript = substr(cTime,len(cTime),1)
  
  if cSubScript = 'p' .and. cHours # '12'
     cHours =  str(val(cHours)+12,2)
  else
     if cHours = '12' .and. cSubScript = 'a'
       cHours = '00'
     elseif Len(cHours) < 2
       cHours =  '0'+cHours
     endif
  endif
return chours+':'+cMinutes


function MilToChrTime(cMilTime) && converts 13:15 to 1:15a
   cHour = substr(cMilTime,1,2)
   cSubscript = iif(val(cHour) >= 12,'p','a')
   cHour = iif(val(cHour) > 12,str(val(cHour)-12,2),cHour)
   if cHour = '00'
      cSubScript = 'a'
      cHour = '12'
   Endif
   cMinutes = substr(cMiltime,at(':',cMiltime)+1,2)
   return ltrim(cHour)+':'+cMinutes+cSubScript

   function NumToChrTime(nTime)  && converts 2300 to 11:00p
   cTime = str(nTime,4)
   cHour = substr(cTime,1,2)
   cMin =  substr(cTime,3,2)
   cSubscript = iif(val(cHour) >= 12,'p','a')
   cHour = iif(val(cHour) > 12,str(val(cHour)-12,2),cHour)
   if val(cHour) = 0
      cHour = '12'
   elseif substr(cHour,1,1) = '0'
      cHour = ' '+substr(cHour,2)
   endif
   return ltrim(cHour)+':'+cMin+cSubScript

function NumTime(cTime) && converts 1:15a to 115
                                 && used for time math
   local chrTime
     chrTime = cTime
     if at('a',cTime) > 0 .and. substr(cTime,1,at(':',cTime)-1) = '12'
        chrTime = '00'+substr(cTime,at(':',cTime)+1)
     Elseif at('p',cTime) >0 .and. substr(cTime,1,at(':',cTime)-1) = '12'
        chrTime = '12'+substr(cTime,at(':',cTime)+1)
     Elseif at('p',cTime) > 0
        chrTime =  str( val( substr(cTime,1,at(':',cTime)-1) )+12,2)+;
                   substr(cTime,at(':',cTime)+1)
                
     else
        chrTime =  substr(cTime,1,at(':',cTime)-1)+;
                     substr(cTime,at(':',cTime)+1)
     endif
     Return val(chrTime)

function IncrementTime(nTime,nIncrement) && adds time to numeric time
   nTime = nTime+nIncrement
   nHours = val(substr(str(nTime,4),1,2))
   nMins = val(substr(str(nTime,4),3,2))
   if nMins >= 60
      nMins = nMins - 60
      nHours = nHours +1
   endif
   if nHours > 24 .or. ;
      (nHours = 24 .and. nMins > 0)
      nHours = 0
   endif
   strHours = ltrim(str(nHours,2))
   strMins  = ltrim(str(nMins,2))
   if len(trim(strHours)) < 2
      strhours = '0'+strhours
   Endif
   if len(trim(strMins)) < 2
      strMins = '0'+strMins
   Endif
   return val(strHours+strMins)
   
function IncrementChrTime(cChrTime,nIncrement)
   nNumTime       = CLASS::NumTime(cChrTime)
   nIncrementTime = CLASS::IncrementTime(nNumTime,nIncrement)
   return CLASS::NumToChrTime(nIncrementTime)


Endclass 

