home *** CD-ROM | disk | FTP | other *** search
- Date Manipulation
- DATES.TPU
-
- Date manipulation is one the most important aspects of business programming
- and can have direct impact on sales and billing by indicating early payment
- discounts and late payment charges - among many other things that can be
- done with dates.
-
- * * * * * * *
-
- A word about the Julian calendar:
-
- Calculating with dates can be a real nuisance, but your efforts can be
- considerably simplified by using the Julian notation rather than the more
- familiar calendar date. Julian date notation was "invented" in 1582 and
- was intended to provide a "universal" calculation of large time intervals.
- The formal Julian system starts with January 1, 4713 BC (considered by
- some religions as the date the earth was created) as day 1 and continues
- through 3267 AD (officially). Thus, January 1, 1988 would be day 2447162 in
- the formal Julian notation.
-
- The historical study of calendar systems can be quite interesting. While
- there are a number of calendar systems currently in use throughout the
- world (Hebrew and Chinese calendars come quickly to mind), there are many
- more no longer in use despite their historical significance.
-
- * * * * * * *
-
- DATES.TPU contains a number of useful functions and procedures such as:
-
- DateToInt - parses an MM/DD/YY date string to provide an integer value.
- IntToDate - converts integer M,D,Y date to a date string.
- ToJulian - Converts the integer date to the Julian date.
- FromJulian - Converts Julian date to integer date.
- DayOfTheWeek - Computes day of week using Zeller's Congruance algorithm.
- CurrentDate - The date in the computer's operating system date buffer.
-
- * * * * * * *
-
- The DateToInt() procedure is described as:
-
- Procedure DateToInt(Date : DateStr;
- Var Month,Day,Year : Integer);
-
- Entering (or passing) the date string returns the integer variables "Month",
- "Day" and "Year" - in that order. The date string is parsed into three
- sections, divided by a non-numeric character such as "-" or "/" so that the
- string "01/01/88" returns the integer values 1 for Month, 1 for Day and 87
- for Year. Similarly, the string "01-01-1987" will return the integer
- values 1 for Month, 1 for Day and 1987 for year. Note that certain European
- and military date notations such as "01.01.87" or "01,01,87" will also be
- parsed correctly.
-
- * * * * * * *
-
- The IntToDate function is described as:
-
- IntToDate(M,D,Y : Integer): DateStr;
-
- Passing three integer values returns the string "MM/DD/YY". If M = "7',
- D = "1" and Y = "88", the returned string will be "07/01/88". Note that
- leading zeroes are added to the string where applicable.
-
- * * * * * * *
-
- The ToJulian function is described as:
-
- ToJulian(M,D,Y : Integer): Real;
-
- Passing three integer values - month, day and year - returns the number of
- days since January 1, 0001 AD (a modified form of Julian date). While this
- may appear to be merely an interesting piece of history, the Julian dates
- may be subtracted from one another to provide the number of days between
- dates - a very practical method of determining various business date require-
- ments. Of course, a little effort is required to ensure that the earlier
- date is subtracted from the later. To get the formal Julian date, simply
- add 1,721,064 to the modified Julian date provided by the program. Note
- also the Julian date is returned as a Real.
-
- * * * * * * *
-
- The FromJulian procedure is described as:
-
- FromJulian(X : Real;
- Var Month, Day, Year : Integer);
-
- This converts the Julian date back to month, day and year. The Julian date
- must be defined as a Real.
-
- * * * * * * *
-
- The DayOfTheWeek function is described as:
-
- DayOfTheWeek(Month,Day,Year : Integer): Integer;
-
- Using Zeller's Congruance algorithm, the day of the week is determined. It
- is necessary, however, to ensure the variable "Year" is the full year.
- If the year is 1987, it must be entered as "1987", not "87". The day is
- returned as an integer: 0 for Sunday, 1 for Monday, and so on.
-
- * * * * * * *
-
- The CurrentDate procedure is described as:
-
- CurrentDate(Var DateString);
-
- This procedure uses the Turbo Pascal 4.0 GetDate procedure but, instead,
- returns the current date set in the operating system as a string in the
- MM/DD/YY format rather than the integer format provided by the Turbo
- Pascal 4.0 "GetDate" procedure.
-
- * * * * * * *
-
- In addition, there are 3 publicly declared constants:
- DayArray - The number of days in each month (non-leap-year),
- WeekArray - The names of the days of the week, 0=Sunday, 1=Monday, etc.,
- MonthArray - The names of the months, 1=January, 2=February, etc.
-
- DateStr is also publicly declared as "String[10]".
-
- Note also that the entered dates are self-correcting; that is, if you enter
- "2-29-87" the Julian date will return "3-1-87", or if you enter "4-31-88"
- the Julian date will return "5-1-88". Note that leap-year dates (2-29-88)
- are also returned correctly.
-
- * * * * * * *
-
- Handling dates, in and of themselves, has never been a difficult task -
- until you are required to calculate the number of days between two dates.
- Fortunately, the problem was resolved for us in 1582 with the Julian calendar,
- although for different purposes and reasons. Had this solution not already
- existed, there is no doubt most programmers would have recognized and handled
- the problem in much the same way.
-
- Oddly, the method of determining days between dates has an amazing number
- of solutions - all of which work quite well. Although the algorithms presented
- here are the most commonly used, they could be wildly inappropriate in geologic
- or pre-history programming applications. However, this algorithm is quite
- appropriate for normal business use (few businesses have kept their doors
- open since before 1 AD or, if they have, require little access to those
- business records).
-
- Pay particular attention to the fact that DATES.TPU assumes all years
- entered as "99" or less fall in the 20th century and treats them accordingly.
- Thus, if you enter "1-1-88", the assumption is that you intended to enter
- "1-1-1988". This is merely to simplify date entry. As we approach the year
- 2000, you may want to change the TPU accordingly.
-
- * * * * * * *
-
- A number of sources were used in the creation of this TPU, including several
- in the public domain. However, none of these sources were directly copied
- and this TPU was independently designed. Because of the large number of
- date handling procedures written in Turbo Pascal, there is a possibility
- this code inadvertantly duplicates pre-exisiting code.
-
- If you have any questions or comments after having reviewed and used
- DATEDEMO.PAS, please address them to:
-
- COMPUsystems N.W.
- Attn: John Winney
- 9792 Edmonds Way, Suite 226
- Edmonds, WA 98020
- (206) 774-1460
- C/O George Wishart Compuserve [70165,460]
-