Time Algorithms

Last update:
May 16, 2001

To make life easy Ronald Scheepstra made available his vocab that calculates the Julian date.  The vocab is on the Pragma Various downloads page (www.logicalbusiness.com/d_variou.htm).  You can find instructions from Ronald at the end of this documentation. 

Thanks Ronald!

 

Days Between Dates, Day Of The Week

It is not a trivial matter to compute the day of the week on which a given event occurred. The arithmetic involved is convoluted and conditional. The Gregorian calendar, adopted in 1582, provides for months which are not arranged so that seven day multiples make up an entire month. The seven days of the week do not regularly appear on a given date because there are twelve months with between 28 and 31 days. Throw in leap years and it becomes clear that some computational help is needed to keep track.

The problem is further complicated by the fact that every fourth year is not a leap year. Only century years evenly divisible by 400 are leap years. Three out of every four century years omit the leap-day - 1900, 1800 and 1700 A.D. were not leap years. This fact may be lost on many people alive today. Most of us will never see a year which ends in 00 which is not a leap year. Those of us alive in 1900 saw one. The next will not occur until the year 2100. The beginning of the millennium, 2000 A.D. will be a leap year.

The program below makes use of these anomalies. The algorithm calls for computing a variable F for each date. F is the factor for that date. It is computed as follows:

If the month is January or February, then

F = (365Y) + D + 31(M - 1) + INP (Y - 1)/4) - INP (3/4(INP[((Y - 1)/100) + 1]))

otherwise use,

F = (365Y) + D + 31(M - 1) - INP (.4M + 2.3) + INP (Y/4) - INP (3/4[INP(Y/100)+1])

where,

Y = current year, e.g. 1981
M = month number from Jan (1) to Dec (12)
D = day of the month from 1 to 31

Once the factor, F, has been computed the day of the week can be found from:

W = F + [INP(- F/7)*7]

where, W is the day of the week such that:

W = 0 for Saturday,
W = 1 for Sunday,
...
W = 6 for Friday.

The number of days between dates is simply the difference between the two factors for each date.

 

Example:
What day of the week was Pearl Harbor attacked (December 7, 1941). Answer: Sunday

Example:
How many days transpired between that day and the date of the Japanese surrender on August 14, 1945. Answer: 1346 days

 

The INP Function

The function INP has been used in place of INT. Many computers do not have INP. The difficulty with INT is that it gives the integer part of an expression only when the argument is greater than or equal to zero. When the argument is negative, INT gives unexpected results.

For example,

INT(- 4.7) = -5 while INP(- 4.7) = - 4

It is more appropriate to use INP when the integer part is desired. INP can be obtained from INT, the greatest integer function, using the following:

for all X >0,

INP(X) = INT(X)

for all X <0,

INP(X) = INT(X) + 1

The difference between the two functions is of no consequence if no negative arguments to the functions are involved.

 

Julian Date

While the time reckoned by a calendar may seem a convenient way to keep track of time, it is enormously inconvenient as a mechanism for regulating the rhythms of our lives. Some absolute count of time from a chosen reference point is desirable.

The interval between any two events, be they financial, meteorological, astronomical or ecclesiastical could be computed by simply subtracting two numbers, i.e., if dates were absolute numbers. If only we had a way of assigning numbers to dates that spanned the passage of months and years. There is such a system. The universally adopted system for the continuous reckoning of time is called the Julian Date. This represents a continuous count of time in days and fractions thereof since January 1, 4713 B.C.

Although the inaccuracies in the Julian calendar caused reforms by Pope Gregory XIII in 1582, the Julian date is not so called because of its relationship to the Julian calendar. The modification of the lap year structure for century years led to the current calendar system. The Julian calendar was almost 10 days behind seasonal time. So October 5, 1582 was declared to be October 15 and then days were dropped from the calendar. The Julian calendar was 365.25 days long. Every fourth year, without exception, was a leap year. There are actually 365.2422 days in the solar year. The difference was responsible for the ten day discrepancy.

The Gregorian reform removed three leap days every 400 years by decreeing that years ending in two zeroes - century years - are only leap years when they are divisible by 400. Since these reforms were instituted by a catholic patriarch they were not well received in many non-catholic countries. More than a century passed before some Protestant lands followed. Britain switched in 1752. Time before 1752 was Old Style, o.s. and time after 1752 was New Style, n.s.

In America, George Washington was born on February 11, 1732 (o.s.). By the time he was an adult his birthday had been shifted to February 22, 1732 (n.s.). France moved to the Gregorian system under Napoleon in 1806. Turkey didn't convert until 1927. Many countries near the equator did not feel the urgency that seasonal shifting presented for countries in the temperate zones. When it's always warm, even in January, who worries about winters in July.

