The following example source program demonstrates the basic design of a AEGIS/cgi program, along with date handling and formatting:
; EASTER.AE - an AEGIS demonstration program
;
; Author: Andrew M. Dunn
;
; Purpose: Display the dates of Easter Sunday and Good Friday in any
; given year between 1900 and 2199
;
; Notes: This script assumes that the variable YEAR contains the
; four-digit numeric year. It is a good example of the
; "EASTER" date intrinsic.
;
; find out where we came from
BackClick=SYSTEM("REFERRER")
; validate the year
IF (YEAR < 1900) || (YEAR > 2199) THEN
PRINT("Sorry, the calculator only works for years between|n")
PRINT("1900 and 2199. Please click <A HREF=",BackClick,">here</A> to try again.|n")
END
ENDIF
; make an actual date (the DATEPART intrinsics only work on whole dates)
; (January 1st will do nicely)
ETest = CAT("01-01-",YEAR)
EDate = DATEPART("EASTER",ETest)
; get today's date
Now = CONVERT("DATE","TODAY")
; choose the most elaborate date display format (weekday, commas, etc.)
CALL SYSTEM("FDATEFMT","CDW")
; find out if we are looking in the future or the past, so we can make the
; grammar and tense of the output statement somewhat literate
EDiff = DATEDIFF(EDate,Now)
IF (EDiff >= 0) THEN
PRINT("In the year |B",YEAR,"|b, |IEaster|i will be on |B",CONVERT("FDATE",EDate),"|b, ")
ELSE
PRINT("In the year |B",YEAR,"|b, |IEaster|i was on |B",CONVERT("FDATE",EDate),"|b, ")
ENDIF
; now do some date math, since Good Friday is two days before Easter Sunday
GFDate = DATEADD(EDate,-2)
; make the date less elaborate for the second date
CALL SYSTEM("FDATEFMT","")
GFSTRG = CONVERT("FDATE",GFDate)
; get length so we can chop off the year
GFLEN = STRLEN(GFSTRG)
; and explain it to the viewer
PRINT("with |IGood Friday|i on |B",LEFT(GFSTRG,GFLEN-5),"|b.|n")
PRINT("Please click <A HREF=",BackClick,">here</A> to compute another date.|n")
END
The following snippet of HTML demonstrates the FORM code needed to invoke it:
<FORM METHOD=GET ACTION=/cgi-bin/aecgi>
<INPUT TYPE=HIDDEN NAME=JOB VALUE=EAST>
To see the program run, enter the year here
<INPUT TYPE=TEXT NAME=YEAR VALUE=2004> and
click <INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=SUBMIT>.
</FORM>
And here is the form, so you can try running the example for yourself: