[futurebasic] [FB^3] Finding a 'Legal' Time

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2001 : Group Archive : Group : All Groups

From: Michael Evans <michael.evans@...>
Date: Tue, 18 Dec 2001 22:07:46 -0500
Hello all:

The following FN isNowTimeLegal% is supposed to find out if the current time
is 'legal', i.e the current time falls within a range of hours where
startHour% defines the start of the range and endHour% the end of the range.
0 <= startHour%, endHour% => 23 where 0 = midnight.

I think that this sort of works but because the seconds derived from a
dateTime are large negative numbers, I'm worried that it wont work for all
values of startHour%, endHour%. Note if startHour% = endHour% then every
nowHour% is 'legal'.

Is there a simpler method that anyone knows of?

Cheers,

----------------------------------------------------------------------------
Michael Evans
----------------------------------------------------------------------------


clear local
local fn isNowTimeLegal%(startHour%, endHour%)
dim nowHour%, hour1Range%, hour2Range%
dim nowSecs&, startSecs&, endSecs&, NowTimeIsLegal%
DIM @ nowDateTimeRec   as DateTimeRec
DIM @ startDateTimeRec as DateTimeRec
DIM @ endDateTimeRec   as DateTimeRec

Long if startHour% = endHour%
NowTimeIsLegal% = _true
xelse
call GetTime(nowDateTimeRec)
call DateToSeconds (nowDateTimeRec, nowSecs&)

nowHour%    = nowDateTimeRec.hour%

startDateTimeRec.year%       = nowDateTimeRec.year%
startDateTimeRec.month%      = nowDateTimeRec.month%
startDateTimeRec.day%        = nowDateTimeRec.day%
startDateTimeRec.hour%       = 0
startDateTimeRec.minute%     = 0
startDateTimeRec.second%     = 0

call DateToSeconds (startDateTimeRec, startSecs&)

startSecs& = startSecs& + (startHour%*60*60)

hour1Range% = startHour% - endHour%
long if hour1Range% < 0
'endHour% is one day later than startHour%
hour2Range% = hour1Range% + 12
xelse
'startHour% and endHour% have the same date
hour2Range% = hour1Range%
end if

endSecs& = startSecs& + (hour2Range%*60*60)

long if (nowSecs& => startSecs&) and (nowSecs& <= endSecs&)
NowTimeIsLegal% = _true
xelse
NowTimeIsLegal% = _false
end if
end if

end fn = NowTimeIsLegal%