Easy Date Converter Advanced Version The EDC Programming Language Easy Date Converter Advanced Version not only processes date operations sequentially, it also implements an interpreter for a programming language, called "EDC". The previous two sections on Batch Processing and Using 'today' and 'result' have already partially defined this programming language by describing the use of date operations and sequences of date operations. This section describes the use in EDC of variables, control structures and input/output. The following pages explain the use of functions, defined functions and subroutines.
Variables and Assignment In the EDC programming language variables such as X and Y may be used. Variable names are not case-sensitive; 'a' names the same variable as 'A'.
Variables do not have types, except according to the intention of the programmer. All variables store numbers (more exactly, signed long integers). A "date" variable is a variable whose value is regarded by the programmer as holding a Julian day number. All other variables hold ordinary numbers (also signed long integers).
A date variable does not hold a date in any particular calendar; it is simply a Julian day number. It may be expressed as a date in a particular calendar only after a particular calendar is specified, which is why many of the functions mentioned in the next section take a calendar argument.
Values can be assigned to variables, as in:
year = 3201 jdn = 2,100,019 x = y x += 1 y -= 3 x += yx += y means x = x + y and x -= y means x = x - y.
Values can be assigned to date variables as well as to number variables, but care must be taken that the appropriate date format is in effect, e.g.:
date format = M/D/Y date_ce = 12/31/2001 CE date format = Y-M-D date_lpm = 2003-11-01 LPMIf the calendar designation (LPM etc.) is omitted then it defaults to CE.
Control Structures The following keywords are used to specify the way operations in the program are carried out.
- IF ... THEN ... ENDIF
- IF ... THEN ... ELSE ... ENDIF
- IF ... THEN ... ELSEIF ... THEN ... ELSE ... ENDIF
- DO ... ENDDO
- DO ... EXITDO ... ENDDO
- SKIP ... ENDSKIP
- STOP
These keywords are case-insensitive, so you can use if ... then ... endif and so on.
In place of IF one may use IFNOT, as in IFNOT ... THEN ... ENDIF, with the obvious meaning. Similarly in place of ELSEIF one may use ELSEIFNOT, so that the following is possible:
IFNOT a = 1 THEN ... ELSEIFNOT b = 1 THEN ... ENDIFAs the conditional expression in IF and IFNOT statements the usual comparisons between variables, x < y, etc., can be made, as well as x != y, which means: x is not equal to y.
DO may have a do-count, as in DO 3, meaning that the statements between that DO and the corresponding ENDDO are to be executed 3 times (unless an EXITDO is encountered).
All of these keywords except THEN must occur at the beginning of a line. THEN is optional, but if present must occur at the end of a line.
DO ...ENDDO and IF ... ENDIF constructs may be nested up to fifty levels. An IF ... ENDIF construct may occur within a DO ... ENDDO construct and vice-versa.
Note that keywords do not include spaces: EXITDO (not EXIT DO), ELSEIF (not ELSE IF) and IFNOT (not IF NOT).
STOP and SKIP ... ENDSKIP are useful during program development, as in:
some code SKIP this code OK ENDSKIP this code being worked on STOP // Don't process the rest some codeSKIP ... ENDSKIP is also useful as follows:
SKIP A multi-line comment goes here. ENDSKIP
This example shows the use of three variables, y, end_year and date.
Input file Result in output window
// Example B4 // Calculates Julian day numbers of // new years day 2007-2020 // in the Hermetic Leap Week Calendar verbose = N first date = LPM second date = JDN y = 2007 end_year = 2020 do date = Date(LPM,y,1,1) date y += 1 if y > end_year exitdo endif enddo
2007-01-01 LPM = 2,454,095 JDN, Monday 2008-01-01 LPM = 2,454,459 JDN, Monday 2009-01-01 LPM = 2,454,823 JDN, Monday 2010-01-01 LPM = 2,455,194 JDN, Monday 2011-01-01 LPM = 2,455,558 JDN, Monday 2012-01-01 LPM = 2,455,922 JDN, Monday 2013-01-01 LPM = 2,456,286 JDN, Monday 2014-01-01 LPM = 2,456,650 JDN, Monday 2015-01-01 LPM = 2,457,014 JDN, Monday 2016-01-01 LPM = 2,457,385 JDN, Monday 2017-01-01 LPM = 2,457,749 JDN, Monday 2018-01-01 LPM = 2,458,113 JDN, Monday 2019-01-01 LPM = 2,458,477 JDN, Monday 2020-01-01 LPM = 2,458,841 JDN, Monday
Output to the Screen All output goes to the textbox in the Easy Date Converter software unless a display off statement has been executed (see, e.g., Example C5). This can be copied to the clipboard and pasted into a text editing program to be printed.
If a variable such as some_date holds a date then the statement date will generate a line of output which is the same as what results from having the value of some_date in the textbox labelled "First date" and clicking on "Compute". This is illustrated in Example B4 above.
Alternatively, output is accomplished by means of the output: statement as explained in Batch Processing. The value of a numerical variable is output using the Val() function, and of a date variable using the DateVal() function:
- Val(number_variable) returns the value of its argument (assumed to be a numerical variable).
- DateVal(date_variable,calendar_specification) returns the value of its argument (assumed to be a date variable) as a date in the calendar specified.
To output the value of the numerical variable year one uses output: Val(year). To output the value of the date variable date as a date in the CE calendar or in the LPM calendar one uses output: DateVal(date,CE) or output: DateVal(date,LPM) respectively. (Don't forget the terminal colon in output:, though the software will tell you if it is missing.)
This example shows the use of the IF ... ELSEIF ... ELSE ... ENDIF construct, and also demonstrates DO n and the use of variables and the output: statement.
Input file Result in output window
// Example B5 // This demonstrates the use of nested IFs. a = 0 b = 0 DO 4 IF a = 0 THEN IF b = 0 THEN output: 1. a = 0 and b = 0 ELSE output: 2. a = 0 and b != 0 ENDIF ELSEIF b = 0 THEN output: 3. a != 0 and b = 0 ELSE output: 4. a != 0 and b != 0 ENDIF IF a = 0 THEN IF b = 0 THEN b = 1 ELSE a = 1 b = 0 ENDIF ELSE b = 1 ENDIF ENDDO
1. a = 0 and b = 0 2. a = 0 and b != 0 3. a != 0 and b = 0 4. a != 0 and b != 0
Output to a File This is controlled by means of the open file, close file and append file statements, which are explained at in the section on Batch Processing. The use of open file and close file is illustrated in Example C5.
File output is normally required only when there is so much output that the textbox becomes full (e.g., if you have a file containing many thousands of Julian day numbers to be converted to Common Era dates). In this case (if a file has been opened) then output will continue to the file until either the batch processing is finished or there is no space left on the disk.
If batch processing causes the textbox to fill up (or you just wish to try out the file output) then place open file at the start of the batch file (or program file) and close file at the end, and all output will go to a file (in the same folder as the batch file) whose name is the same as the batch file except that .output.txt. is appended.
Input The principal input is the program file being processed. Variables in the program may be initialized as described above, e.g., start_year = 2000, date3 = 2007-02-11 CE and todays_date = today.
Input data may also be included in the program text to be assigned to elements of an array. This is explained in the section on Arrays.
Input from a user while a program is running may be accomplished by the use of the input: statement, which assigns user input to a variable. E.g., when the statement year = input: Which year CE? is executed an input box will be displayed and any numerical value entered by the user will be stored in the given variable. Newlines can be included in the prompt as \n, e.g.:
year = input: This program calculates first and last Sundays in all months of a year.\n\nWhich year?
which produces:
Dates may be input by a user in the same way by using the date input: statement, e.g.,
date2 = date input: Enter a date: Dates entered in this way should have an appended calendar specification, e.g., 2033-02-11 JC. If lacking then the date is assumed to be a CE date.
The use of the input: statement is illustrated in Example C1, Example C5 and in Example D4.
Error Messages The Easy Date Converter Advanced Version software performs extensive error checking when a program is run. There are many different error messages which can occur, most of which give the line number at which the error occurs. Thus it is recommended to compose programs using an editor which shows line numbers (and which allows indentation of blocks of code).
Easy Date Converter Advanced Version Main Page Date/Calendar Software Hermetic Systems Home Page