The strange starting point for reckoning the Julian Date, January 1, 4713 B.C., is not arbitrary. It was suggested in 1582 by an Italian scholar of Greek and Hebrew named Joseph Scaliger. He reckoned that 4713 B.C. was the beginning of the current Julian period of 7,980 years. This is the product of the 28 year solar cycle - the interval at which all dates recur on the same day of the week: the lunar cycle of 19 years which contains an integral number of lunar months; and the indiction or tax period of 15 years introduced by Constantine in 313 A.D. The product of those three numbers: 28 X 19 X 15 = 7980. The last time those periods started simultaneously was 4713 B.C. It will not happen again until 3267 A.D. Scaliger's proposal reduced the dating problems associated with the many calendar reforms. Ecclesiastical approval was most important. His system enjoyed the advantage of predating the ecclesiastically approved date of creation, October 4, 4004 B.C. The system was named after Scaliger's father, Julius Caesar (sic) Scaliger and is not associated with the Julian calendar.

December 25, 1981 has a Julian Date of 2,444,964. January 1, 1978 at midnight (0 hours UT) is JD 2,443,509.5, while July 21, 1978 at 1500 hours UT is JD 2,443,711.125. Julian dates are regularly carried out to fractions of a day. The Julian Date can be computed from the expression below:

JD = K - 32075 + 1461 *(I + 4800 + (J - 14)/12)/4 + 367* (J -2 - (J - 14)/12*12)/12 - 3*((I + 4900 + (J - 14)/12)/100)/4

This expression was developed by Henry Fliegel and Thomas Van Flandern and appeared in the Communications of the ACM, Volume 11, 1968. It is important to note that this is a FORTRAN statement and assumes that the variables I, J and K are integers and will operate using the rules of FORTRAN integer arithmetic. I is the current year, J is the number of the month and K is the day of the month. December 25, 1981 would be: I = 1981, J = 12 and K = 25.

In BASIC the expression is a bit more complex. It requires the introduction of the INP function - INT will not work - and some judicious use of parentheses. The section just prior to this one, features an explanation of INP versus INT.

Some astronomical phenomena relating to space exploration pose minor accuracy problems when the conventional Julian Date is used. The Julian Date does not begin at midnight, when the day is born. Rather, it begins at noon. Any computation done at 0 hours UT contains the decimal suffix of .5, this is inconvenient. The seven digit numbers also pose precision problems when stored in computers both on the ground and onboard satellites. So the Julian Date for Space (JDS) was developed and defined as:

JDS = JD - 2,436,099.5

This system starts at midnight UT on September 17, 1957. This is the first Julian day divisible by 100 prior to the launch of the first manmade satellite by the Soviet Union on October 4, 1957.

The program does not calculate fractional days. It could easily be modified to do so. The algorithm used is valid for any date in the Gregorian calendar.

The problem of converting the Julian Date back into a calendar date is a bit different. The algorithm cannot be so compact. Fliegel and Van Flandern offered the following brief subroutine to convert back to calendar dates. It is in FORTRAN.

SUBROUTINE DATE (JD,I,J,K)
L = JD + 68569
N = 4* L/146097
L = L - (146097*N +3)/4
I = 4000*(L + 1)/1461001
L = L - 1461* I/4 + 31
J = 80*I /2447
K = L - 2447*J / 80
L = J/11
J = J + 2 - 12*L
I = 100*(N - 49) + I + L
RETURN
END

The Julian Date is not just an astronomical unit. It has applications in any branch of study where an accurate reckoning of the passage of days is needed. Banking, accounting, biology, meteorology, geology, anthropology, all can benefit from using Julian dates to compute the time elapsed in days between temporal events.

Example:
Compute the Julian date for August 29, 1981. Answer: 2444846.

 

stop.gif (975 bytes) It seems that in the subroutine to calculate the Julian Date back to calendar date there is a mistake. 
The mistake is in the line that says:

J = 80* I/2447

Instead it should say

J = 80*L/2447

The source that we used already contains the error.  Thanks to Ronald Scheepstra for pointing it out.

 

 

Acknowledgments:

Stephen J. Rogowski,
Computers for Sea & Sky
Creative Computing Press, Morristown, New Jersey 07960 - ISBN: 0-916688-38-0

 

Ronald Scheepstra,
November 10, 1998

