
76 Ill.2d 244 (1979)
390 N.E.2d 872
THE PEOPLE OF THE STATE OF ILLINOIS, Appellee,
v.
LARUE SCHEIB, Appellant.  THE PEOPLE OF THE STATE OF ILLINOIS, Appellee,
v.
RONALD FERGUSON, Appellant.
Nos. 50865, 51021.
Supreme Court of Illinois.
Opinion filed May 24, 1979.
*245 *246 *247 Mary Robinson, Deputy Defender, and Richard E. Cunningham, Assistant Appellate Defender, of the Office of the State Appellate Defender, of Elgin, for appellant.
William J. Scott, Attorney General, of Chicago, C. Joseph Cavanagh, State's Attorney, of Springfield, and Edward Petka, State's Attorney, of Joliet (Donald B. Mackay and Melbourne Noel, Assistant Attorneys General, of Chicago, and Robert C. Perry and Jane F. Bularzik, of the State' Attorneys Appellate Service Commission, of Springfield, of counsel), for the People.
Robert Agostinelli, Deputy Defender, and Michael J. Pelletier, Assistant Appellate Defender, of the Office of the State Appellate Defender, of Ottawa, for appellant.
*248 William J. Scott, Attorney General, of Chicago, C. Joseph Cavanagh, State's Attorney, of Springfield, and Edward Petka, State's Attorney, of Joliet (Donald B. Mackay and Melbourne Noel, Assistant Attorneys General, of Chicago, and Robert C. Perry and Jane F. Bularzik, of the State's Attorneys Appellate Service Commission, of Springfield, of counsel), for the People.
Appellate court affirmed in part and reversed in part; circuit court affirmed in part and reversed in part; cause remanded. Appellate court reversed; circuit court affirmed in part and reversed in part; cause remanded.
MR. JUSTICE MORAN delivered the opinion of the court:
Each of these two cases, which we have consolidated for review in this court, involves the application of credit for time served prior to each defendant's revocation proceeding.
In cause No. 50865, defendant, Larue Scheib, pleaded guilty to burglary and was sentenced by the circuit court of Sangamon County to two years' probation. The conditions of Scheib's probation included a $200 fine and separate jail sentences of six weekends and 20 days in jail. The trial court gave Scheib credit for 20 days which he had already served prior to trial. Approximately four months later, Scheib's probation was revoked pursuant to a trial court's finding that he had violated his probation by committing arson. The trial court sentenced Scheib on the burglary offense to a prison term of two to six years. The court allowed him credit for 82 days which he had served in jail during the pendency of the probation-revocation and sentencing hearings but refused to credit him for the time served on probation, for the weekends served in the county jail, or for the 20 days of incarceration which had preceded the original trial on the burglary offense.
The Appellate Court for the Fourth District held that Scheib was entitled to credit for the weekends of periodic imprisonment served as a condition of probation but was not entitled to credit for the 20 days he had served prior to the original trial. The court also held that, because *249 periodic imprisonment is to be calculated on the basis of the duration of the term of sentence, Scheib was to be granted credit of one full week for each weekend actually served in jail. (59 Ill. App.3d 104.) In response to the court's denial of rehearing, one judge indicated that he would grant credit for the 20 days served in custody. We allowed Scheib leave to appeal.
In cause No. 51021, defendant, Ronald Ferguson, was convicted of criminal damage to property, a misdemeanor, and was sentenced by the circuit court of Will County to a conditional discharge for a period of two years. Ferguson's discharge was conditioned, in part, upon his serving 120 days in jail. The trial court gave Ferguson credit for 60 days which he had already served prior to trial and suspended the remaining 60-day term. Less than a month later, Ferguson's conditional discharge was revoked pursuant to a trial court's finding that he had violated the terms of his conditional discharge by committing robbery. He was sentenced on the misdemeanor offense to a term of 264 days in the Vandalia Correctional Center. The court allowed him credit for 14 days which he had spent on conditional discharge but failed to credit him for the 60 days he had served in custody prior to the original trial.
The Appellate Court for the Third District held that, because Ferguson had already received credit for the 60 days of preconviction incarceration, he was not entitled to credit upon resentencing after revocation of his conditional discharge. (60 Ill. App.3d 422.) We allowed Ferguson leave to appeal.
The predominant question common to both cases is whether time spent in confinement for a particular offense must be credited to a defendant upon resentencing after revocation of probation or conditional discharge. Two potentially conflicting provisions of chapter V of the Unified Code of Corrections (Ill. Rev. Stat. 1975, ch. 38, par. 1005-1-1 et seq.) are involved. Section 5-6-4(h) of *250 the Code, which section applies to the sentences here involved, provides in pertinent part:
"Time served on probation or conditional discharge shall be credited by the court against a sentence of imprisonment or periodic imprisonment unless the court orders otherwise." (Emphasis added.) (Ill. Rev. Stat. 1975, ch. 38, par. 1005-6-4(h).)
This section, applicable generally upon resentencing after revocation proceedings, authorizes the trial court to use its discretion in determining if credit is warranted. On its face, the section might be construed to apply both to time spent unconfined on probation (or conditional discharge) and to time which, though spent in confinement, was considered served as a condition of probation (or conditional discharge).
The Code's section 5-8-7(b), however, provides:
"The offender shall be given credit on the maximum term and the minimum period of imprisonment for time spent in custody as a result of the offense for which the sentence was imposed." (Emphasis added.) (Ill. Rev. Stat. 1975, ch. 38, par. 1005-8-7(b).)
This section applies, generally, whenever a sentence of imprisonment is imposed, and it requires that credit be given for all time spent in custody for the same offense.
The two statutory provisions are incompatible only if section 5-6-4(h) is construed, as the State urges, to apply, upon resentencing after revocation proceedings, to the time actually spent in custody as a condition of probation or conditional discharge.
A cardinal rule of statutory construction ordains that sections in pari materia should be considered with reference to one another so that both sections may be given harmonious effect. (Galvin v. Galvin (1978), 72 Ill.2d 113, 118; Gillespie v. Riley Management Corp. (1974), 59 Ill.2d 211, 215; 2A J. Sutherland, Statutes & Statutory Construction secs. 46.05, 51.03 (4th ed. 1973).) It is not a *251 legislative oversight that section 5-8-7(b), on the one hand, requires that credit be granted and that section 5-6-4(h), on the other hand, permits the denial of credit. In People ex rel. Morrison v. Sielaff (1974), 58 Ill.2d 91, this court recognized that the legislature intended to distinguish between confinement and lesser forms of restraint for the purposes of applying credit. In holding that a defendant was not entitled to credit under section 5-8-7(b) for the time spent out on bail, the court confirmed that section 5-8-7(b) requires only that the period during which a defendant is actually confined be credited to the sentence of imprisonment ultimately imposed for the offense. In contrast to section 5-8-7(b), section 5-6-4(h) does not refer to time spent in confinement. Section 5-6-4(h) (Ill. Rev. Stat. 1977, ch. 38, par. 1005-6-4(h)) now encompasses three specific forms of restraint  probation, conditional discharge and supervision  each a lesser restraint on freedom than confinement. Reading the sections in consort, we conclude that section 5-8-7(b) is to apply whenever the time, for which credit is sought, was served in confinement, and that section 5-6-4(h) is to apply whenever the time was served unconfined on probation, conditional discharge or supervision. Read in this manner, a defendant must be fully credited for any time which he has spent in jail for a particular offense, regardless of whether the time in confinement was considered served as part of a condition of probation or conditional discharge.
In each of the cases at bar, the defendant spent time in jail prior to trial because of an inability to furnish bail. This jail time was credited against the time which the defendant was to serve as part of the original sentence. Upon resentencing after revocation of the original sentence, however, the trial judge refused to credit the jail time against the sentence of imprisonment for the same offense. Notwithstanding the clear and explicit language of *252 section 5-8-7(b), the State contends that credit was properly denied upon resentencing because the jail time had already been credited against the original sentence. The State suggests that a literal reading of section 5-8-7(b) would afford a defendant "repeat crediting" for the same time served in jail.
The State's position has only superficial appeal. The object of mandatory credit under section 5-8-7(b) is to account for all the time served in confinement for a particular offense. (Ill. Ann. Stat., ch. 38, par. 1005-8-7, Council Commentary, at 514 (Smith-Hurd 1973).) The concept of credit insures that a defendant is never subjected to more total time in confinement for a particular offense upon resentencing than he could have received for the offense in the first instance. When a defendant is credited upon imposition of the original sentence for the time served until then, and then credited upon resentencing after revocation, he is not being given double credit against the ultimate sentence: the time served has merely been carried over to the resentencing proceeding so that it may be properly subtracted once from the sentence he must ultimately serve.
Additionally, the State's position is wanting for constitutional reasons. Clearly, we do not favor any construction that would raise legitimate doubts as to the constitutional validity of a statutory provision. (Craig v. Peterson (1968), 39 Ill.2d 191, 201; People v. Nastasio (1960), 19 Ill.2d 524, 529.) Two situations readily illustrate the constitutional vulnerability of the State's argument.
In the first, a defendant, unable to post bail, remains in jail for 30 days awaiting trial. Upon conviction of a misdemeanor, he is sentenced to two years' probation with the condition that he serve 30 days in jail. The 30 days of pretrial incarceration are credited against the original sentence. Upon violation of probation, the defendant is sentenced to the 364-day maximum allowed for a misdemeanor. *253 (Ill. Rev. Stat. 1975, ch. 38, par. XXXX-X-XX; Ill. Rev. Stat. 1975, ch. 38, par. 1005-5-2(b).) According to the State, credit should not be given for the 30 days spent in confinement because the 30 days had already been credited at the time the original sentence was imposed. The obvious consequence of the denial of credit is that the defendant is subjected to 364 days plus 30 days in confinement for the commission of a misdemeanor, a punishment which exceeds the maximum permitted for such offense. It was just such a consequence that the Supreme Court, in North Carolina v. Pearce (1969), 395 U.S. 711, 23 L.Ed.2d 656, 89 S.Ct. 2072, held to be a violation of the constitutional prohibition against double jeopardy because it constituted multiple punishments for the same offense. We, too, cite the situation because "[t]he constitutional violation is flagrantly apparent in a case involving the imposition of a maximum sentence * * *. * * * Though not so dramatically evident, the same principle obviously holds true whenever punishment already endured is not fully subtracted from any new sentence imposed." North Carolina v. Pearce (1969), 395 U.S. 711, 718, 23 L.Ed.2d 656, 665, 89 S.Ct. 2072, 2077.
In the second situation, a defendant, capable of posting bail, is released pending trial. Upon conviction, he is sentenced to two years' probation with the condition that he serve 30 days in jail. After trial, he serves the 30 days in jail as part of the original sentence. Thereafter, he violates his probation. According to the State, this defendant, unlike the defendant in the former situation, would be entitled to credit under section 5-8-7(b) for the 30 days in jail because he had not yet received credit for it. Yet, in both situations, the defendants had committed identical offenses, received identical original sentences and spent the same amount of time in confinement prior to violating probation. The only difference between the two situations is that, in the former, the defendant had spent his time in jail prior to trial because *254 of an inability to furnish bail. Clearly, no legitimate legislative purpose would be served by creating two such distinct classifications under section 5-8-7(b). See Annot., Right to Credit for Time Spent in Custody Prior to Trial or Sentence, 77 A.L.R.3d 182, sec. 4 (1977).
The State raises a final point which pertains only to defendant Scheib. The conditions of Scheib's probation included a sentence of six weekends in the Sangamon County jail. Scheib had begun to serve this sentence when his probation was revoked. Upon resentencing Scheib to prison for a term of two to six years, the trial court applied section 5-6-4(h) and refused to credit Scheib for any of the weekends served in jail. The appellate court reversed. In determining how much credit Scheib should be allowed, the appellate court characterized the weekend sentence as a term of periodic imprisonment (Ill. Rev. Stat. 1975, ch. 38, pars. 1005-6-3(b)(1), 1005-7-1 et seq.) and concluded that Scheib must be granted credit of one full week for each weekend actually served in jail. The State contends that the trial court properly denied the credit and, alternatively, posits that if credit must be granted, it should reflect only the number of weekend days actually spent in jail. We disagree with the State in both respects.
As already concluded, section 5-6-4(h) is not controlling when the sentence of probation incorporates a condition which subjects a defendant to periods of actual confinement. When the trial court imposed a sentence of six weekends in jail as a condition of Scheib's probation, it did so with the express authorization of section 5-6-3(b)(1) of the Code. Pursuant to this section, a trial court may require, as a condition of probation, that the defendant be sentenced to a term of imprisonment which is to be served periodically for the duration of its term. (Ill. Rev. Stat. 1975, ch. 38, par. 1005-6-3(b)(1).) The court ordered that Scheib be committed on the weekends *255 for a term of six weeks and released for the interim periods. Section 5-7-1(d) of the Code expressly instructs that "[t]he term of the sentence [of periodic imprisonment] shall be calculated upon the basis of the duration of its term rather than upon the basis of the actual days spent in confinement." (Ill. Rev. Stat. 1975, ch. 38, par. 1005-7-1(d).) Consequently, though Scheib was to spend only 12 weekend days in confinement, the term of the imprisonment sentence was to run 37 days. Scheib had served only a portion of the term when he was resentenced for violating probation. The Code provides:
"That part of the term under paragraph (d) of Section 5-7-1 which has been served under the sentence of periodic imprisonment shall be credited against a sentence of imprisonment." (Emphasis added.) (Ill. Rev. Stat. 1975, ch. 38, par. 1005-7-2(c).)
This section plainly mandates that the credit to which Scheib is entitled must be determined on the basis of the duration of that portion of the 37-day term which he had served.
Accordingly, the judgments of the appellate and circuit courts in these two causes are reversed insofar as they denied the defendants credit for the terms of their incarceration. The judgments of the appellate and circuit courts in cause No. 50865, and of the circuit court in cause No. 51021, are otherwise affirmed. The causes are remanded to the respective trial courts with directions that the defendants be given proper credit in accordance with the views expressed in this opinion.
50865  Appellate court affirmed in part and reversed in part; circuit court affirmed in part and reversed in part; cause remanded, with directions.
51021  Appellate court reversed; circuit court affirmed in part and reversed in part; cause remanded.
