home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-07-23 | 4.4 KB | 161 lines | [TEXT/PJMM] |
- unit Calendar;
-
- {Except for IsValidDate, the only connection this unit has to Calendar.c is the}
- {calling syntax. It uses the toolbox calls Date2Secs and Secs2Date.}
- {By Ingemar Ragnemalm 1994}
-
- interface
-
- function IsValidDate (day: Integer; month: Integer; year: Integer): Boolean;
- function DaysInMonth (theMonth: Integer; theYear: Integer): Integer;
- function DaysInYear (theYear: Integer): Integer;
- function FirstDayOfMonth (theMonth: Integer; theYear: Integer): Integer;
- function DayOfMonth (theDay, theMonth, theYear: Integer): Integer;
-
- { constants for month of year values (non-macish format, unfortunately)}
- 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;
- { constants for days of week values }
- SUNDAY = 1;
- MONDAY = 2;
- TUESDAY = 3;
- WEDNESDAY = 4;
- THURSDAY = 5;
- FRIDAY = 6;
- SATURDAY = 7;
-
- implementation
-
- {• IsValidDate() •//}
-
- {• Given a day, month, year input, IsValidDate() will return TRUE }
- {• if the date is valid and FALSE if not. •//}
- {• --------------------------------------------------------------- •//}
-
- function IsValidDate (day: Integer; month: Integer; year: Integer): Boolean;
- begin
- IsValidDate := FALSE;
- if (year > 0) then
- if ((month > 0) and (month <= 12)) then
- if (day > 0) and (day <= DaysInMonth(month, year)) then
- IsValidDate := TRUE;
- end; {• IsValidDate()•//}
-
- {• --------------------------------------------------------------- •//}
-
- {• DaysInMonth() •//}
-
- {• Given a month (range JANUARY..DECEMBER <1..12>) and a year, •//}
- {• DaysInMonth() will return the number of days in the input month. Works•//}
- {• for leap years. •//}
-
- {• --------------------------------------------------------------- •//}
-
- function DaysInMonth (theMonth: Integer; theYear: Integer): Integer;
- var
- time: DateTimeRec;
- secs: longint;
- begin
- time.year := theYear;
- time.month := theMonth;
- time.day := 32;
- time.hour := 0;
- time.minute := 0;
- time.second := 0;
- Date2Secs(time, secs);
- Secs2Date(secs, time);
-
- DaysInMonth := 32 - time.day;
- end; {• DaysInMonth()•//}
-
- {• --------------------------------------------------------------- •//}
-
- {• DaysInYear() •//}
-
- {• Given an input year, DaysInYear() will compute the number of days in •//}
- {• the year. •//}
-
- {• --------------------------------------------------------------- •//}
-
- function DaysInYear (theYear: Integer): Integer;
- var
- time: DateTimeRec;
- secs: longint;
- begin
- time.year := theYear;
- time.month := 1;
- time.day := 367;
- time.hour := 0;
- time.minute := 0;
- time.second := 0;
- Date2Secs(time, secs);
- Secs2Date(secs, time);
-
- DaysInYear := 367 - time.day;
- end; {• DaysInYear()•//}
-
- {• --------------------------------------------------------------- •//}
-
- {• FirstDayOfMonth() •//}
-
- {• Given a valid month in theMonth (JANUARY..DECEMBER <1..12>), •//}
- {• FirstDayOfMonth() will return the actual day (SUNDAY..SATURDAY <1..7>)•//}
- {• that theMonth starts on. •//}
-
- {• --------------------------------------------------------------- •//}
-
- function FirstDayOfMonth (theMonth: Integer; theYear: Integer): Integer;
- var
- time: DateTimeRec;
- secs: longint;
- begin
- time.year := theYear;
- time.month := theMonth;
- time.day := 1;
- time.hour := 0;
- time.minute := 0;
- time.second := 0;
- Date2Secs(time, secs);
- Secs2Date(secs, time);
-
- FirstDayOfMonth := time.dayOfWeek;
- end; {• FirstDayOfMonth()•//}
-
- {• --------------------------------------------------------------- •//}
-
- {• DayOfMonth() •//}
-
- {• Given a valid input date, DayOfMonth() will return the actual day •//}
- {• (SUNDAY..SATURDAY <1..7>). •//}
-
- {• --------------------------------------------------------------- •//}
-
- function DayOfMonth (theDay, theMonth, theYear: Integer): Integer;
- var
- time: DateTimeRec;
- secs: longint;
- begin
- time.year := theYear;
- time.month := theMonth;
- time.day := theDay;
- time.hour := 0;
- time.minute := 0;
- time.second := 0;
- Date2Secs(time, secs);
- Secs2Date(secs, time);
-
- DayOfMonth := time.dayOfWeek;
- end; {• DayOfMonth()•//}
-
- end.