Difference between revisions of "File date and time"

From BeebWiki
Jump to: navigation, search
m (1 revision)
m (1 revision)
 
(One intermediate revision by the same user not shown)
(No difference)

Latest revision as of 19:12, 8 March 2015

File server and OSFILE functions read and write dates and times in an internal format. These functions and procedures from the FInfo library provide a easy way of converting to and from the internal format.

   REM FNf_date - convert date into internal format
   REM FNf_time - convert time into internal format
   REM --------------------------------------------
   DEFFNf_date(d%,m%,y%):y%=y%-1981:=d%+m%*256+(y%AND15)*4096+(y%DIV16)*32
   DEFFNf_time(h%,m%,s%):=h%+m%*256+s%*65536
   :
   REM PROCf_date - extract date from internal format
   REM PROCf_time - extract time from internal format
   REM ----------------------------------------------
   DEFPROCf_date(d%):day%=d%AND31:month%=(d%AND&F00)DIV256
   year%=(d%AND&F000)DIV4096+(d%AND&E0)/2+1981:ENDPROC
   DEFPROCf_time(t%):hour%=t%AND255:minute%=(t%AND&FF00)DIV256
   second%=(t%AND&FF0000)DIV65536:ENDPROC

The following example reads a file's modification date and displays it:

   type%=FNfile(5,filename$)
   PROCf_date(X%!15)
   PRINT "Last modified on ";day%;"/";month%;"/";year%

The next example sets a file's modification date to 15th February 1992:

   A%=FNfile(5,filename$)     :REM Read existing attributes
   X%!15=FNf_date(15,2,1992)  :REM Overwrite date portion of attributes
   A%=FNfile(4,filename$)     :REM Write new attributes

Jgharston 11:33, 27 August 2008 (BST)