Easy Date Converter Advanced Version
Functions
 

Functions are of two kinds, built-in functions and defined functions.

The built-in functions are of two kinds:

  1. Functions for use only with output:
  2. Functions which can be used with output: and in other ways.
There are two functions of type 1:

These were described previously under Output. The remainder of this page concerns built-in functions of type 2.

Functions can have from zero to four arguments. (If zero then the parentheses are still required.) An argument in a function call must be a number, a previously-defined variable, today or result; it cannot be another function. A function (but not a defined function) can occur as a term in an IF statement (or in an ELSEIF, IFNOT or ELSEIFNOT statement).

The built-in functions of type 2 are currently:

The remainder of this page presents several examples of programs written in the EDC programming language illustrating the use of functions. The input files for these examples are contained in edca_examples.zip — click on that link to download the file.

Note that each statement must be placed on a separate line. Blank lines have no effect on the output. Indentation is optional, but is recommended for IF ... ENDIF constructs. All keywords and variables are case-insensitive, though, of course, case in text following output: is preserved.

Program files must be standard text files with extension .txt and should not contain tab characters. To run a program from within the Easy Date Converter program click on Input file and select the program file.


Example C1

This example shows the use of the INPUT: statement and also demonstrates use of the Val(), Date() and Suffix() functions.

As noted previously, this programming language has "increment" and "decrement" operators, += and -= respectively, which can be used with variables holding dates as well as those holding numbers. The use of the former (applied to a number) is shown in this example, where m += 1 means m = m + 1.

For convenience of display, the first input text has been split into three lines. The output is for year 2007 and day 13.

Input file Result in output window
//  Example C1
//  nth day of month

verbose = N
first date = CE
second date = CE
date format = Y-M-D

y = input: This program ascertains
the day of the week for a given day of the month
for all months of a given year.\n\nWhich year?

d = input: Which day of the month?

output: val(d);;
output: suffix(d);
output: day of all months for;
output: val(y);;
output: :
bl

m = 1
DO 12
    date = Date(CE,y,m,d)
    date
    m += 1
ENDDO
13th day of all months for 2007:

2007-01-13 CE, Saturday
2007-02-13 CE, Tuesday
2007-03-13 CE, Tuesday
2007-04-13 CE, Friday
2007-05-13 CE, Sunday
2007-06-13 CE, Wednesday
2007-07-13 CE, Friday
2007-08-13 CE, Monday
2007-09-13 CE, Thursday
2007-10-13 CE, Saturday
2007-11-13 CE, Tuesday
2007-12-13 CE, Thursday


Example C2

This example demonstrates use of the Add(), DayOf(), MonthOf() and DoW() functions. The output depends on today's date.

Input file Result in output window
//  Example C2

output: Shows the use of IF ... ELSEIF ...;
output: ELSEIFNOT ... ELSE ... ENDIF
bl

verbose = N
date format = Y-M-D
first date = CE
second date = CE

output: Today is;
today
bl

date = Add(today,4)
day = DayOf(date,CE)
month = MonthOf(date,CE)

DO 7

    result # 1

    IF DoW(result) = Monday THEN
        output: It's Monday ...;
    ELSEIF DoW(result) = Wednesday THEN
        output: It's Wednesday ...;
    ELSEIF DoW(result) = Friday THEN
        output: Thank God it's Friday ...;
    ELSEIFNOT DoW(result) = Wednesday
        output: It's not Wednesday ...;
    ELSE
        output: Another day ...;
        //  We should never reach here.
    ENDIF

    IF result < date THEN
        output: and not yet;
        output: MonthName(month,CE);
        output: val(day);;
        output: .
    ELSEIF result > date then
        output: and;
        output: MonthName(month,CE);
        output: val(day);
        output: has passed.
    ELSE
        output: and;
        output: MonthName(month,CE);
        output: val(day);
        output: has arrived.
    ENDIF
    bl

ENDDO
Shows the use of IF ... ELSEIF ... ELSEIFNOT ... ELSE ... ENDIF

