Article 59 [source]

Spanish Criminal Code
English translation

When the precautionary measures suffered and the sentence imposed are of a different nature, the Judge or Court will order that the sentence imposed be considered executed in that part which it considers compensated.