
88 Cal.App.3d 864 (1979)
152 Cal. Rptr. 111
In re GORDON BANKS on Habeas Corpus.
Docket No. 10103.
Court of Appeals of California, Fourth District, Division Two.
January 26, 1979.
*866 COUNSEL
Charles E. Ward, Public Defender, Littleton M. Gunn and Andrew E. Rubin, Deputy Public Defenders, for Petitioner.
Evelle J. Younger, Attorney General, Michael D. Wellington, Deputy Attorney General, James M. Cramer, District Attorney, and Joseph A. Burns, Deputy District Attorney, for Respondent.
OPINION
GARDNER, P.J.
In this case we hold that constitutional principles of equal protection and due process of law mandate that in calculating the maximum duration of an incompetency commitment under Penal Code sections 1368-1370, credit must be given for precommitment confinement attributable to the same criminal prosecution.
Petitioner, charged with a misdemeanor  brandishing a deadly weapon, Penal Code section 417, subdivision (a)  pleaded not guilty and not guilty by reason of insanity. After a guilty verdict on the guilt phase and before the sanity phase could begin, he was found to be mentally incompetent to stand trial. (Pen. Code, § 1368.) Criminal proceedings were suspended and he was committed to a state hospital. At the time of the commitment, he had already spent over 60 days in confinement as a result of this prosecution. We infer that this confinement was based on his inability to make bail, i.e., indigency.[1] When the petitioner had been in the state hospital for six months from the date of his original confinement, he filed a petition for writ of habeas corpus. The prosecution resisted based on the following language from Penal Code section 1370: "If at the end of ... a period of commitment equal to the maximum term *867 of imprisonment provided by law for the most serious offense charged in the ... misdemeanor complaint ... the defendant has not recovered his mental competence, he shall be returned to the committing court." (Italics added.) The prosecution contended that the plain language of this section indicated that the time of commitment started the clock running. We must agree. Under the plain language of Penal Code section 1370, the petitioner could remain in the state hospital for six months from the date of commitment (the maximum period of punishment under Pen. Code, § 417, subd. (a)).
The petitioner next contends that, under Penal Code section 2900.5, he is entitled to credit for his initial period of incarceration prior to commitment. To this contention the prosecution argues that Penal Code section 2900.5 provides for credit only after a defendant has been convicted of a criminal offense. Here, the petitioner has never been convicted since proceedings have been suspended, ergo Penal Code section 2900.5 affords him no comfort. Again, we must agree. Under the plain language of the statute Penal Code section 2900.5 refers to convictions and there has never been a conviction.
So far, on elementary principles of statutory construction, i.e., the plain language of the statute, the prosecution is far ahead. The box score  prosecution two, the petitioner zero. However, as we all know, simple principles of statutory construction are not necessarily the answer. The courts, under constitutional principles, have often made mincemeat of some seemingly clear-cut statutory schemes. Thus, although the statute clearly gave the petitioner no credit for precommitment custody, principles of equal protection and due process of law mandate that credit. The application of these principles has a devastating effect on the prosecution's position  and the statutory scheme. The reasons fall, generally, into two categories.

