home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / DATES.ZIP / DATES.DOC next >
Encoding:
Text File  |  1988-09-24  |  5.1 KB  |  103 lines

  1.   DATES  --  A unit providing Julian day numbers and date manipulations.
  2.  
  3.   Version 1.00 - 10/26/1987 - First general release
  4.  
  5.   Scott Bussinger
  6.   Professional Practice Systems
  7.   110 South 131st Street
  8.   Tacoma, WA  98444
  9.   (206)531-8944
  10.   Compuserve 72247,2671
  11.  
  12.   This UNIT for Turbo Pascal 4.0 provides a new data type Date, which is a
  13. Julian day number indicating the number of days that have elapsed since
  14. January 1, 1900.  A Date allows you to store any date from January 1, 1900 to
  15. December 31, 2078 in only two bytes.  Also defined is an enumerated type
  16. defining the days of the week.  The available routines support conversion
  17. to/from a day, month and year format to the Date format, checking for valid
  18. dates, adding a number of days, months and years to a Date, conversion to/from
  19. a Date and a string form that can be used for sorting and a routine for
  20. determining the day of the week for a given date.  To include this unit in
  21. your program, add DATES to the USES clause in your main program.
  22.   The advantages of using Julian Date numbers are the savings of much storage
  23. space (2 bytes vs. 6 ASCII characters) and that the number of days between any
  24. two dates is a simple subtraction.  The algorithms used here are adapted from
  25. an article by Gordon King in the June 1983 issue of Dr. Dobb's Journal.  Mr.
  26. King in turn credits Algorithm 199 in "The Collected Algorithms of the ACM"
  27. (1963) by R. G. Tantzen.
  28.  
  29.  
  30. type Date = Word;
  31.     A date is stored as a word variable and represents the number of days
  32.     elapsed since January 1, 1900.
  33.  
  34. type Day = (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday);
  35.     A Day variable can take the value of any of these special constants
  36.     representing the days of the week.
  37.  
  38. function ValidDate(Day,Month,Year: word): boolean;
  39.     This functions checks that the given date is both a valid date and that it
  40.     is within the range of dates that can be stored in a Date variable.  Note
  41.     that no error checking takes place in any of the other routines -- it is
  42.     assumed that input error checking will call this routine and all
  43.     parameters to the other routines will thus have alreay been checked.  Days
  44.     range from 1..31 depending on the month and year, months range from 1..12,
  45.     and years range from 1900..2078.
  46.  
  47. procedure DMYtoDate(Day,Month,Year: word;var Julian: Date);
  48.     Calculate the Julian day number for the given date and return as a Date.
  49.     Again note that no error checking is taking place in this routine -- if
  50.     the date given doesn't make sense then neither will the result, use
  51.     ValidDate to check for valid dates first if necessary.
  52.  
  53. procedure DateToDMY(Julian: Date;var Day,Month,Year: word);
  54.     The reciprocal routine for DMYtoDate, this procedure takes a Julian day
  55.     number and returns the day, month and year.
  56.  
  57. function BumpDate(Julian: Date;Days,Months,Years: integer): Date;
  58.     This routine adds (or subtracts) a given number of days, months and years
  59.     from the Date.  Months and years are added first before days are added.
  60.     Note that no overflow or underflow checking is performed on the
  61.     calculation, be sure that the resulting date will be in the valid range
  62.     for a Date variable.
  63.  
  64. function CurrentAge(Birthdate: Date): word;
  65.     This function returns the current age of a person in years from a given
  66.     date of birth.  This uses the system date for today's date.
  67.  
  68. function DayOfWeek(Julian: Date): Day;
  69.     This routine returns the day of the week for the given date.  This
  70.     information can be used directly, or supplied to the DayString routine
  71.     below to obtain a string representation of the day of the week.
  72.  
  73. function Today: Date;
  74.     This function returns the current system date as a Date value.  This is
  75.     only accurate if you have set the system time or have a battery operated
  76.     clock hardware.
  77.  
  78. function DayString(WeekDay: Day): string;
  79.     This routine takes a Day value and converts it into a string with the name
  80.     of the day for use in output.  The first letter of each is capitalized.
  81.  
  82. function MonthString(Month: word): string;
  83.     This routine takes an integer from 1..12 and converts it into a string
  84.     with the name of the month for use in output.  The first letter of each is
  85.     capitalized.
  86.  
  87. function DateToStr(Julian: Date): string;
  88.     Returns a two character string representing the Date suitable for use
  89.     in standard string sorts or comparisons.  For example, the result could
  90.     be concatenated to a key for use with the Database Toolbox.
  91.  
  92. function StrToDate(StrVar: string): Date;
  93.     The reciprocal function to DateToStr, this converts a sortable string back
  94.     into a Date value.
  95.  
  96. const BlankDate = $FFFF;
  97.     This special constant is not in the valid range for a Date variable and
  98.     can be used to represent an non-entry, blank entry, or not-a-real-date in
  99.     input and output routines.  Do not supply this value to any routines
  100.     expecting a Date value.  If you decide to use this constant, it is
  101.     expected that you will check for this special value before calling any of
  102.     the above routines.
  103.