you might benefit from studying state machines. Here is a small introduction to the topic: Yet another Finite State Machine introduction
You have 2 states : IDLE and ACTIVE
state IDLE
if the reed switch activates, note the time, activate the relay and change state to ACTIVE
state ACTIVE
if the reed switch deactivates, deactivate the relay and change state to IDLE
else
if the duration (current time minus the time you noted) exceeds some threshold, deactivate the relay and change state to IDLE