home *** CD-ROM | disk | FTP | other *** search
-
- {This program appeared in the book entitled TURBO PASCAL LIBRARY by Douglas
- Stivison. It computes the day of the week a certain date appeared on.
- It also gives the Julian value for the date. }
-
-
- const
- dayarray : array [0..6] of string [9] =
- ('Sunday',
- 'Monday',
- 'Tuesday',
- 'Wednesday',
- 'Thursday',
- 'Friday',
- 'Saturday');
-
- montharray : array [1..12] of string [9] =
- ('January',
- 'February',
- 'March',
- 'April',
- 'May',
- 'June',
- 'July',
- 'August',
- 'September',
- 'October',
- 'November',
- 'December');
-
- monthdays : array [1..12] of integer =
- (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
-
- type
- datestr = string [8];
-
-
- procedure datetoint (date: datestr;
- var month,
- day,
- year: integer);
- var
- position: integer;
-
-
- function parsedate (var i: integer;
- dat: datestr): integer;
- var
- num: integer;
-
- begin
-
- while not (dat [i] in ['0'..'9']) and (i <= length (date)) do
- i := i + 1;
-
- num := 0;
-
- while (dat [i] in ['0'..'9']) and (i <= length (date)) do
- begin
- num :=(ord (dat [i])- ord ('0'))+(num * 10);
- i := i + 1;
- end;
-
- parsedate := num;
- end;
-
- begin
- position := 1;
- month := parsedate (position, date);
- day := parsedate (position, date);
- year := parsedate (position, date)+ 1900;
- end;
-
-
- function caljul (m,
- d,
- y: integer): real;
- var
- x: real;
-
- begin
- x := int (30.57 * m)+ int (365.25 * y - 395.25)+ d;
-
- if m > 2 then
- if int (y / 4)= y / 4 then
- x := x - 1
- else
- x := x - 2;
-
- caljul := x;
- end;
-
-
- procedure julcal (x: real;
- var month,
- day,
- year: integer);
- var
- m,
- d,
- y: real;
- d1: integer;
-
- begin
- y := int (x / 365.26)+ 1;
- d := x + int (395.25 - 365.25 * y);
-
- if int (y / 4)* 4 = y then
- d1 := 1
- else
- d1 := 2;
-
- if d >(91 - d1) then
- d := d + d1;
-
- m := int (d / 30.57);
- d := d - int (30.57 * m);
-
- if m > 12 then
- begin
- m := 1;
- y := y + 1;
- end;
-
- month := trunc (m);
- day := trunc (d);
- year := trunc (y);
- end;
-
-
- function inttodate (m,
- d,
- y: integer): datestr;
- var
- i: integer;
- month,
- day,
- year: string [2];
- date: datestr;
-
- begin
-
- if y >= 1900 then
- y := y - 1900;
-
- str(m : 2, month);
- str(d : 2, day);
- str(y : 2, year);
- date := month + '/' + day + '/' + year;
-
- for i := 1 to length (date) do
- if date [i]= ' ' then
- date[i]:= '0';
-
- inttodate := date;
- end;
-
- function dayofweek (month,
- day,
- year: integer): integer;
- var
- century: integer;
-
- begin
-
- if month > 2 then
- month := month - 2
- else
- begin
- month := month + 10;
- year := pred (year);
- end;
-
- century := year div 100;
- year := year mod 100;
- dayofweek := (day - 1 +((13 * month - 1) div 5) +
- (5 * year div 4) +
- (century div 4) -
- (2 * century) + 1) mod 7;
- end;