home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / database / edit_22 / dates.doc < prev    next >
Encoding:
Text File  |  1988-06-11  |  7.3 KB  |  166 lines

  1.                              Date Manipulation
  2.                                  DATES.TPU
  3.  
  4. Date manipulation is one the most important aspects of business programming
  5. and can have direct impact on sales and billing by indicating early payment
  6. discounts and late payment charges - among many other things that can be
  7. done with dates.
  8.  
  9.                                * * * * * * *
  10.  
  11. A word about the Julian calendar:
  12.  
  13. Calculating with dates can be a real nuisance, but your efforts can be
  14. considerably simplified by using the Julian notation rather than the more
  15. familiar calendar date.  Julian date notation was "invented" in 1582 and
  16. was intended to provide a "universal" calculation of large time intervals. 
  17. The formal Julian system starts with January 1, 4713 BC (considered by
  18. some religions as the date the earth was created) as day 1 and continues
  19. through 3267 AD (officially).  Thus, January 1, 1988 would be day 2447162 in
  20. the formal Julian notation.
  21.  
  22. The historical study of calendar systems can be quite interesting.  While
  23. there are a number of calendar systems currently in use throughout the
  24. world (Hebrew and Chinese calendars come quickly to mind), there are many
  25. more no longer in use despite their historical significance.
  26.  
  27.                                * * * * * * *
  28.  
  29. DATES.TPU contains a number of useful functions and procedures such as:
  30.  
  31.   DateToInt    - parses an MM/DD/YY date string to provide an integer value.
  32.   IntToDate    - converts integer M,D,Y date to a date string.
  33.   ToJulian     - Converts the integer date to the Julian date.
  34.   FromJulian   - Converts Julian date to integer date.
  35.   DayOfTheWeek - Computes day of week using Zeller's Congruance algorithm.
  36.   CurrentDate  - The date in the computer's operating system date buffer.
  37.  
  38.                                * * * * * * *
  39.  
  40. The DateToInt() procedure is described as:
  41.  
  42.   Procedure DateToInt(Date : DateStr;
  43.                       Var Month,Day,Year : Integer);
  44.  
  45. Entering (or passing) the date string returns the integer variables "Month",
  46. "Day" and "Year" - in that order.  The date string is parsed into three
  47. sections, divided by a non-numeric character such as "-" or "/" so that the
  48. string "01/01/88" returns the integer values 1 for Month, 1 for Day and 87
  49. for Year.  Similarly, the string "01-01-1987" will return the integer
  50. values 1 for Month, 1 for Day and 1987 for year.  Note that certain European
  51. and military date notations such as "01.01.87" or "01,01,87" will also be
  52. parsed correctly.
  53.  
  54.                                * * * * * * *
  55.  
  56. The IntToDate function is described as:
  57.  
  58.   IntToDate(M,D,Y : Integer): DateStr;
  59.  
  60. Passing three integer values returns the string "MM/DD/YY".  If M = "7',
  61. D = "1" and Y = "88", the returned string will be "07/01/88".  Note that
  62. leading zeroes are added to the string where applicable.
  63.  
  64.                                * * * * * * *
  65.  
  66. The ToJulian function is described as:
  67.  
  68.   ToJulian(M,D,Y : Integer): Real;
  69.  
  70. Passing three integer values - month, day and year - returns the number of
  71. days since January 1, 0001 AD (a modified form of Julian date).  While this
  72. may appear to be merely an interesting piece of history, the Julian dates
  73. may be subtracted from one another to provide the number of days between
  74. dates - a very practical method of determining various business date require-
  75. ments.  Of course, a little effort is required to ensure that the earlier
  76. date is subtracted from the later.  To get the formal Julian date, simply
  77. add 1,721,064 to the modified Julian date provided by the program.  Note
  78. also the Julian date is returned as a Real.
  79.  
  80.                                * * * * * * *
  81.  
  82. The FromJulian procedure is described as:
  83.  
  84.   FromJulian(X : Real;
  85.              Var Month, Day, Year : Integer);
  86.  
  87. This converts the Julian date back to month, day and year.  The Julian date
  88. must be defined as a Real.
  89.  
  90.                                * * * * * * *
  91.  
  92. The DayOfTheWeek function is described as:
  93.  
  94.   DayOfTheWeek(Month,Day,Year : Integer): Integer;
  95.  
  96. Using Zeller's Congruance algorithm, the day of the week is determined.  It
  97. is necessary, however, to ensure the variable "Year" is the full year.
  98. If the year is 1987, it must be entered as "1987", not "87".  The day is
  99. returned as an integer: 0 for Sunday, 1 for Monday, and so on.
  100.  
  101.                                * * * * * * *
  102.  
  103. The CurrentDate procedure is described as:
  104.  
  105.   CurrentDate(Var DateString);
  106.  
  107. This procedure uses the Turbo Pascal 4.0 GetDate procedure but, instead,
  108. returns the current date set in the operating system as a string in the
  109. MM/DD/YY format rather than the integer format provided by the Turbo
  110. Pascal 4.0 "GetDate" procedure.
  111.  
  112.                                * * * * * * *
  113.  
  114. In addition, there are 3 publicly declared constants:
  115.   DayArray   - The number of days in each month (non-leap-year),
  116.   WeekArray  - The names of the days of the week, 0=Sunday, 1=Monday, etc.,
  117.   MonthArray - The names of the months, 1=January, 2=February, etc.
  118.  
  119. DateStr is also publicly declared as "String[10]".
  120.  
  121. Note also that the entered dates are self-correcting; that is, if you enter
  122. "2-29-87" the Julian date will return "3-1-87", or if you enter "4-31-88"
  123. the Julian date will return "5-1-88".  Note that leap-year dates (2-29-88)
  124. are also returned correctly.
  125.  
  126.                                * * * * * * *
  127.  
  128. Handling dates, in and of themselves, has never been a difficult task -
  129. until you are required to calculate the number of days between two dates. 
  130. Fortunately, the problem was resolved for us in 1582 with the Julian calendar,
  131. although for different purposes and reasons.  Had this solution not already
  132. existed, there is no doubt most programmers would have recognized and handled
  133. the problem in much the same way.
  134.  
  135. Oddly, the method of determining days between dates has an amazing number
  136. of solutions - all of which work quite well.  Although the algorithms presented
  137. here are the most commonly used, they could be wildly inappropriate in geologic
  138. or pre-history programming applications.  However, this algorithm is quite
  139. appropriate for normal business use (few businesses have kept their doors
  140. open since before 1 AD or, if they have, require little access to those
  141. business records).
  142.  
  143. Pay particular attention to the fact that DATES.TPU assumes all years
  144. entered as "99" or less fall in the 20th century and treats them accordingly.
  145. Thus, if you enter "1-1-88", the assumption is that you intended to enter
  146. "1-1-1988".  This is merely to simplify date entry.  As we approach the year
  147. 2000, you may want to change the TPU accordingly.
  148.  
  149.                                * * * * * * *
  150.  
  151. A number of sources were used in the creation of this TPU, including several
  152. in the public domain.  However, none of these sources were directly copied
  153. and this TPU was independently designed.  Because of the large number of
  154. date handling procedures written in Turbo Pascal, there is a possibility
  155. this code inadvertantly duplicates pre-exisiting code.
  156.  
  157. If you have any questions or comments after having reviewed and used
  158. DATEDEMO.PAS, please address them to:
  159.  
  160.                              COMPUsystems N.W.
  161.                              Attn: John Winney
  162.                         9792 Edmonds Way, Suite 226
  163.                              Edmonds, WA 98020
  164.                               (206) 774-1460
  165.                     C/O George Wishart  Compuserve [70165,460]
  166.