I.
(1) Denial of credit for precommitment confinement results in discrimination on the basis of wealth in violation of state and federal equal protection guaranties because indigent defendants who are unable to obtain release on bail will serve precommitment jail time and so will be confined longer than wealthier defendants who are released on bail prior to their incompetency commitments. (Williams v. Illinois (1970) 399 U.S. 235 [26 L.Ed.2d 586, 90 S.Ct. 2018]; In re Young, 32 Cal. App.3d 68, 71 [107 Cal. Rptr. 915].)
*868 The leading case is Williams v. Illinois, supra. There, the petitioner was sentenced to a one-year term and a $500 fine. Under Illinois law, a prisoner who had not paid his fine by the end of his term could be required to remain in confinement until the fine was worked off at the rate of $5 for each additional day served. The Supreme Court held this procedure to be constitutionally defective, stating: "... once the State has defined the outer limits of incarceration necessary to satisfy its penological interests and policies, it may not then subject a certain class of convicted defendants to a period of imprisonment beyond the statutory maximums solely by reason of their indigency." (Id., at pp. 241-242 [26 L.Ed.2d at p. 593]. See also, Tate v. Short (1971) 401 U.S. 395, 398-399 [28 L.Ed.2d 130, 133-134, 91 S.Ct. 668].)
The relevance of this decision to the issue of a convicted defendant's right to credit for presentence confinement was quickly perceived by lower federal courts. In case after case, state laws denying or restricting such credits were struck down. (E.g., Johnson v. Prast (7th Cir.1977) 548 F.2d 699, 702; King v. Wyrick (8th Cir.1975) 516 F.2d 321, 323; Hart v. Henderson (5th Cir.1971) 449 F.2d 183, 185; White v. Gilligan (S.D. Ohio 1972) 351 F. Supp. 1012, 1013.) Similar conclusions were reached by state courts. (E.g., Klimas v. State (1977) 75 Wis.2d 244 [249 N.W.2d 285, 287]; State v. Sutton (1974) 21 Ariz. App. 550 [521 P.2d 1008, 1009].) Reviewing this line of authority, a federal court recently stated: "It seems recognized that the right to credit for jail time awaiting trial on a bailable offense and pending appeal is not a matter of legislative grace but is a right constitutionally mandated, available to state prisoners as well as federal prisoners." (Durkin v. Davis (4th Cir.1976) 538 F.2d 1037, 1039-1040.)
Prior to 1972, there was no statutory authority in California for an award of credit for presentence confinement. (See People v. Rose, 41 Cal. App.2d 445, 446 [106 P.2d 930].) In 1971, the Legislature enacted two statutes, Penal Code sections 2900.5 and 2900.6, mandating presentence credit for convicted felons and misdemeanants, respectively, effective in March 1972. (Stats. 1971, ch. 1732.) Later these statutes were revised and combined into the present section 2900.5. (Stats. 1976, ch. 1045.) In 1973, it was held that prisoners who began serving their sentences prior to the effective date of section 2900.5 were nonetheless entitled to credit for presentence incarceration upon a showing that the confinement resulted from indigency. (In re Young, supra, 32 Cal. App.3d 68, 75.) Shortly thereafter, our Supreme Court held the nonretroactivity provisions of section 2900.5 unconstitutional on equal protection grounds. (In re Kapperman, 11 Cal.3d 542, 545-550 [114 Cal. Rptr. 97, 522 P.2d 657].)
*869 For purposes of equal protection, we can perceive no logical distinction between the application of credit against an actual sentence and the application of credit against a sentence term used to measure the maximum permissible duration of an incompetency commitment. In either case, the denial of credit necessarily results in longer confinement for indigents unable to post bail bonds.[2] This discriminatory treatment is constitutionally forbidden.