I am re-programming my software from Pragma 3 to Pragma 4. That is not an easy task if you want to do it right. One of my major problems was that the 'Monolith' utilities did not work with Pragma 4. I used those frequently, also when it came to time and date calculations.

I had to re-write the whole story. Difficult:-(. Until Paul Hotz gave me the following source code:

int CConvert::YYYYMMDDToJulianDate (CString date)
{
int length, day, month, year;
int j_date;
int z, j1, j2, j3;

length = date.GetLength();
if (length != 8)
return 0;

year = atoi(date.Left(4));
month = atoi(date.Mid(4,2));
day = atoi(date.Mid(6,2));

// the algorithm for the Julian date has been copied from // Computers for Sea & Sky by Stephen J. Rogowski, 1981
z = (month - 14) / 12;
j1 = day - 32075 + Inp(1461*((year + 4800 + Inp(z))) / 4);
j2 = Inp(367 * (month - 2 - Inp(z) * 12) / 12);
j3 = - 3 * Inp(Inp(( year + 4900 + Inp(z))/100)/4);
j_date = j1 + j2 + j3;

return j_date;
}


To calculate the Julian date back into a Gregorian date I took the following FORTRAN subroutine as an example:


JD: Julian Date

L = JD + 68569
N = 4 * L / 146097
L = L - (146097 * N + 3) / 4
I = 4000 * (L + 1) / 1461001
L = L - 1461 * I / 4 + 31
J = 80 * L / 2447
K = L - 2447 * J / 80
L = J / 11
J = J + 2 - 12 * L
I = 100 * (N - 49) + I + L


The verb I created using the first routine to calculate from Gregorian to Julian date:

Verb CONVERT DATE TO JULIAN

The number of objects this verb uses is 2

The name of object number 1 is NOUN TO CONVERT
The prompt for object number 1 is from date
The name of object number 2 is NOUN TO EDIT
The prompt for object number 2 is into noun

1 COMMENT text is Noun to convert a 'normal' date to
2 COMMENT text is a Julian date. Extracted from a program
3 COMMENT text is written by the famous Paul Hotz
4 COMMENT text is ****************************************
5 COMMENT text is First we extract the values needed from
6 COMMENT text is the date
7 INIT JD DATE
8 EXTRACT from noun NOUN TO CONVERT from position 1 layout 4 into noun YEAR
9 EXTRACT from noun NOUN TO CONVERT from position 5 layout 2 into noun MONTH
10 EXTRACT from noun NOUN TO CONVERT from position 7 layout 2 into noun DAY
11 COMMENT text is ----------------------------------------
12 COMMENT text is first line: z = (month - 14) / 12;
13 SUBTRACT the value of 14 from the value of MONTH
14 DIVIDE the value DIFFERENCE by 12
15 COPY the value QUOTIENT to the noun Z-VALUE
16 INP into noun Z-VALUE
17 COMMENT text is ----------------------------------------
18 COMMENT text is second line: [z is already INP]
19 COMMENT text is j1=day - 32075 + Inp(1461*((year+4800+Inp(z))) / 4
20 ADD the value YEAR to the value 4800
21 ADD the value SUM to the value Z-VALUE
22 MULTIPLY the value SUM by the value 1461
23 DIVIDE the value PRODUCT by 4
24 INP into noun QUOTIENT
25 SUBTRACT the value of 32075 from the value of DAY
26 ADD the value QUOTIENT to the value DIFFERENCE
27 COPY the value SUM to the noun J1-VALUE
28 COMMENT text is ----------------------------------------
29 COMMENT text is third line: (z is already inp)
30 MULTIPLY the value Z-VALUE by the value 12
31 SUBTRACT the value of 2 from the value of MONTH
32 SUBTRACT the value of PRODUCT from the value of DIFFERENCE
33 MULTIPLY the value DIFFERENCE by the value 367
34 DIVIDE the value PRODUCT by 12
35 INP into noun QUOTIENT
36 COPY the value QUOTIENT to the noun J2-VALUE
37 COMMENT text is ----------------------------------------
38 COMMENT text is fourth line:
39 COMMENT text is j3 = - 3*Inp(Inp((year+4900+Inp(z))/100)/4)
40 ADD the value YEAR to the value 4900
41 ADD the value SUM to the value Z-VALUE
42 DIVIDE the value SUM by 100
43 INP into noun QUOTIENT
44 DIVIDE the value QUOTIENT by 4
45 INP into noun QUOTIENT
46 MULTIPLY the value -3 by the value QUOTIENT
47 COPY the value PRODUCT to the noun J3-VALUE
48 COMMENT text is ----------------------------------------
49 COMMENT text is Last line:
50 COMMENT text is NOUN TO EDIT = j1 + j2 + j3
51 ADD the value J1-VALUE to the value J2-VALUE
52 ADD the value SUM to the value J3-VALUE
53 COPY the value SUM to the noun NOUN TO EDIT

In the noun NOUN TO EDIT is the Julian date copied. This is 2000 compatible and can be used in interest-calculations etc.

The following verb is for calculating the Julian date back to a normal date. Easy to use. I had some problems with it. This is because in some publications (not only on the website) the FORTRAN subroutine was not correct.  At some point a L value was changed into an I value. I was beginning to believe that you could not calculate a Gregorian date from a Julian date. But some time ago I discovered a website where they did just that, using a Java script and the FORTRAN subroutine. I pressed the right mouse button and look for the calculations in the source of that page. There I discovered the difference.   Now we have a working verb for calculating the Julian date back to Gregorian date.

Have fun with it.

Verb CONVERT JULIAN TO DATE

The number of objects this verb uses is 2
The name of object number 1 is NOUN TO CONVERT
The prompt for object number 1 is from Julian date
The name of object number 2 is NOUN TO EDIT
The prompt for object number 2 is into noun

1 COMMENT text is Following the FORTRAN formula on the website
2 INIT JD DATE
3 COMMENT text is L = JD + 68569
4 ADD the value 68569 to the value NOUN TO CONVERT
5 COPY the value SUM to the noun L-VALUE
6 COMMENT text is ---------------------------------------------
7 COMMENT text is N = 4*L/146097
8 MULTIPLY the value L-VALUE by the value  4
9 DIVIDE the value PRODUCT by 146097
10 INP into noun QUOTIENT
11 COPY the value QUOTIENT to the noun N-VALUE
12 COMMENT text is ---------------------------------------------
13 COMMENT text is L=L-(146097*N+3)/4
14 MULTIPLY the value 146097 by the value N-VALUE
15 ADD the value PRODUCT to the value 3
16 DIVIDE the value SUM by 4
17 INP into noun QUOTIENT
18 SUBTRACT the value of QUOTIENT from the value of L-VALUE
19 COPY the value DIFFERENCE to the noun L-VALUE
20 COMMENT text is ---------------------------------------------
21 COMMENT text is I=4000*(L+1)/1461001
22 ADD the value 1 to the value L-VALUE
23 MULTIPLY the value SUM by the value 4000
24 DIVIDE the value PRODUCT by 1461001
25 INP into noun QUOTIENT
26 COPY the value QUOTIENT to the noun I-VALUE
27 COMMENT text is ---------------------------------------------
28 COMMENT text is L=L-1461*I/4+31
29 MULTIPLY the value 1461 by the value I-VALUE
30 DIVIDE the value PRODUCT by 4
31 INP into noun QUOTIENT
32 SUBTRACT the value of QUOTIENT from the value of  L-VALUE
33 ADD the value 31 to the value DIFFERENCE
34 COPY the value SUM to the noun L-VALUE
35 COMMENT text is ---------------------------------------------
36 COMMENT text is j=80*L/2447
37 MULTIPLY the value 80 by the value L-VALUE
38 DIVIDE the value PRODUCT by 2447
39 INP into noun QUOTIENT
40 COPY the value QUOTIENT to the noun J-VALUE
41 COMMENT text is ---------------------------------------------
42 COMMENT text is K=L-2447*J/80
43 MULTIPLY the value 2447 by the value J-VALUE
44 DIVIDE the value PRODUCT by 80
45 INP into noun QUOTIENT
46 SUBTRACT the value of QUOTIENT from the value of  L-VALUE
47 COPY the value DIFFERENCE to the noun K-VALUE
48 COMMENT text is ---------------------------------------------
49 COMMENT text is L=J/11
50 DIVIDE the value J-VALUE by 11
51 INP into noun QUOTIENT
52 COPY the value QUOTIENT to the noun L-VALUE
53 COMMENT text is ---------------------------------------------
54 COMMENT text is J=J+2-12*L
55 MULTIPLY the value L-VALUE by the value 12
56 ADD the value J-VALUE to the value 2
57 SUBTRACT the value of PRODUCT from the value of  SUM
58 COPY the value DIFFERENCE to the noun J-VALUE
59 COMMENT text is ----------------------------------------------
60 COMMENT text is I=100*(N-49)+I+L
61 SUBTRACT the value of 49 from the value of N-VALUE
62 MULTIPLY the value DIFFERENCE by the value 100
63 ADD the value PRODUCT to the value I-VALUE
64 ADD the value SUM to the value L-VALUE
65 COPY the value SUM to the noun I-VALUE
66 COMMENT text is ------------------------------------------------
67 INP into noun I-VALUE
68 INP into noun J-VALUE
69 INP into noun K-VALUE
70 .ALZ what K-VALUE length 2
71 .ALZ what J-VALUE length 2
72 .ALZ what I-VALUE length 4
73 JOIN the value I-VALUE to the value J-VALUE
74 JOIN the value HEAD to the value K-VALUE
75 COPY the value HEAD to the noun NOUN TO EDIT

 

Results in NOUN TO EDIT the date in CCYYMMDD-format. The K-Value contains the day, the J-Value the month and the I-Value contains the year.

I have also use a couple of small utility-verbs as I call them. For your convenience the recaps of those verbs follow:

Verb EXTRACT, to extract from a string. Very simple and I think speaks for itself.

The number of objects this verb uses is 4
The name of object number 1 is NOUN TO EXTRACT
The prompt for object number 1 is from noun
The name of object number 2 is POSITION
The prompt for object number 2 is from position
The name of object number 3 is LAYOUT
The prompt for object number 3 is layout
The name of object number 4 is SEGMENT
The prompt for object number 4 is into noun

1 SUBTRACT the value of 1 from the value of POSITION
2 CUT the value NOUN TO EXTRACT after DIFFERENCE
3 CUT the value TAIL after LAYOUT
4 COPY the value HEAD to the noun SEGMENT
5 .RTS from the noun SEGMENT

 

Verb INP, a very small verb. Almost not worth mentioning but very handy and also very important. I like small utility-verbs that I can use anywhere.

The number of objects this verb uses is 1
The name of object number 1 is NOUN TO EDIT
The prompt for object number 1 is into noun

1 SPLIT the value of NOUN TO EDIT
2 COPY the value INTEGER to the noun NOUN TO EDIT

 

Verb .ALZ, add leading zero's to a noun. Very handy to make sure references etc. have the correct length.

The number of objects this verb uses is 2
The name of object number 1 is NOUN TO EDIT
The prompt for object number 1 is what
The name of object number 2 is LAYOUT
The prompt for object number 2 is length

1 COMMENT text is ****************************************************
2 COMMENT text is Add Leading Zero's for the specified noun until
3 COMMENT text is the desired length is reached
4 COMMENT text is ****************************************************
5 COMMENT text is NOUN TO EDIT = Value that is to be edited
6 COMMENT text is LAYOUT = The desired length
7 JOIN the value "00000000000000000000000000000" to the value NOUN TO EDIT
8 CUT the value HEAD after ""
9 SUBTRACT the value of LAYOUT from the value of LENGTH
10 CUT the value HEAD after DIFFERENCE
11 COPY the value TAIL to the noun NOUN TO EDIT

 

Verb INIT JD DATE, just to make sure that al temporary nouns for the calculations do not have an old value that could disturb the working of the programs. Not really necessary but I like to do it anyway.

The number of objects this verb uses is 0

1 COPY the value 0 to the noun Z-VALUE
2 COPY the value 0 to the noun J1-VALUE
3 COPY the value 0 to the noun J2-VALUE
4 COPY the value 0 to the noun J3-VALUE
5 COPY the value 0 to the noun I-VALUE
6 COPY the value 0 to the noun J-VALUE
7 COPY the value 0 to the noun K-VALUE
8 COPY the value 0 to the noun L-VALUE
9 COPY the value 0 to the noun N-VALUE

 

Verb .RTS, is a verb that removes the trailing spaces from a noun,

The number of objects this verb uses is 1

The name of object number 1 is NOUN TO EDIT
The prompt for object number 1 is from noun

1 CUT the value NOUN TO EDIT after ""
2 SUBTRACT the value of 1 from the value of LENGTH
3 CUT the value NOUN TO EDIT after DIFFERENCE
4 IF the value TAIL "=" the value " "
   do
5 RETURN
   else
6 COPY the value HEAD to the noun NOUN TO EDIT
7 REPEAT
   end

 

To calculate what day of the week a specific date is if use the following:

Verb DETERMINE DAY OF WEEK

The number of objects this verb uses is 2
The name of object number 1 is DATE
The prompt for object number 1 is of which date
The name of object number 2 is NOUN TO EDIT
The prompt for object number 2 is into noun

1 COMMENT text is Needs to know the DATE in CCYYMMDD format
2 COMMENT text is Returns the Day of week
3 COMMENT text is -------------------------------------------
4 COMMENT text is first we calculate the factor
5 COMMENT text is This verbs calculate the factor for DATE
6 COMMENT text is Mandatory: DATE must be in format CCYYMMDD
7 COMMENT text is where CC = Century
8 COMMENT text is YY = The year
9 COMMENT text is MM = Month
10 COMMENT text is DD = Day
11 COMMENT text is i.e. 01-07-1997 is 19970701
12 COMMENT text is ************************************************
13 COMMENT text is For explanation see the Technical Bulletin
14 COMMENT text is on the http://www.logicalbusiness.com/t_altime.htm
15 COMMENT text is *************************************************
16 COMMENT text is First we initialize the nouns from DATE
17 COMMENT text is -------------------------------------------------
18 CUT the value DATE after 4
19 COPY the value HEAD to the noun YEAR
20 CUT the value TAIL after 2
21 COPY the value HEAD to the noun MONTH
22 COPY the value TAIL to the noun DAY
23 COMMENT text is *************************************************
24 COMMENT text is Since the calculation of January and February
25 COMMENT text is is different from the other months, we go
26 COMMENT text is two ways here:
27 COMMENT text is -------------------------------------------------
28 IF the value MONTH "<>" the value "01"
    do
29 IF the value MONTH "<>" the value "02"
    do
30 COMMENT text is ********************************************
31 COMMENT text is It is NOT January or February.
32 CALC FACTOR 03-12 noun to edit FACTOR
    else
33 COMMENT text is ********************************************
34 COMMENT text is It is January or February
35 CALC FACTOR 01-02 noun to edit FACTOR
    end
    else
    end
36 SUBTRACT the value of FACTOR from the value of 0
37 DIVIDE the value DIFFERENCE by 7
38 INP into noun QUOTIENT
39 MULTIPLY the value QUOTIENT by the value 7
40 ADD the value PRODUCT to the value FACTOR
41 COPY the value SUM to the noun DAY OF WEEK
42 IF the value DAY OF WEEK "=" the value 0
    do
43 COPY the value "Saturday" to the noun NOUN TO EDIT
    else
    end
44 IF the value DAY OF WEEK "=" the value 1
    do
45 COPY the value "Sunday" to the noun NOUN TO EDIT
    else
    end
46 IF the value DAY OF WEEK "=" the value 2
    do
47 COPY the value "Monday" to the noun NOUN TO EDIT
    else
    end
48 IF the value DAY OF WEEK "=" the value 3
    do
49 COPY the value "Tuesday" to the noun NOUN TO EDIT
    else
    end
50 IF the value DAY OF WEEK "=" the value 4
    do
51 COPY the value "Wednesday" to the noun NOUN TO EDIT
    else
    end
52 IF the value DAY OF WEEK "=" the value 5
    do
53 COPY the value "Thursday" to the noun NOUN TO EDIT
    else
    end
54 IF the value DAY OF WEEK "=" the value 6
    do
55 COPY the value "Friday" to the noun NOUN TO EDIT
    else
    end

 

Verb CALC FACTOR 03-12

The number of objects this verb uses is 1
The name of object number 1 is NOUN TO EDIT
The prompt for object number 1 is noun to edit

1 COMMENT text is calculating the factor for months march
2 COMMENT text is through December
3 COMMENT text is ******************************************
4 COMMENT text is First we calculate part 1 of the calculation
5 COMMENT text is --------------------------------------------
6 MULTIPLY the value YEAR by the value 365
7 ADD the value PRODUCT to the value DAY
8 SUBTRACT the value of 1 from the value of MONTH
9 MULTIPLY the value DIFFERENCE by the value 31
10 ADD the value SUM to the value PRODUCT
11 COPY the value SUM to the noun PART1
12 COMMENT text is *********************************************
13 COMMENT text is Lets see about part two
14 COMMENT text is ---------------------------------------------
15 MULTIPLY the value MONTH by the value 0,4
16 ADD the value 2,3 to the value PRODUCT
17 SPLIT the value of SUM
18 COPY the value INTEGER to the noun PART2
19 COMMENT text is *********************************************
20 COMMENT text is So far the easy parts. Now lets complicate
21 COMMENT text is things. Let us calculate part three
22 COMMENT text is ---------------------------------------------
23 DIVIDE the value YEAR by 100
24 ADD the value 1 to the value QUOTIENT
25 SPLIT the value of SUM
26 MULTIPLY the value INTEGER by the value 0,75
27 SPLIT the value of PRODUCT
28 COPY the value INTEGER to the noun TEMP VAL
29 DIVIDE the value YEAR by 4
30 SPLIT the value of QUOTIENT
31 SUBTRACT the value of TEMP VAL from the value of  INTEGER
32 COPY the value DIFFERENCE to the noun PART3
33 COMMENT text is ********************************************
34 COMMENT text is Join the parts:
35 COMMENT text is --------------------------------------------
36 SUBTRACT the value of PART2 from the value of  PART1
37 ADD the value DIFFERENCE to the value PART3
38 COPY the value SUM to the noun NOUN TO EDIT


Verb CALC FACTOR 01-02

The number of objects this verb uses is 1
The name of object number 1 is NOUN TO EDIT
The prompt for object number 1 is noun to edit

1 COMMENT text is calculating the factor for January and February
2 COMMENT text is First we calculate part 1 of the calculation
3 COMMENT text is --------------------------------------------
4 MULTIPLY the value YEAR by the value 365
5 ADD the value PRODUCT to the value DAY
6 SUBTRACT the value of 1 from the value of MONTH
7 MULTIPLY the value DIFFERENCE by the value 31
8 ADD the value SUM to the value PRODUCT
9 COPY the value SUM to the noun PART1
10 COMMENT text is *********************************************
11 COMMENT text is Lets see about part two
12 COMMENT text is ---------------------------------------------
13 SUBTRACT the value of 1 from the value of  YEAR
14 DIVIDE the value DIFFERENCE by 4
15 SPLIT the value of QUOTIENT
16 COPY the value INTEGER to the noun PART2
17 COMMENT text is *********************************************
18 COMMENT text is So far the easy parts. Now lets complicate
19 COMMENT text is things. Let us calculate part three
20 COMMENT text is ---------------------------------------------
21 SUBTRACT the value of 1 from the value of YEAR
22 DIVIDE the value DIFFERENCE by 100
23 ADD the value 1 to the value QUOTIENT
24 SPLIT the value of SUM
25 MULTIPLY the value INTEGER by the value 0,75
26 SPLIT the value of PRODUCT
27 COPY the value INTEGER to the noun PART3
28 COMMENT text is ********************************************
29 COMMENT text is Join the parts
30 COMMENT text is --------------------------------------------
31 ADD the value PART1 to the value PART2
32 SUBTRACT the value of PART3 from the value of SUM
33 COPY the value DIFFERENCE to the noun NOUN TO EDIT

Another date calculation that people like to have is the following. If we tell someone we will meet him three weeks from now we can do two things. Look at a calendar to find out what date that will be or let the computer find out. The computer does it with the following verb. It is an old verb, but it is 2000 compatible.

Verb CALCULATE DATE + ?

The number of objects this verb uses is 3
The name of object number 1 is DATE TO START
The prompt for object number 1 is from date
The name of object number 2 is NUMBER OF DAYS
The prompt for object number 2 is how many days
The name of object number 3 is NOUN TO EDIT
The prompt for object number 3 is into noun

1 COMMENT text is What date is it in x-day's from now.
2 COMMENT text is --------------------------------------
3 COMMENT text is Old program to calculate that. Does not use
4 COMMENT text is the Julian date yet.
5 COMMENT text is -------------------------------------
6 COMMENT text is last edited by RS: 09-02-1996
7 COMMENT text is *********************************************
8 COMMENT text is DATE TO START must be in the CCYYMMDD format
9 COMMENT text is result will also be in that format
10 COMMENT text is ---------------------------------------------
11 COMMENT text is LEAP = 1 is leap year, 0 is not a leap year
12 COMMENT text is the following is used by this verb to determine
13 COMMENT text is how many days a month has. Normally you would
14 COMMENT text is place this in your AUTOEXEC or INIT NOUNS or
15 COMMENT text is what ever you use for never changing nounvalues
16 COPY the value "~0131~0228~0331~0430~0531~0630~0731~0831~0930~1031~1130~1231" to the noun DAYS IN A MONTH
17 COMMENT text is ----------------------------------------------
18 CUT the value DATE TO START after 4
19 COPY the value HEAD to the noun YEAR
20 CUT the value TAIL after 2
21 COPY the value HEAD to the noun MONTH
22 COPY the value TAIL to the noun DAY
23 CHECK LEAP YEAR year YEAR
24 ADD the value NUMBER OF DAYS to the value DAY
25 COPY the value SUM to the noun DAY
26 LABEL this line with RESUME
27 JOIN the value "~" to the value MONTH
28 CUT the value DAYS IN A MONTH after HEAD
29 CUT the value TAIL after 2
30 IF the value MONTH "=" the value "02"
    do
31 ADD the value LEAP to the value HEAD
    else
32 COPY the value HEAD to the noun SUM
    end
33 SUBTRACT the value of SUM from the value of DAY
34 IF the value DIFFERENCE "<" the value 1
    do
35 GO TO line labeled END
    else
36 COPY the value DIFFERENCE to the noun DAY
37 ADD the value 1 to the value MONTH
38 .ALZ what SUM length 2
39 COPY the value SUM to the noun MONTH
40 IF the value MONTH "<" the value 13
    do
41 GO TO line labeled RESUME
    else
42 SUBTRACT the value of 12 from the value of MONTH
43 COPY the value DIFFERENCE to the noun MONTH
44 .ALZ what MONTH length 2
45 ADD the value 1 to the value YEAR
46 COPY the value SUM to the noun YEAR
47 .ALZ what YEAR length 4
48 CHECK LEAP YEAR year YEAR
49 GO TO line labeled RESUME
    end
    end
50 LABEL this line with END
51 .ALZ what DAY length 2
52 JOIN the value YEAR to the value MONTH
53 JOIN the value HEAD to the value DAY
54 COPY the value HEAD to the noun NOUN TO EDIT

 

R E C A P the definition of CHECK LEAP YEAR

The number of objects this verb uses is 1
The name of object number 1 is NOUN TO CHECK
The prompt for object number 1 is year

1 COMMENT text is LEAP = 1 is leap year, 0 is not a leap year
2 DIVIDE the value NOUN TO CHECK by 4
3 SPLIT the value of QUOTIENT
4 IF the value FRACTION "=" the value 0
    do
5 DIVIDE the value NOUN TO CHECK by 100
6 SPLIT the value of QUOTIENT
7 IF the value FRACTION "=" the value 0
    do
8 DIVIDE the value NOUN TO CHECK by 400
9 SPLIT the value of QUOTIENT
10 IF the value FRACTION "=" the value 0
    do
11 COPY the value 1 to the noun LEAP
    else
12 COPY the value 0 to the noun LEAP
    end
    else
13 COPY the value 1 to the noun LEAP
    end
    else
14 COPY the value 0 to the noun LEAP
    end

There is also a very easy way to let the computer calculate the above:

Create a verb that first calculate the Julian Date, then add the amount days to the Julian date and let the verb calculate the new Gregorian date from the sum.

I have added the verbs above for it because old applications in Pragma 3 or NL uses something like that and it can easily be made in Pragma 3 or NL. Yes, it needs some conversion but it is possible. There are still a lot of Pragma 3 users.

 

Vocab with Julian Date Conversions

Ronald Scheepstra,
December 9, 1999

I hereby send you a vocab (called julian.pfm). You or your customers can import this into their vocabulary and use it.  It contains verbs to calculate a Julian date from a Gregorian date and back.  Available for everyone and import it in your own vocabulary free of charge.

I am a strong believer in sharing information and knowledge within  the Pragma world because I am convinced that it helps us all to make better and stronger programs. Therefore I think it is a good idea to make this vocabulary available for download on your websites.


There are several verbs in the vacabulary:

DETERMINE DAY OF WEEK = to find out what day we have it uses
CALC FACTOR 01+02 to calculate the factor for jan and feb
CALC FACTOR 03/12 to calculate the factor for other months

CONVERT DATE TO JULIAN to convert a Gregorian date to a Julian date
CONVERT JULIAN TO DATE to convert a Julian date to a Gregorian date

And some other small programs used by the above mentioned. They are all explained inside the verbs.

It also contains a verb called CHECK DATE. This verb checks the date to be millennium proof and if not tries to make it so. Examine it and you will know how it works. It gives back to dates, one it places in the object noun (NOUN TO EDIT). It also fill a noun called DATE SCREEN. This is the date notation for display on screen (easy readable for the user). However, because I am Dutch I use the Dutch notation and there is a difference with the English notation.

Let me explain:
In Dutch we say that today it is eight December 1999, so we use the notation 08-12-1999. In English you would say that today it is the December the eight 1999 so one uses the notation 12-08-1999.

So my check date uses reproduces to dates when used like this:

CHECK DATE date TODAY
it produces TODAY = 19991208 (for use on file)
and produces DATE SCREEN = 08-12-1999

For those who use the English notation they should alter the verb so that it produces the DATE SCREEN like 12-08-1999.

To download the vocabulary go to the Logical web site, Various downloads.

 

 

2001-05-16
logo.gif, lip_tec3.gif, stop.gif
t_altime.htm