GCL Home ] [ CGI Tutorial ] [ Home ]

Creating Timers with Graphic Counter Language

Starting with version 2.00, you can use GCL to create timers. GCL allows you to use the same source file for the creation of a timer you use for a counter. The only difference is in command line switches that tell GCL how the particular source file is to be interpreted.

In GCL terminology, a timer is a graphic (or textual) representation of current date, time, and time zone. You can display them all, or just one or two of them.

Various counter programs on the web can be used for the display of date and time. From what I have seen, they typically show the date as month-day-year, and time as hours:minutes(:seconds) followed by am or pm. This is the way date and time are usually shown North America, and probably other English speaking countries.

But the web is international. No matter where you live, your web page will be visited by people from various countries speaking various languages. From day one, GCL was designed with an international audience in mind. This is why timers created with GCL are not formatted to American customs but to the international standard defined by ISO 8601.

The standard requires that date should be shown either as CCYY-MM-DD or CCYYMMDD, where CC stands for century, YY for year, MM for month and DD for day of the month, each shown as two digits even if lesser than 10.

Time is to be shown in 24-hour format. Minutes may be separated from hours (and seconds from minutes) by a colon (:), or just placed together with no separators. If both date and time are shown together, they are separated by the capital letter T.

Finally, the time zone may be shown if necessary. If the time zone is UTC (Universal Time Coordinated, formerly known as GMT), it should be indicated by appending the capital letter Z. Otherwise, it should be shown as the number of hours (and possibly minutes) from UTC, preceded by a minus sign (-)West of UTC, or a plus sign (+) East of UTC.

GCL follows the ISO standard. So, for example, at the time you fetched this page for my web server, it was , which is to say .

Defining Time Zone

In GCL parlance time zone can be defined by either the utc keyword or the stz keyword. The former is self-explanatory. The latter stands for Server Time Zone, which is the local time zone of the web server.

In reality, you may want to use a time zone that differs from either. For example, you may want to display current time at wherever you live, but your web server may be physically located somewhere else. I live in Rhinelander, Wisconsin. But the server for this web site is in Pittsburgh, Pennsylvania (hosted by pair Networks, in case youre curious). But in the example above, I showed you the time as it is in Rhinelander, not in Pittsburgh. How did I do it? By using the following line in my source file:

stz - 3600

That tells GCL to display time (and date) as it is 3600 seconds (one hour) West of Pittsburgh (the server time zone).

Now, suppose I wanted to use the time zone of Bratislava, Slovakia, the place I was born and raised in. I could instruct GCL to display time as it is one hour East of UTC:

utc + 3600

Unfortunately, I would have to change my source file twice a year: Once when switching from standard time to daylight-saving time, and once when switching back. Instead, I could simply use:

stz + 21600

This tells GCL to display time as it is 21600 seconds (6 hours) East of Pittsburgh (the server time zone). Since the server time adjusts for standard and daylight-saving time automatically, it makes more sense to use it as reference.

Copyright © 1999 G. Adam Stanislav
All rights reserved

Telling GCL to Create a Timer

As mentioned at the start of this page, you tell GCL you want it to produce a timer by using command line parameters. Here they are:

  • The -a parameter forces GCL to show the date.
  • The -m parameter tells it you want to see the time.
  • The -z parameter makes it show the time zone.
You can combine them as necessary. And, of course, you can use the -t parameter to produce text output for the use with SSI.

You can also place these command line parameters at the end of the #! line in your source code (it appears this is what you have to do with SSI, at least I have not figured out any other way).

Additionally, you can use the seconds keyword if you want GCL to show the seconds (otherwise, it only shows hours and minutes).

This is the source code I used to show you my local time above:

#!/usr/bin/gcl -tamz
stz - 3600

I named the file winow.cgi and inserted it here using the following SSI directive and HTML code:

<b><!--#exec cgi="winow.cgi" --></b>

Again, the result is

Customizing Text Timer Characters

You can instruct GCL not to show the dashes, colons, the T, and the Z (of course, if you do not want the Z to show up, you can just not use the -z switch). You can also replace them with different characters. The proper keywords are dash, colon, time, and zone. These must be followed by none if you do not want them displayed.

If you want to change them, follow each keyword by an equal sign (=), and then either an integer representing the ASCII code of the character, or the character itself between double quotes. If you want to use the double quote character, precede it by a backslash... and if you want to use the backslash, precede it by a backslash too.

So, to replace the colon with a backslash, you would use the following line:

colon = "\\"

Lets consider a more likely example now. Lets take winow.cgi, and modify it not to use dashes and colons, while replacing the T with an at sign (@). Our modified source code would look like this:

#!/usr/bin/gcl -tamz
stz - 3600
dash none
colon none
time = "@"

Now you may be wondering if deleting the dashes will have an adverse effect on displaying the time zone. After all, GCL uses the same ASCII character to display a dash as it does for the minus sign. The answer to your question is: No. Even though GCL uses the same ASCII character for the dash and the minus sign by default, it treats them as separate logical characters.

Here is the current output of the above source code:

By the way, if you use an ASCII character with value below space (32), or an integer less than 32, the effect will be the same as using the none keyword.

Although I am ending here for now, I will add more soon!

GCL Home ] [ CGI Tutorial ] [ Home ]