II.
(2) Pretrial confinement of incompetent defendants beyond the maximum period for the charged offense violates basic notions of fairness and due process because the state has no legitimate interest in continued confinement of an incompetent accused beyond the maximum sentence term for the charged offense. (In re Davis, 8 Cal.3d 798 [106 Cal. Rptr. 178, 505 P.2d 1018].)
(3) "The due process clauses, federal and state, are the most basic substantive checks on government's power to act unfairly or oppressively. As such, they protect against infringements by the state upon those `fundamental' rights `implicit in the concept of ordered liberty.' (Palko v. Connecticut (1937) 302 U.S. 319, 325 [82 L.Ed. 288, 292, 58 S.Ct. 149].)" (Hale v. Morgan, 22 Cal.3d 388, 398 [149 Cal. Rptr. 375, 584 P.2d 512].) "Substantive due process ... deals with protection from arbitrary legislative action ... i.e., the law must not be unreasonable, arbitrary or capricious but must have a real and substantial relation to the object sought to be attained." (Gray v. Whitmore, 17 Cal. App.3d 1, 21 [94 Cal. Rptr. 904].) "Due process forbids the arbitrary deprivation of liberty (Goss v. Lopez, supra, 419 U.S. 565, 574 [42 L.Ed.2d 725, 734-735] and, in the context of commitment to a mental hospital requires at least `that the nature and duration of commitment bear some reasonable relation to the purpose for which the individual is committed.' (Jackson v. Indiana (1972) 406 U.S. 715, 738 [32 L.Ed.2d 435, 451, 92 S.Ct. 1845].)" (In re Roger S., 19 Cal.3d 921, 935 [141 Cal. Rptr. 298, 569 P.2d 1286].) (Italics added.)
*870 (4) It is undisputed that if petitioner were to recover his competency and to be convicted of the charged offense, any sentence he received would have to be reduced by allowing credit both for the precommitment time spent in jail and for the commitment period in a state hospital. (Pen. Code, § 2900.5; In re Jordan, 50 Cal. App.3d 155, 158 [123 Cal. Rptr. 268]; People v. Cowsar, 40 Cal. App.3d 578, 579 [115 Cal. Rptr. 160].) If the sum of these two periods of confinement equalled six months, the sentencing court could not require any further confinement. (See Pen. Code, § 1170, subd. (a)(2).) Thus, petitioner became immune from postsentence confinement when he had been confined for a total of six months on the pending charge even though his incompetency commitment was then less than six months.
The first question raised by petitioner's argument is: What is the state's interest in continuing the prosecution of an accused who, by reason of presentence confinement, has acquired an immunity to postsentence punishment? The second and related question is: Does the interest of the state in determining the guilt or innocence of an accused who is immune from further direct punishment justify deprivation of the accused's liberty?
We can conceive of a number of instances in which the state would have some legitimate interest in determining the guilt or innocence of an accused even though the accused, in effect, had already been punished. For example, a conviction would be required to enhance a sentence for a later offense (Pen. Code, § 667.5), to require registration as a sex offender (Pen. Code, § 290), or as a controlled substances offender (Health & Saf. Code, § 11590), to revoke a driver's license (Veh. Code, § 13350), or to prohibit ownership or possession of a concealable firearm (Pen. Code, § 12021). Where any one or more of these interests are present, it would be necessary to decide whether such interest or interests were of sufficient importance to permit the continued involuntary confinement, for a limited period, of an incompetent defendant for the purpose of treating the accused so that competency might be restored and the trial conducted.
In petitioner's case, however, none of the cited examples are applicable and we can perceive no substantial public interest to be served by the determination of his guilt or innocence now that he may no longer be required to serve any sentence. (See People v. Superior Court (Mowry), supra, 20 Cal. App.3d 684, 687; In re Pfeiffer, supra, 264 Cal. App.2d 470, *871 477-480.) His continued confinement therefore violates fundamental due process principles.
(5) Incompetency commitments may not be used as a pretext for preventive detention or to vex or harass the accused. While it is certainly unfair to subject an incompetent defendant to a criminal trial (see Pate v. Robinson (1966) 383 U.S. 375 [15 L.Ed.2d 815, 86 S.Ct. 836]; In re Dennis, 51 Cal.2d 666 [335 P.2d 657]), it is no less unfair to deprive the incompetent defendant of his liberty for a period in excess of the maximum sentence for the charged offense, without the benefit either of a trial on the issue of guilt, or of the commitment procedures applicable to the nondefendant mentally ill.
The impact of In re Moye, 22 Cal.3d 457 [149 Cal. Rptr. 491, 584 P.2d 1097], should be noted. In Moye, the Supreme Court compared two groups  mentally disordered sex offenders and those found not guilty by reason of insanity. These groups were found to be "similarly situated" for equal protection purposes because (1) both classes involve persons found to have committed criminal acts and (2) both groups are committed for treatment because their illness poses a danger to the community as evidenced by the criminal acts. (Moye, supra, at pp. 463-464.) Neither of these standards fit the incompetent defendant. If this initial question of being "similarly situated" is ignored, the problem comes up in another context. Different treatment may be justified by reference to a state interest. In Moye, the court could find no compelling interest in holding those not guilty by reason of insanity longer than mentally disordered sex offenders. However, in the case of the incompetent defendant the state may have a legitimate interest in obtaining a conviction, an interest not present in the case of either mentally disordered sex offenders or those found not guilty by reason of insanity. Thus, we conclude that Moye has no direct relevance to the instant case.[3]
We hasten to point out that our ruling does not necessarily mean that a defendant who has served a period of confinement equal to the maximum time applicable to the criminal offense need be released. As Moye points out, if the individual is dangerous to society, extended commitment procedures under the LPS Act are available and appear to constitute adequate protection against the premature release of dangerous persons to society.
*872 In the meantime, our petitioner has been released. This case is literally moot. However, each side has requested that we not resort to a mootness disposition because the case presents an issue of broad public interest "`capable of repetition but yet evading review.'" (In re William M., 3 Cal.3d 16, 23, fn. 14 [89 Cal. Rptr. 33, 473 P.2d 737].) Therefore, we have decided the issue even though the petitioner will not be directly affected by the ruling.
Petition denied.
McDaniel, J., and Morris, J., concurred.
NOTES
[1]  At this point we must indulge in an inference. The record is clear that he was in custody because of this particular criminal charge. Since there was no parole or probation hold, or custody on another matter, we infer that he was in custody because of indigency. The only other possibility that comes to mind is that he might choose not to make bail to avoid going home to a shrewish wife. This, we do not deem to be a reasonable inference.
[2]  When the maximum period of confinement is reached and the incompetent is returned to the committing court, subdivision (d) of Penal Code section 1370 provides that the criminal action "remains subject to dismissal pursuant to Section 1385." While the statute does not explicitly require dismissal when the incompetency commitment has expired and the accused has already been confined for a period equal to the maximum sentence for the charged offense, it would be a rare case in which dismissal would not be granted. (See People v. Superior Court (Mowry) 20 Cal. App.3d 684, 687 [97 Cal. Rptr. 886]; In re Pfeiffer, 264 Cal. App.2d 470, 477-480 [70 Cal. Rptr. 831].) Thus for all practical purposes the expiration of the incompetency commitment is the end of the criminal proceeding.
[3]  However, one would be naive indeed to ignore Moye. If nothing else, it indicates the direction in which judicial winds are blowing.
