Decoding the timestamp in class libararies and forms

I was asked

Is there a way to translate the timestamp in a VCX to a human readable format?  

Visual Foxpro puts a timestamp on many records in the table that represents a form or class library. Historically this field was used to match records across supported platforms: DOS, Mac, Unix, Windows.

The VFP reserved variable “_screen” is an object reference to the Form instance that represents the VFP desktop. Because it’s a form instance, you can save it as a class using the SaveAsClass method. This will cause a timestamp record to be created that we can use to run the sample code. The sample code delays 3 seconds, creates a subclass of the form, adds a button, then shows the timestamps of the items in the class library.

The timestamp is in a standard format.

ERASE t.vcx

_screen.AddObject("btn","commandbutton") && add a button to the desktop

_screen.SaveAsClass("t.vcx","myform") && create class myform in a target file t.vcx

INKEY(3) && delay 3 seconds

MODIFY CLASS xx OF t.vcx as myform FROM t.vcx nowait && create a subclass of myform in the same file

ASELOBJ(aArray,1) && get an object reference to the class in the designer

aArray[1].addobject("btn2","commandbutton") && and btn2 to the class

aArray[1].btn2.top=200 && move it down so it doesn't hide btn

KEYBOARD "Y" && a "y" in the "Do you want to save changes")

RELEASE WINDOWS "Class designer" && close the designer

USE t.vcx && open the table

SCAN FOR timestamp!=0 && look for timestamps

      ?timestamp,DecodeTimeStamp(timestamp),objname+" "+class

ENDSCAN

PROCEDURE DecodeTimeStamp(nTimestamp as Number) as Datetime && see https://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/filetimetodosdatetime.asp

nDate=BITRSHIFT(nTimestamp,16)

      nTime=BITAND(nTimestamp,2^16-1)

     

      nYear=BITAND(BITRSHIFT(nDate,9),2^8-1)+1980

      nMonth=BITAND(BITRSHIFT(nDate,5),2^4-1)

      nDay=BITAND(nDate,2^5-1)

      nHr=BITAND(BITRSHIFT(nTime,11),2^5-1)

      nMin=BITAND(BITRSHIFT(nTime,5),2^6-1)

      nSec=BITAND(nTime,2^5-1)

      RETURN DATETIME(nYear,nMonth,nDay,nHr,nMin,nSec)

RETURN

 

48662