Today is 2007-03-13 CE, Tuesday

2007-03-13 CE plus 1 day = 2007-03-14 CE, Wednesday
It's Wednesday ... and not yet March 17.

2007-03-14 CE plus 1 day = 2007-03-15 CE, Thursday
It's not Wednesday ... and not yet March 17.

2007-03-15 CE plus 1 day = 2007-03-16 CE, Friday
Thank God it's Friday ... and not yet March 17.

2007-03-16 CE plus 1 day = 2007-03-17 CE, Saturday
It's not Wednesday ... and March 17 has arrived.

2007-03-17 CE plus 1 day = 2007-03-18 CE, Sunday
It's not Wednesday ... and March 17 has passed.

2007-03-18 CE plus 1 day = 2007-03-19 CE, Monday
It's Monday ... and March 17 has passed.

2007-03-19 CE plus 1 day = 2007-03-20 CE, Tuesday
It's not Wednesday ... and March 17 has passed.


Example C3

This example again shows the use of variables, in this case, X, Y2 and DAYS_DIFF. A variable can have any name consisting of letters, digits, underscores and other characters, but must not begin with a digit and must not be a keyword ('today', 'if', etc.). Variable names are case-insensitive.

This example also demonstrates the use of DO ... EXITDO ... ENDDO.

Input file Result in output window
//  Example C3

verbose = N
first date = CE
second date = ORD
date format = Y-M-D

output: Today is;
today
bl

X = Add(4,today)

DO
    result # 1
    result # # X
    bl
    IF result = 0 THEN
        output: Arrived at;
        output: Dateval(X,ORD);;
        output: .
        bl
        EXITDO
    ENDIF
ENDDO

DAYS_DIFF = -1
Y2 = Subtract(5,today)

today
bl

DO
    result # DAYS_DIFF
    IF result = Y2 THEN
        EXITDO
    ENDIF
ENDDO
Today is 2007-03-13 CE = 2007-072 ORD, Tuesday

2007-03-13 CE plus 1 day = 2007-073 ORD, Wednesday
2007-03-14 CE to 2007-076 ORD = 3 days

2007-03-14 CE plus 1 day = 2007-074 ORD, Thursday
2007-03-15 CE to 2007-076 ORD = 2 days

2007-03-15 CE plus 1 day = 2007-075 ORD, Friday
2007-03-16 CE to 2007-076 ORD = 1 day

2007-03-16 CE plus 1 day = 2007-076 ORD, Saturday
2007-03-17 CE to 2007-076 ORD = 0 days

Arrived at 2007-076 ORD.

2007-03-13 CE = 2007-072 ORD, Tuesday

2007-03-13 CE minus 1 day = 2007-071 ORD, Monday
2007-03-12 CE minus 1 day = 2007-070 ORD, Sunday
2007-03-11 CE minus 1 day = 2007-069 ORD, Saturday
2007-03-10 CE minus 1 day = 2007-068 ORD, Friday
2007-03-09 CE minus 1 day = 2007-067 ORD, Thursday


Example C4

The use of the increment operator as applied to a date is shown in this example.

Input file Result in output window
//  Example C4

verbose = N
date format = Y-M-D
first date = CE
second date = CE

X = 2007-12-21 CE

do

    X += 1

    X # # 2007-12-25

    if result = 0 then
        output: It's;
        output: DoW(X);
        output: and it's Christmas!
    elseif result = 1 then
        output: Tomorrow is Christmas.
    elseif result < 0 then
        output: Christmas is past.
        if result < -1 then
            exitdo
        endif
    else
        output: It's;
        output: DoW(X);
        output: and it's only;
        output: Val(result);
        output: more days to Christmas.
    endif
    bl

enddo
2007-12-22 CE to 2007-12-25 CE = 3 days
It's Saturday and it's only 3 more days to Christmas.

2007-12-23 CE to 2007-12-25 CE = 2 days
It's Sunday and it's only 2 more days to Christmas.

2007-12-24 CE to 2007-12-25 CE = 1 day
Tomorrow is Christmas.

