help with while loop

I need a while loop that checks for a file existence if it exists it exits with 0 rerturn code, if not it shold check to see if its last day of the month then wait and check for every 5 mnutes
until 1PM, after that succeed the script and continue. But if its the last day of the month it should wait till 4PM and fail the script. can somebody show how the loop looks like

Try...

T=n; until [ -f file1 ] || [ $T = y ]; do sleep 300; [ $(date +%k) -ge 16 ] && T=y; done