home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / file2dat.zip / f2dtest.cmd next >
OS/2 REXX Batch file  |  1995-11-01  |  1KB  |  44 lines

  1. /* f2dtest - REXX program for testing the age of a specified file. */
  2. /* RRC 95-10-30 Original release. */
  3.  
  4. call RxFuncAdd SysLoadFuncs, RexxUtil, SysLoadFuncs
  5. call SysLoadFuncs
  6.  
  7. SemName = ARG(1)
  8. IF SemName = '' THEN DO
  9.      say 'Requires a filename parameter'
  10.      EXIT
  11. END
  12. FileDate = STREAM( SemName, 'C', 'query datetime' )
  13. Now = Time('S')/86400
  14. Today = Date('B') || SUBSTR(Now,2)
  15. NumericDate = File2Dat(FileDate)
  16. Age = Today - NumericDate
  17. AgeInt = Age % 1
  18. AgeFrac = Age - AgeInt
  19.  
  20. say 'File date is 'FileDate
  21. say 'File2Dat interprets this as: 'NumericDate
  22. say 'Today is 'Today
  23. say 'Thus the file is 'Age' days old'
  24. say 'Interpreted by FRACT2TIME, this is 'AgeInt' days -- 'FRACT2TIME(AgeFrac)' (h:m:s) old'
  25.  
  26. exit
  27.  
  28.  
  29. /* calculate time from fraction */
  30. FRACT2TIME: PROCEDURE                   /* calculate time from given value */
  31.     /* hours    = 24      =   24           */
  32.     /* minutes  = 1440    =   24 * 60      */
  33.     /* seconds  = 86400   =   24 * 60 * 60 */
  34.  
  35.     tmp = arg(1) + 0.0000001            /* account for possible precision error */
  36.  
  37.     hours   = (tmp * 24) % 1
  38.     minutes = (tmp * 1440 - hours * 60) % 1
  39.     seconds = (tmp * 86400 - hours * 3600 - minutes * 60) % 1
  40.  
  41.     RETURN RIGHT(hours,2,'0')':'RIGHT(minutes,2,'0')':'RIGHT(seconds,2,'0')
  42.  
  43. /* end of FRACT2TIME */
  44.