2007-12-25 CE to 2007-12-25 CE = 0 days
It's Tuesday and it's Christmas!

2007-12-26 CE to 2007-12-25 CE = -1 day
Christmas is past.

2007-12-27 CE to 2007-12-25 CE = -2 days
Christmas is past.


Example C5

The examples above have merely illustrated how to code in this programming language. Now a few examples will be given which have some relevance to calendrical studies.

This example shows the use of the input: statement. It also illustrates the use of open file, close file, display off and display on, and the add() function. The program asks for a start year and and end year, and performs computations on the specified range of years. The display is suppressed after a few lines, and restored to give the result. The full output is written to the file c5.txt.output.txt. The output below was obtained by specifying the range of years to be 2000 through 2500.

Input file Result in output window
//  Example C5

open file

output: This program find years whose
output: new year's eve occurs on a Saturday.
bl

start_year = input: Start year CE?
end_year = input: End year CE?

if start_year > end_year then
    output: The end year must not be;
    output: earlier than the start year.
    stop
endif

count = 0

year = start_year

do
    date = NewYearsDay(year,CE)

    date -= 1
    //  Date of new year's eve.

    if DoW(date) = Saturday then
        output: New year's eve;
        output: VAL(year);
        output: CE is a Saturday.
        count += 1
    endif

    year += 1
    if year > end_year then
        exitdo
    endif

    if year > add(start_year,80) then
	display off
    endif

enddo

display on

bl

if count = 0 then
    output: There are no new year's eve Saturdays
elseif count = 1 then
    output: There is one new year's eve Saturday
else
    output: There are;
    output: val(count);
    output: new year's eve Saturdays
endif

output: in the range;
output: val(start_year);
output: CE through;
output: val(end_year);
output: CE.

close file
[Output to file C:\Vb6\edca\batch2\c5.txt.output.txt]

This program find years whose
new year's eve occurs on a Saturday.

new year's eve 2006 CE is a Saturday.
new year's eve 2012 CE is a Saturday.
new year's eve 2017 CE is a Saturday.
new year's eve 2023 CE is a Saturday.
new year's eve 2034 CE is a Saturday.
new year's eve 2040 CE is a Saturday.
new year's eve 2045 CE is a Saturday.
new year's eve 2051 CE is a Saturday.
new year's eve 2062 CE is a Saturday.
new year's eve 2068 CE is a Saturday.
new year's eve 2073 CE is a Saturday.
new year's eve 2079 CE is a Saturday.

There are 72 new year's eve Saturdays
in the range 2000 CE through 2500 CE.

The results suggest that new year's eve Saturdays always occur at intervals of 5, 6 or 11 years. The intervals tend to form a repeating pattern of 6, 5, 6, 11, but sometimes there are irregularities, such at 6, 6, 6, 5, 6, 11.


Example C6

Another one:

Input file Result in output window
//  Example C6

start_year = 2000
end_year = 2012

output: Years in the range;
output: Val(start_year);
output: through;
output: Val(end_year)
output: in the CE, ISO and LPM calendars
output: which are leap years:
bl

year = start_year
DO

    IF IsLeapYear(year,CE) THEN
        output: The year;
    	output: Val(year);
    	output: CE is a leap year.
    ENDIF

    IF IsLeapYear(year,ISO) THEN
        output: The year;
    	output: Val(year);
    	output: ISO is a leap year.
    ENDIF

    IF IsLeapYear(year,LPM) THEN
        output: The year;
    	output: Val(year);
    	output: LPM is a leap year.
    ENDIF

    year += 1
    IF year > end_year THEN
	EXITDO
    ENDIF
ENDDO
bl

output: In the CE Calendar:
year = start_year
DO
    IF IsLeapYear(year,CE) THEN
        output: The year;
    	output: Val(year);
    	output: CE is a leap year.
    ENDIF
    year += 1
    IF year > end_year THEN
	EXITDO
    ENDIF
ENDDO
bl

