If I understand correctly, you were in jail pending trial since 10/6/07. I would guess that the trial was about to commence or already had commenced when you agreed to the two misdemeanors. I'm not going to speculate why the trial was so delayed. Because any sentence of probation or any sentence over 90 days requires a Pre-Sentence Investigation (PSI), you were not sentenced immediately upon plea. But once you were sentenced to the 2 consecutive years and sent back to jail, your time was computed and you were released.
Yes, you had already done more than the maximum on the 2 year sentence. However, until the time you plead, you were facing a lot more time than that on prison sentences.
You got a break. You did not get any felonies. The sentence is legal. The only question in my mind is why you were not released on 1/19/10 at the time you pled, with directions to return for sentencing, as you had already served the maximum time. There may have been reasons, possibly even stated on the record. It seems that the PSI was expedited in order to get you out as soon as possible.
I do not know if there is a substantial basis for a lawsuit for those possibly extra two weeks in jail. You could talk to some civil rights attorneys to find out if any would be willing to take such a case. They would need to be able to sue for more than a certain amount of money to make it worth their while to take the case.
DISCLAIMER: This answer to a short simplified question is provided solely for general informational purposes only and is not intended to provide the specific legal advice you might need to decide your future actions. It is intended to provide you, and others with similar issues, a general, common-sense idea of the situation. Please consult with a local attorney to evaluate your particular case in the depth it deserves. This answer does not constitute legal advice, create an attorney-client relationship, or constitute attorney advertising.
Since I suspect that the potential maximum sentences that you could have received were greater than two one-year consecutive terms I do not believe that you would have a cause of action against the state, county or city of New York. It just happens that your case was resolved with a plea and sentencing agreement that resulted in being sentence to a total term of years that was slightly less than the credit you had accumulated.