According to Section 479 of the BNSS, the court must grant bail to an undertrial who has been detained for a duration equal to or greater than half of the maximum sentence stipulated for the offence.