(1)This section applies where—
(a)a court or officer sentences an offender to a term of imprisonment or service detention in respect of a service offence (“the offence in question”); and
(b)the offender has been kept in service custody, in connection with the offence in question or any related offence, for any period since being charged with the offence in question or any related offence.
(2)The court must direct that the number of days for which the offender has been kept in service custody in connection with the offence in question or any related offence since being so charged is to count as time served by him as part of the sentence.
(3)Subsection (2) does not apply if and to the extent that—
(a)rules made by the Secretary of State so provide in the case of—
(i)a period of service custody which is wholly or partly concurrent with a sentence of imprisonment or service detention; or
(ii)sentences of imprisonment or service detention for consecutive terms or for terms which are wholly or partly concurrent; or
(b)it is in the opinion of the court just in all the circumstances not to give a direction under that subsection.
(4)Where the court gives a direction under subsection (2) it must state in open court—
(a)the number of days for which the offender was kept in service custody as mentioned in that subsection; and
(b)the number of days in relation to which the direction is given.
(5)Where the court does not give a direction under subsection (2), or gives such a direction in relation to a number of days less than that for which the offender was kept in service custody as mentioned in that subsection, it must state in open court—
(a)that its decision is in accordance with rules made under paragraph (a) of subsection (3); or
(b)that it is of the opinion mentioned in paragraph (b) of that subsection and what the circumstances are.
(6)This section applies to—
(a)a determinate sentence of detention under section 209, and
(b)a sentence of detention under section 228 of the 2003 Act passed as a result of section 222 of this Act,
as it applies to an equivalent sentence of imprisonment.
(7)References in this section to “the court” are to the court or officer mentioned in subsection (1).