Penal Code PC § 4024
(a) The sheriff may discharge any prisoner from the county jail at such time on the last day such prisoner may be confined as the sheriff shall consider to be in the best interests of the prisoner.
(b)(1) Upon completion of a sentence served by a prisoner or the release of a prisoner ordered by the court to be effected the same day, including prisoners who are released on their own recognizance, have their charges dismissed by the court, are acquitted by a jury, are cited and released on a misdemeanor charge, have posted bail, or have the charges against them dropped by the prosecutor, the sheriff may offer a voluntary program to the prisoner that would allow that prisoner to stay in the custody facility for up to 16 additional hours or until normal business hours, whichever is shorter, in order to offer the prisoner the ability to be discharged to a treatment center or during daytime hours. The prisoner may revoke his or her consent and be discharged as soon as possible and practicable.
(2) This subdivision does not prevent the early release of prisoners as otherwise allowed by law or allow jails to retain prisoners any longer than otherwise required by law without the prisoner’s express written consent.
(3) Offering this voluntary program is an act of discretion within the meaning of Section 820.2 of the Government Code .
(4) If a prisoner has posted bail and elects to participate in this program, he or she shall notify the bail agent as soon as possible and practicable of his or her decision to participate.
(5) A sheriff offering this program shall, whenever possible, allow the prisoner volunteering to participate in the program to make a telephone call to either arrange for transportation, or to notify the bail agent pursuant to paragraph (4), or both.