Hi,
You can create a DID Inbound rule, and set custom opening hours 9:00am - 4:00pm
Then for the rest of the hours, you can set the " Destination for calls outside office hours" to a dummy extension, and enable Autoswitch in its forwarding settings.
The dummy extension can have custom office hours 4:00pm - 6:00pm and sending the call to the external number under the Available status.
And then for the DND status, send them to a voicemail (covers the 6:00pm - 9:00am window)