home *** CD-ROM | disk | FTP | other *** search
- Listing 1
-
-
- {
- Program Name: delta_mins.4gl
-
- Description: Function which calculates the
- time difference in minutes
- between any two date/times. The
- input parameters are a start
- date, start hour. start minute,
- and end date, end hour, and end
- minute.
- The variable 'time_diff' is
- passed back with the total time
- difference in minutes.
-
-
- Revision: Version 1.0
- Author: Debra L. McCusker
- }
-
- DEFINE time_diff INTEGER
-
- FUNCTION delta_mins(date1, hour1, min1, date2, hour2, min2)
-
- DEFINE date1 DATE
- DEFINE hour1 INTEGER
- DEFINE min1 INTEGER
- DEFINE date2 DATE
- DEFINE hour2 INTEGER
- DEFINE min2 INTEGER
-
- DEFINE strt_yr INTEGER
- DEFINE strt_mo INTEGER
- DEFINE strt_day INTEGER
- DEFINE end_yr INTEGER
- DEFINE end_mo INTEGER
- DEFINE end_day INTEGER
- DEFINE incr1 INTEGER
- DEFINE incr2 INTEGER
- DEFINE incr3 INTEGER
-
- { Time Difference Calculation -- the normal working day
- is from 8:00 AM to 5:00 PM. The time difference calculation
- will follow these rules: If the starting time and completion
- time occur on the same day, then the starting hours/mins and
- ending hours/mins will simply be used to figure the time
- difference. If the time difference spans days, then the start
- time is subtracted from 1700 hours (5:00 PM) to get the time
- increment for the first day. All complete days between the
- start and end are treated as 9 hours (540 min) each. The end
- increment will be calculated by having 800 hours (8:00 AM)
- subtracted from the completion time.
- }
-
- LET start_yr = YEAR(date1)
- LET start_mo = MONTH(date1)
- LET start_day = DAY(date1)
- LET end_yr = YEAR(date2)
- LET end_mo = MONTH(date2)
- LET end_day = DAY(date2)
-
- IF (start_yr = end yr) AND (strt_mo = end_mo)
- THEN
- IF strt_day = end_day
- THEN
- LET time_diff = (60-min1) + (hour2-(hour1+)) * 60+min2
- ELSE
- LET incr1 = (60-min1) + (17-(hour1+1) * 60
- LET incr2 = ((end_day - 1) - strt_day) * 540
- LET incr3 = (hour2 -8) * 60 + min2
-
- LET time_diff = incr1 + incr2 + incr3
- END IF
- ELSE
- {
- ( If the time diff spans either months or years -- to get the
- time difference, must get # mins to end of the current day, then
- the # complete days between date1 and date2, then # mins left on
- the final day.
- }
- LET incr1 = (60 - min1) + (17 - (hour1 + 1)) * 60
- LET incr2 = ((date2 - 1) - date1) * 540
- LET incr3 = (hour2 - 8) * 60 + min2
-
- LET time_diff = incr1+ incr2 + incr3
- END IF
-
- RETURN time_diff
-
- END FUNCTION
-