home *** CD-ROM | disk | FTP | other *** search
- Unit Dates;
-
- Interface
-
- Uses
- Crt,Dos;
-
- Const
- DayArray : Array[1..12] of Integer = (31,28,31,30,31,30,31,31,30,31,30,31);
- WeekArray : 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');
-
- Type
- DateStr = String[10];
-
- Procedure DateToInt(Date : DateStr; Var Month,Day,Year : Integer);
- Function IntToDate(M,D,Y : Integer): DateStr;
- Function ToJulian(M,D,Y : Integer): Real;
- Procedure FromJulian(X : Real; Var M,D,Y : Integer);
- Function DayOfTheWeek(Month,Day,Year : Integer): Integer;
- Function CurrentDate : DateStr;
-
- Implementation
-
- Procedure DateToInt(Date : DateStr; Var Month,Day,Year : Integer);
- Var
- Position : Integer;
-
- Function Parsedate(Var I : Integer; Dat : DateStr): Integer;
- Var
- Num : Word;
- 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);
- If Year < 100 then Year := Year + 1900;
- End;
-
- Function IntToDate(M,D,Y : Integer): DateStr;
- Var
- Mo,Da,Yr : String[2];
- Date : DateStr;
- Begin
- If Y < 100 then Y := Y + 1900;
- Str(M,Mo);
- Str(D,Da);
- Str(Y,Yr);
- IntToDate := Mo + '/' + Da + '/' + Yr;
- End;
-
- Function ToJulian(M,D,Y : Integer): Real;
- Var
- X : Real;
- I : Word;
- Begin
- X := Int((Y * 365.25) - Int(Y/100)) - 1;
- For I := 1 to M-1 do X := X + DayArray[I];
- X := X + D;
- If (Int(Y/4) = Y/4) and (M > 2) then X := X + 1;
- ToJulian := X;
- End;
-
- Procedure FromJulian(X : Real; Var M,D,Y : Integer);
- Var
- I,J,K : Integer;
- Begin
- Y := Round(X / 365.25);
- J := Round((X - (Y * 365.25)) + Int(Y/100));
- If Int(Y/4) = Y/4 then J := J + 1 else J := J + 2;
- K := 1;
- If (Int(Y/4) = Y/4) then DayArray[2] := 29;
- While J > DayArray[K] do
- Begin
- J := J - DayArray[K];
- K := K + 1;
- End;
- If K > 12 then begin K := 1; Y := Y + 1; End;
- M := K;
- D := J;
- End;
-
- Function DayOfTheWeek(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;
- DayOfTheWeek := (Day - 1 + ((13 * Month - 1) Div 5) + (5 * Year Div 4) +
- Century Div 4 - 2 * Century + 1) Mod 7;
- End;
-
- Function CurrentDate : DateStr;
- Var
- I,Year,Month,Day,DayOfWeek : Word;
- CDate : String[8];
- M,D,Y : String[2];
- Begin
- Getdate(Year,Month,Day,DayOfWeek);
- Str(Month:2,M);
- Str(Day:2,D);
- Str((Year - 1900):2,Y);
- CDate := M + '/' + D + '/' + Y;
- For I := 1 to Length(CDate) do if CDate[I] = ' ' then CDate[I] := '0';
- CurrentDate := CDate;
- End;
-
- End.