SAY "Enter the Hour and Minute to schedule an event,"
SAY "for example, 10:45pm"
PULL scheduled
IF LASTPOS('PM', scheduled) \= 0 THEN DO
PARSE VAR scheduled hours ':' minutes 'PM' .
pm = 'pm'
END
ELSE IF LASTPOS('AM', scheduled) \= 0 THEN DO
PARSE VAR scheduled hours ':' minutes 'AM' .
pm = 'am'
END
ELSE DO
PARSE VAR scheduled hours ':' minutes .
pm = 'pm'
END
hours = STRIP(hours)
minutes = STRIP(minutes)
IF hours = '' | DATATYPE(hours, 'W') = 0 THEN DO
bad:
SAY "Entered time incorrectly"
EXIT
END
IF minutes = '' | DATATYPE(minutes, 'W') = 0 THEN SIGNAL bad
SAY '"'||hours||'"'
SAY '"'||minutes||'"'
SAY '"'||pm||'"'
scheduled = hours || ':' || minutes || pm
hours = TIME('H', scheduled, 'C')
minutes = TIME('M', scheduled, 'C')
minutes = (hours * 60) + minutes
current = TIME('C')
curr_hours = TIME('H', current, 'C')
curr_minutes = TIME('M', current, 'C')
curr_minutes = (curr_hours * 60) + curr_minutes
IF curr_minutes <= minutes THEN DO
seconds = (minutes - curr_minutes) * 60
SAY seconds
CALL SLEEP seconds
SAY "It's time!"
END
ELSE SAY "The scheduled time has already passed!"
EXIT |