home *** CD-ROM | disk | FTP | other *** search
- DATES -- A unit providing Julian day numbers and date manipulations.
-
- Version 1.00 - 10/26/1987 - First general release
-
- Scott Bussinger
- Professional Practice Systems
- 110 South 131st Street
- Tacoma, WA 98444
- (206)531-8944
- Compuserve 72247,2671
-
- This UNIT for Turbo Pascal 4.0 provides a new data type Date, which is a
- Julian day number indicating the number of days that have elapsed since
- January 1, 1900. A Date allows you to store any date from January 1, 1900 to
- December 31, 2078 in only two bytes. Also defined is an enumerated type
- defining the days of the week. The available routines support conversion
- to/from a day, month and year format to the Date format, checking for valid
- dates, adding a number of days, months and years to a Date, conversion to/from
- a Date and a string form that can be used for sorting and a routine for
- determining the day of the week for a given date. To include this unit in
- your program, add DATES to the USES clause in your main program.
- The advantages of using Julian Date numbers are the savings of much storage
- space (2 bytes vs. 6 ASCII characters) and that the number of days between any
- two dates is a simple subtraction. The algorithms used here are adapted from
- an article by Gordon King in the June 1983 issue of Dr. Dobb's Journal. Mr.
- King in turn credits Algorithm 199 in "The Collected Algorithms of the ACM"
- (1963) by R. G. Tantzen.
-
-
- type Date = Word;
- A date is stored as a word variable and represents the number of days
- elapsed since January 1, 1900.
-
- type Day = (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday);
- A Day variable can take the value of any of these special constants
- representing the days of the week.
-
- function ValidDate(Day,Month,Year: integer): boolean;
- This functions checks that the given date is both a valid date and that it
- is within the range of dates that can be stored in a Date variable. Note
- that no error checking takes place in any of the other routines -- it is
- assumed that input error checking will call this routine and all
- parameters to the other routines will thus have alreay been checked. Days
- range from 1..31 depending on the month and year, months range from 1..12,
- and years range from 1900..2078.
-
- procedure DMYtoDate(Day,Month,Year: integer;var Julian: Date);
- Calculate the Julian day number for the given date and return as a Date.
- Again note that no error checking is taking place in this routine -- if
- the date given doesn't make sense then neither will the result, use
- ValidDate to check for valid dates first if necessary.
-
- procedure DateToDMY(Julian: Date;var Day,Month,Year: integer);
- The reciprocal routine for DMYtoDate, this procedure takes a Julian day
- number and returns the day, month and year.
-
- function BumpDate(Julian: Date;Days,Months,Years: integer): Date;
- This routine adds (or subtracts) a given number of days, months and years
- from the Date. Months and years are added first before days are added.
- Note that no overflow or underflow checking is performed on the
- calculation, be sure that the resulting date will be in the valid range
- for a Date variable.
-
- function DayOfWeek(Julian: Date): Day;
- This routine returns the day of the week for the given date. This
- information can be used directly, or supplied to the DayString routine
- below to obtain a string representation of the day of the week.
-
- function DayString(WeekDay: Day): string;
- This routine takes a Day value and converts it into a string with the name
- of the day for use in output. The first letter of each is capitalized.
-
- function MonthString(Month: integer): string;
- This routine takes an integer from 1..12 and converts it into a string
- with the name of the month for use in output. The first letter of each is
- capitalized.
-
- function DateToStr(Julian: Date): string;
- Returns a two character string representing the Date suitable for use
- in standard string sorts or comparisons. For example, the result could
- be concatenated to a key for use with the Database Toolbox.
-
- function StrToDate(StrVar: string): Date;
- The reciprocal function to DateToStr, this converts a sortable string back
- into a Date value.
-
- const BlankDate = $FFFF;
- This special constant is not in the valid range for a Date variable and
- can be used to represent an non-entry, blank entry, or not-a-real-date in
- input and output routines. Do not supply this value to any routines
- expecting a Date value. If you decide to use this constant, it is
- expected that you will check for this special value before calling any of
- the above routines.