home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / nettos11.zip / MISC / NWDATE.PRG < prev    next >
Text File  |  1993-02-23  |  4KB  |  180 lines

  1. /*
  2.  * File......: NWDATE.PRG
  3.  * Author....: Glenn Scott / David Peterson
  4.  * CIS ID....: 76370,1532
  5.  * Date......: $Date$
  6.  * Revision..: $Revision$
  7.  * Log file..: $Logfile$
  8.  *
  9.  * This is an original work by Glenn Scott and David Peterson
  10.  * and is placed in the public domain.
  11.  *
  12.  * Notes: David Peterson reworked all the date code for 
  13.  * internationalization.
  14.  *
  15.  * Modification history:
  16.  * ---------------------
  17.  *
  18.  * $Log$
  19.  *
  20.  */
  21.  
  22. #include "netto.ch"
  23.  
  24. function _fndt2Str( dDate, cTime )
  25.   local cDt := "", aDate
  26.  
  27.   default dDate to ctod(""), ;
  28.           cTime to "99:99:99"
  29.  
  30.  
  31.   if dDate == ctod("") .or. cTime == "99:99:99"
  32.      cDt := repl( chr( -1 ), 6 )      // FFFFFFFFFFFFh
  33.   else
  34.      // Convert to international date format
  35.      cDt := _fndtonc(dDate) + _fnttonc(cTime)
  36.   endif
  37.      
  38.   return cDt
  39.  
  40. /* ------------------------------------------------------------------ */
  41.  
  42. function _fnStr2dt( cStr )
  43.   local dDate, cTime
  44.  
  45.   default cStr to repl( chr( - 1 ), 6 )     // FFFFFFFFFFFFh
  46.  
  47.   if cStr == repl( chr( -1 ), 6 )
  48.      dDate := ctod( "  /  /  ")
  49.      cTime := "99:99:99"
  50.   else
  51.      dDate := _fnnctod( subs( cStr, 1, 3 ) )
  52.      cTime := _fnnctot( subs( cStr, 4, 3 ) )
  53.   endif
  54.  
  55.   return { dDate, cTime }
  56.  
  57. /* ------------------------------------------------------------------ */
  58.   
  59. /*
  60.  * _fnnctod() - Convert Novell 3 byte date string to a Clipper date
  61.  *
  62.  */
  63.  
  64. function _fnnctod(cDate)
  65.    LOCAL dDate, cDateFormat := SET(_SET_DATEFORMAT)
  66.    SET(_SET_DATEFORMAT, "yy/mm/dd")
  67.    dDate  := ctod( str( BYTE2I( substr( cDate, 1, 1 ) ), 2 ) + "/" + ;
  68.                    str( BYTE2I( substr( cDate, 2, 1 ) ), 2 ) + "/" + ;
  69.                    str( BYTE2I( substr( cDate, 3, 1 ) ), 2 ) )
  70.    SET(_SET_DATEFORMAT, cDateFormat)
  71.    return dDate
  72.   
  73. /*
  74.  * _fndtonc() - Convert Clipper date into the Novell 3-byte date string
  75.  *
  76.  */
  77.  
  78. function _fndtonc(dDate)
  79.    LOCAL cNDate
  80.  
  81.    cNDate  := I2BYTE( year  (dDate) % 100 ) + ;
  82.               I2BYTE( month (dDate)       ) + ;
  83.               I2BYTE( day   (dDate)       )
  84.  
  85.    return cNDate
  86.   
  87. /*
  88.  * _fnttonc() - Convert a Clipper time to the Novell 3 byte time string
  89.  *
  90.  */
  91.  
  92. function _fnttonc(cTime)
  93.    LOCAL cNTime
  94.  
  95.    cNTime  := I2BYTE( val( subs( cTime, 1, 2 ) ) ) + ;
  96.               I2BYTE( val( subs( cTime, 4, 2 ) ) ) + ;
  97.               I2BYTE( val( subs( cTime, 7, 2 ) ) )
  98.  
  99.    return cNTime
  100.  
  101. /*
  102.  * _fnnctot() - Convert a Novell 3 byte time string to a Clipper time
  103.  *
  104.  */
  105.  
  106. function _fnnctot(cNTime)
  107.    LOCAL cTime
  108.  
  109.    cTime  := _fnstrz( BYTE2I( substr( cNTime, 1, 1 ) ), 2 ) + ":" + ;
  110.              _fnstrz( BYTE2I( substr( cNTime, 2, 1 ) ), 2 ) + ":" + ;
  111.              _fnstrz( BYTE2I( substr( cNTime, 3, 1 ) ), 2 ) 
  112.  
  113.    return cTime
  114.  
  115. /*
  116.  * _fnintod() - Convert Year, Month and Day values to a date
  117.  *
  118.  */
  119.  
  120. function _fnintod(nYear, nMonth, nDay)
  121.    LOCAL dDate, cDateFormat := SET(_SET_DATEFORMAT)
  122.    SET(_SET_DATEFORMAT, "yy/mm/dd")
  123.    dDate  := ctod( str( nYear,  2 ) + "/" + ;
  124.                    str( nMonth, 2 ) + "/" + ;
  125.                    str( nDay,   2 ) )
  126.    SET(_SET_DATEFORMAT, cDateFormat)
  127.    return dDate
  128.   
  129. /*
  130.  * _fndtoin() - Convert date to Year, Month and Day values.
  131.  * The values are returned as an array {Year, Month, Day}
  132.  *
  133.  */
  134.  
  135. function _fndtoin(dDate)
  136.    LOCAL nYear, nMonth, nDay
  137.  
  138.    nYear  := year  (dDate) % 100
  139.    nMonth := month (dDate)
  140.    nDay   := day   (dDate)
  141.  
  142.    return { nYear, nMonth, nDay }
  143.   
  144.  
  145. /*
  146.  * _fndtoic() - Convert Clipper Date to an international date
  147.  * in the form "yy/mm/dd"
  148.  *
  149.  */
  150.  
  151. function _fndtoic(dDate)
  152.    LOCAL cDate, cDateFormat := SET(_SET_DATEFORMAT)
  153.  
  154.    SET(_SET_DATEFORMAT, "yy/mm/dd")
  155.    cDate := dtoc(dDate)
  156.    SET(_SET_DATEFORMAT, cDateFormat)
  157.  
  158.    return cDate
  159.   
  160.  
  161. /*
  162.  * _fnictod() - Convert an international date in the form "yy/mm/dd"
  163.  * to a Clipper date
  164.  *
  165.  */
  166.  
  167. function _fnictod(cDate)
  168.    LOCAL dDate, cDateFormat := SET(_SET_DATEFORMAT)
  169.  
  170.    SET(_SET_DATEFORMAT, "yy/mm/dd")
  171.    dDate := ctod(cDate)
  172.    SET(_SET_DATEFORMAT, cDateFormat)
  173.  
  174.    return dDate
  175.  
  176. static function _fnstrz( n, w )
  177.   return padl( alltrim( str( n ) ), w, "0" )
  178.   
  179.  
  180.