For purposes of this chapter:
(a)
A person is deemed confined in a “state prison” if he or she is confined in any of the prisons and institutions specified in Section 5003 by order made pursuant to law, including, but not limited to, commitments to the Department of Corrections and Rehabilitation or the Department of Corrections and Rehabilitation, Division of Juvenile Justice, regardless of the purpose of the confinement and regardless of the validity of the order directing the confinement, until a judgment of a competent court setting aside the order becomes final.
(b)
A person is deemed “confined in” a
prison although, at the time of the offense, he or she is temporarily outside its walls or bounds for the purpose of serving on a work detail, for the purpose of confinement in a local correctional institution pending trial, or for any other purpose for which a prisoner may be allowed temporarily outside the walls or bounds of the prison. A prisoner who has been released on parole is not deemed “confined in” a prison for purposes of this chapter.