output: In the ISO Calendar:
year = start_year
DO
    IF IsLeapYear(year,ISO) THEN
        output: The year;
    	output: Val(year);
    	output: ISO is a leap year.
    ENDIF
    year += 1
    IF year > end_year THEN
	EXITDO
    ENDIF
ENDDO
bl

output: In the LPM Calendar:
year = start_year
DO
    IF IsLeapYear(year,LPM) THEN
        output: The year;
    	output: Val(year);
    	output: LPM is a leap year.
    ENDIF
    year += 1
    IF year > end_year THEN
	EXITDO
    ENDIF
ENDDO
bl

output: Years in the three calendars which are
output: not mentioned above are not leap years.
Years in the range 2000 through 2012
in the CE, ISO and LPM calendars
which are leap years:

The year 2000 CE is a leap year.
The year 2003 LPM is a leap year.
The year 2004 CE is a leap year.
The year 2004 ISO is a leap year.
The year 2008 CE is a leap year.
The year 2009 ISO is a leap year.
The year 2009 LPM is a leap year.
The year 2012 CE is a leap year.

In the CE Calendar:
The year 2000 CE is a leap year.
The year 2004 CE is a leap year.
The year 2008 CE is a leap year.
The year 2012 CE is a leap year.

In the ISO Calendar:
The year 2004 ISO is a leap year.
The year 2009 ISO is a leap year.

In the LPM Calendar:
The year 2003 LPM is a leap year.
The year 2009 LPM is a leap year.

Years in the three calendars which are
not mentioned above are not leap years.


Example C7

This example illustrates the use of the Date() and DateVal() functions.

Input file Result in output window
//  Example C7

hyphen = Y
verbose = N

Output: Today is

x = today
output: DateVal(x,CE)
output: DateVal(x,JC)
output: DateVal(x,LPM)
output: DateVal(x,LPW)
output: DateVal(x,ISO)
output: DateVal(x,ORD)
output: DateVal(x,JDN)
bl

first date = CE

y = Date(LPW,2007,18,1)
second date = LPW
x # # y

y = Date(ISO,2008,33,7)
second date = ISO
x # # y

y = Date(ORD,2009,299)
second date = ORD
x # # y
Today is
2007-02-13 CE
2007-01-31 JC
2007-02-16 LPM
2007-08-2 LPW
2007-W07-2 ISO
2007-044 ORD
2,454,145 JDN

2007-02-13 CE to 2007-18-1 LPW = 69 days
2007-02-13 CE to 2008-W33-7 ISO = 551 days
2007-02-13 CE to 2009-299 ORD = 986 days


Example C8

This example also illustrates the use of the Date() and DateVal() functions and shows that the programming language allows use of fairly complex combinations of DO's and IF's.

Input file Result in output window
//  Example C8

hyphen = Y
verbose = N

year = 2007

output: The dates of the 2nd Tuesday in each
output: month of the CE and LPM calendars
output: for;
output: Val(year);
output: are respectively:
bl

month = 1
do
//  for each month

    cal = 1
    do
    //  for each calendar
        if cal = 1 then
            date = Date(CE,year,month,1)
        else
            date = Date(LPM,year,month,1)
        endif

        count = 0
        do
        //  for each day
            if DoW(date) = Tuesday then
                count += 1
                if count = 2 then
                    if cal = 1 then
                        date_ce = date
                    else
                        date_lpm = date
                    endif
                    exitdo
                endif
            endif
            date += 1
        enddo
        //  for each day

        cal += 1
        if cal > 2 then
            exitdo
        endif
    enddo
    //  for each calendar

    output: DateVal(date_ce,CE);
    output: and;
    output: DateVal(date_lpm,LPM)

    month += 1
    if month > 12 then
        exitdo
    endif

enddo
//  for each month
The dates of the 2nd Tuesday in each
month of the CE and LPM calendars
for 2007 are respectively:

