Entirely at your current PD's whim first of all.
Then the second PD's whim 2nd of all.
The more interesting question is, if you are promoted to 2nd yr by the current PD, and leave, does that mean they have to forever and always sign off that first year?
(Although OP, you should know that even having an entire year signed off could still be counted as ZERO months in another program if it is a different specialty. Within the same specialty, the next PD is not likely to count a whole year signed off by the old PD as a big fat zero, but it is not a guaranteed 1 to 1 ratio. And you can certainly have to repeat rotations you already did.)
Residency must be treated as an all or nothing game. It is not college. There are no credits that transfer in that sense.
Sure, in this all or nothing game people walk away and go somewhere else and it isn't always A TOTAL loss, but it is always AT a loss. Get it?
Assume if you don't finish the year you get NOTHING but a shiv in the kidney. Assume if you finish the year AND transfer under the sweetest of sweetheart deals that you will be extending the length of your training at best.
Got it?
Sorry, I'm not trying to be mean, it is the bitterest of pills, and I know that I don't have to convince you that the system is complete insanity, you being an intern is proving that to you daily, but still, you must accept this harsh reality.
There are stories of people being cut month 11 and PD signs off on nada.
Your current PD is basically the closest to your life's personal buddha jesus hitler god figure of existence, an avalanche waiting to bury you, your only source of career redemption.
One of my past posts on resident resignation/dismissal/termination goes into exquisite detail the ways that you and current and former PDs interact.