This is fairly easy to do.

You will need 4 ring Plans as follows:

RP1 - Company A and Company B Closed (Night)
RP2 - Company A OPEN and Company B CLOSED
RP3 - Company A and Company B OPEN (Day)
RP4 - Company A CLOSED and Company B OPEN

Then set your trunk ring destinations for the 2 lines accordingly.

This can be setup with auto day/night switch or manual.