Last Modified Date/Time (Within a REBOL Script)Author: Carl Read It's common for pages on the Internet to have a "last modified" date and if you're building CGI webpages using REBOL it's a simple matter to automate this feature. The key to this is REBOL's MODIFIED? function which can allow the script to examine its own file for when it was last altered. (NOTE: The examples here can be used with standard REBOL scripts - it's not just for CGI.) Now you could and perhaps should use the date in the REBOL script's header for this, but this requires you to always remember to update it with every edit of the script which is, ahem, an easy thing to forget. By examining the file itself we ensure the date of the last modification will always be shown. To show MODIFIED? being used in this way we'll first use it in a REBOL/View script so it can easily be tested locally instead of on a website. In this first example the script is assumed to be called modified-example.r. When it is run, a word MOD is given the modified date of the script which is then displayed in a View layout...
There's problems with this though. If you decide to change the file-name of the script you'll also need to change the name of the file within the script. Also, if you use CHANGE-DIR in your script, MODIFIED? could be looking in the wrong directory for the file unless you've given it its full path. What would be better would be if we had a way of finding the script's file without needing to know its name or what directory it was in. Well REBOL allows us to do this. The SYSTEM/OPTIONS/SCRIPT object holds script's file-name and full path. So if we replace the file-name in our script with SYSTEM/OPTIONS/SCRIPT we have a method of accessing the modified date that can be used without change in any script. Doing this, we now have a script looking like this...
NOTE: If you're testing the above script at the REBOL Console use LAUNCH instead of DO to run it, otherwise SYSTEM/OPTIONS/SCRIPT will not contain the script's file-name. And finally, here's MODIFIED? used in this way in an example REBOL CGI script...
As you can see from that, the HTML parts of REBOL CGI scripts don't need to look much different from plain HTML documents. The CGI specific lines are these two...
Following the second of those in the script is the printing of the HTML document proper, which is in three parts, the middle part adding the modified date to the document. (If you're new to CGI but are interested in it, see the section devoted to it in the Network Protocols chapter of the REBOL/Core Guide.) A final note about dates: As used in the scripts above, they'll be displayed something like this...
To just show the date you could use...
while the following can be used to show the date and time but without the zone...
And speaking of zones, if you want to show GMT instead of local time, just subtract the zone from the time. ie...
|