Two clocks, not one
Demurrage is the charge for leaving a container inside the terminal after the free days run out. Detention is the charge for keeping the carrier equipment outside the terminal after you have taken it away. They are billed by different parties, they run at different daily rates, and only one of them stops when you unpack.
Most contracts give somewhere between three and seven free days for each. On a busy import lane you can burn four of them before anyone has touched the box, because clearance, a wharf slot and a receiving window all have to line up.
The clock starts at discharge
The day that matters is discharge, not arrival and not berthing. A vessel can sit at anchor for two days, berth on a Friday, and discharge your container on the Saturday. If your free time is four days and the receiver is closed at the weekend, you have one working day left before it costs money.
This is why we put the discharge date in front of you the moment the terminal reports it, with the date free time expires beside it. Both are known on the day. Neither is usually shown to the shipper until the charge exists.
What to do about it
File the entry before arrival. An entry lodged while the box is still at sea is the single largest thing you can do, and it costs nothing.
Book the delivery slot before the vessel berths, not after clearance. The slot is the constraint on retail lanes, and the queue for one is longer than the queue for customs.
Ask for the free time terms at quote stage. Carriers sell extra free days cheaply before a booking and expensively afterwards. If your receiver is slow, buying three extra days up front is usually cheaper than the storage.