running a script only till a point in a day

how can i run the script if its less than a particular time only in unix.

for e.g the script kicks off at 9AM and looks for some file etc. I want to make sure it runs only till 12PM and then succeed the job and proceed regardless if the file exists or not. how can we do this

echo waiting ...
while true
do
        date
        test `date '+%H:%M'` == "12:00" && echo time is up && break
        test ! -f /tmp/x.x && echo file not found, sleeping ... && sleep 10
        test -f /tmp/x.x && echo file has been found && break
done
echo done

Tested on Cygwin and OpenBSD