2007-01-09 CE and 2007-01-09 LPM
2007-02-13 CE and 2007-02-09 LPM
2007-03-13 CE and 2007-03-09 LPM
2007-04-10 CE and 2007-04-09 LPM
2007-05-08 CE and 2007-05-09 LPM
2007-06-12 CE and 2007-06-09 LPM
2007-07-10 CE and 2007-07-09 LPM
2007-08-14 CE and 2007-08-09 LPM
2007-09-11 CE and 2007-09-09 LPM
2007-10-09 CE and 2007-10-09 LPM
2007-11-13 CE and 2007-11-09 LPM
2007-12-11 CE and 2007-12-09 LPM


Example C9

This example uses two functions concerning hexades (a concept unique to the Hermetic Leap Week Calendar). The output below is obtained by entering "2004" and "17" in response to the prompts "Enter start year:" and "Enter number of years:" respectively.

Input file Result in output window
//  Example C9

year = input: Enter start year:
num_years = input: Enter number of years:

do num_years

    year_in_hexade = YearInHexade(year)

    if year_in_hexade = 1 then
        bl
    endif

    output: Year;
    output: Val(year);
    output: LPM is year;
    output: Val(year_in_hexade);
    output: in a;

    if IsInShortHexade(year) then
        output: short;
    else
        output: long;
    endif

    output: hexade.

    year += 1

enddo
Year 2004 LPM is year 4 in a long hexade.
Year 2005 LPM is year 5 in a long hexade.
Year 2006 LPM is year 6 in a long hexade.

Year 2007 LPM is year 1 in a long hexade.
Year 2008 LPM is year 2 in a long hexade.
Year 2009 LPM is year 3 in a long hexade.
Year 2010 LPM is year 4 in a long hexade.
Year 2011 LPM is year 5 in a long hexade.
Year 2012 LPM is year 6 in a long hexade.

Year 2013 LPM is year 1 in a short hexade.
Year 2014 LPM is year 2 in a short hexade.
Year 2015 LPM is year 3 in a short hexade.
Year 2016 LPM is year 4 in a short hexade.
Year 2017 LPM is year 5 in a short hexade.

Year 2018 LPM is year 1 in a long hexade.
Year 2019 LPM is year 2 in a long hexade.
Year 2020 LPM is year 3 in a long hexade.


Example C10

Suppose that, perusing dates in the Common Era Calendar and month dates in the Hermetic Leap Week Calendar we conjecture that the first day in any CE month always occurs in the first week of an LPM month, or maybe it's the last day of any CE month. The program below was written to look for counterexamples to this conjecture (and it finds them). Note that the use of # (explained in Batch Processing) avoids the use of several output: lines. This example is also the first to use the function YearOf().

Input file Result in output window
//  Example C10

hyphen = Y
verbose = N

first date = CE
second date = LPM

year = 2002
month = 1

do 12
//  Do for month = 1 to 12 of year.

    date = Date(CE,year,month,1)
    //  First day of the CE month.

    date -= 1
    //  Last day of previous month.

    do 2
    //  Do last day of previous month
    //  and then first day of month.

        if DayOf(date,LPM) > 7
            date #
            output: Not in 1st week of month;
            output: MonthOf(date,LPM);
            output: of year;
            output: YearOf(date,LPM);
            output: LPM.
            bl
        endif

        date += 1

    enddo

    month += 1

enddo
2001-12-31 CE = 2002-01-08 LPM, Monday
Not in 1st week of month 1 of year 2002 LPM.

2002-01-01 CE = 2002-01-09 LPM, Tuesday
Not in 1st week of month 1 of year 2002 LPM.

2002-04-01 CE = 2002-04-08 LPM, Monday
Not in 1st week of month 4 of year 2002 LPM.

2002-07-01 CE = 2002-07-08 LPM, Monday
Not in 1st week of month 7 of year 2002 LPM.

2002-09-30 CE = 2002-10-08 LPM, Monday
Not in 1st week of month 10 of year 2002 LPM.

2002-10-01 CE = 2002-10-09 LPM, Tuesday
Not in 1st week of month 10 of year 2002 LPM.


Easy Date Converter Advanced Version Main Page
Date/Calendar Software Hermetic Systems Home Page