home *** CD-ROM | disk | FTP | other *** search
- { File: FastDate.PAS
- Author: David N. Dubois
- Date: 1988.04.16
-
- Unit FastDate demonstrates the !FAST! day counting function. }
-
- unit FastDate;
-
- interface
-
- uses
- dos; { for current date function }
-
- type
- DateType = record
- Year : integer;
- Month : 1 .. 12;
- Day : 1 .. 31;
- end;
-
- function CountDays ( Date : DateType ) : longint;
-
- function DaysBetweenDates ( Date1 : DateType;
- Date2 : DateType ) : longint;
-
- procedure DateIs ( var Date : DateType;
- NewYear : integer;
- NewMonth : byte;
- NewDay : byte );
-
- procedure Today ( var Date : DateType );
-
- function DayOfWeek ( Date : DateType ) : byte; { 0 = Sunday }
-
- function DateToString ( Date : DateType ) : string;
-
- const
- January = 1;
- February = 2;
- March = 3;
- April = 4;
- May = 5;
- June = 6;
- July = 7;
- August = 8;
- September = 9;
- October = 10;
- November = 11;
- December = 12;
-
- implementation
-
- function CountDays ( Date : DateType ) : longint;
- external;
- {$L FastDate.OBJ }
-
- function DaysBetweenDates ( Date1 : DateType;
- Date2 : DateType ) : longint;
- begin
- DaysBetweenDates := CountDays ( Date2 ) - CountDays ( Date1 );
- end;
-
- procedure DateIs ( var Date : DateType;
- NewYear : integer;
- NewMonth : byte;
- NewDay : byte );
- begin
- with Date do
- begin
- Year := NewYear;
- Month := NewMonth;
- Day := NewDay;
- end;
- end;
-
- procedure Today ( var Date : DateType );
- var
- Year : word;
- Month : word;
- Day : word;
- DOW : word;
- begin
- getdate ( Year, Month, Day, DOW );
- DateIs ( Date, Year, Month, Day );
- end;
-
- function DayOfWeek ( Date : DateType ) : byte;
- begin
- DayOfWeek := ( CountDays ( Date ) + 716573 ) mod 7;
- end;
-
- function DateToString ( Date : DateType ) : string;
- const
- MonthName : array [ 1 .. 12 ] of string [ 9 ]
- = ( 'January', 'February', 'March', 'April',
- 'May', 'June', 'July', 'August',
- 'September', 'October', 'November', 'December' );
- DOWName : array [ 0 .. 6 ] of string [ 9 ]
- = ( 'Sunday', 'Monday', 'Tuesday', 'Wednesday',
- 'Thursday', 'Friday', 'Saturday' );
- var
- DayString : string;
- YearString : string;
- begin
- with Date do
- begin
- str ( Day, DayString );
- str ( Year, YearString );
- DateToString := DOWName [ DayOfWeek ( Date ) ]
- + ', ' + MonthName [ Month ]
- + ' ' + DayString
- + ', ' + YearString;
- end;
- end;
-
- end.