The usual solution in respect of duration of port stay is to allow an appropriate period time to cover loading and discharging, generally called ‘laytime’ or, sometimes, ‘lay days’, which is at the charterer’s free disposal, and to grant him the possibility, in case of need, of detaining the vessel beyond the agreed time, against payment of compensation to the owner for the use of the additional time…
Per Lord Esher in Nielsen v Wait (1885) 16 QBD 67 at pp.70-71:
Other days are sometimes given also favour of the charterer, which are called "demurrage days." Those are days beyond the lay day but during which the amount that he has to pay for the use of the ship is a fixed sum, necessarily what it costs the owner to keep his ship, but a fixed sum, which is usually about what it is supposed it costs the owner to keep the ship. This stipulation also is in favour of the charterer, because instead of being involved in a dispute as to what he would have to pay for days during which the ship is kept idle, a sum is fixed, and he knows what he has to pay if he keeps the ship beyond the lay days. Those are the "demurrage days." If he keeps the ship beyond the lay days, when he pays nothing, and only the number of demurrage days, he pays a fixed sum for demurrage. If he keeps the ship after that, it is a question of damages, and he does not know what he has to pay until the question is settled by tribunal or by agreement.
Per Lord Esher in Budgett & Co. v Binnington & Co  1 QB 35 at p.38:
This has been called an absolute and independent contract, and it is obvious that contrast is intended to be drawn between such a contract and a conditional one, and that absolute contract is meant an unconditional one. The only condition attached to it is that lay-days shall have commenced and run out, and, that condition being fulfilled, the obligation arises. Directly the shipowner shews this state of facts, he has proved his case, and it lies on other side to shew, not that there has been no breach of contract, but that he is excused from the performance - in other words, his case is one of confession and avoidance, and the whole burden of proof is on him. Speaking generally of all contracts, a breach is excused where the party committing the breach has been prevented by the other side from carrying out his contract. Here the condition is that the cargo should be out of the ship in a certain number of days; and shipowner, by any act of his, has prevented the discharge, then, though the freighter’s contract is broken, he is excused .
In Inverkip Steamship Co Ltd v Bunge & Co  2 KB 193 at pp.200-202 Scrutton LJ said:
…there is almost invariably a term in the agreement providing for an additional payment, known as demurrage, for detention beyond the agreed lay days. This is sometimes treated as agreed damages for detaining the ship, sometimes as an agreed payment for extra lay days. In my view the mere fact that the charterer has not loaded the ship in the lay days does not entitle the shipowner to withdraw the ship from the service; and whether the payment for these days after the lay days on which the ship is detained is treated as agreed liquidated damages or as an agreed payment for time which the charterer has a right to use at his option, the amount to be paid for these days is fixed by the charter. On the other hand it is obvious that the charterer is not entitled to keep the ship on demurrage "for ever." What is the time when he may treat his obligation to stay as removed and sail away?
…To enable the ship to abandon the charter without the consent of the charterer I think the shipowner must show either such a failure to load as amounts to a repudiation of or final refusal to perform the charter, which the shipowner may accept as a final breach and depart claiming damages – Mersey Steel and Iron Co. v Naylor, Benzon & Co. (1884) 9 App. Cas. 434, 439 - or such a commercial frustration of the adventure by delay under the doctrine of Jackson v Union Marine Insurance Co. (1874) LR 10 CP 125 as puts an end to the contract.
…One main argument of the shipowners’ counsel as I understood it was that as the charterer was bound to have a cargo ready for loading, and had not such a cargo, the demurrage provision did not apply. This is in my experience an entirely novel argument. Ships with twenty lay days have frequently loaded no cargo for, say, twelve days because none was there and either finished in their lay days or in some demurrage days; but it has never been contended or understood to be the law that because there was no cargo there when the ship was ready to load the charterer had lost the benefit of the demurrage days or lay days and was bound to load in a reasonable time or pay damages for detention.
Per Lord Brandon in President of India v Lips Maritime Corporation (The Lips)  2 Lloyd’s Rep 311, at p.315:
[Demurrage] is a liability in damages to which a charterer becomes subject because, by detaining the chartered ship beyond the stipulated lay days, he is in breach of his contract. Most, if not all, voyage charters contain a demurrage clause, which prescribes a daily rate at which the damages for such detention are to be quantified. The effect of such a claim is to liquidate the damages payable: it does not alter the nature of the charterer’s liability, which is and remains a liability for damages, albeit liquidated damages.
MSC Mediterranean Shipping Company SA v Cottonex Anstalt  EWHC 283 (Comm) per Leggat J at para 115:
The ability to claim demurrage in a significant category of cases in an amount which is extravagantly high in comparison with the sum that would be required to compensate for loss caused by the breach signifies that the payments cannot be justified as a pre-estimate of the loss. Nor can I see any other commercial justification for such an arrangement. Making every allowance for the advantages of certainty and avoiding disputes, it is impossible to justify on compensatory grounds a provision which can require payments without end for so long as the Carrier chooses to keep the contract in force. Such a clause could only be explained as serving the function of penalising breach of the contract.