Harry had the best morning he’d had in a long time. (Harry
Potter and the Sorcerer’s Stone)
The prefect tense above makes a range of which the best is selected out. So, in fact, he’d had in long time means ‘during a long period of time.’ Is this right understanding?
Not exactly. If we rewrite the sentence in a different way, it might be clearer:
It had been a long time since Harry’d had a morning this good.
In this case in a long time essentially means exactly that; it has been a long time since [x] last happened. (That is, a lot of time has passed since [x] last happened.) In this case, it has been a long time since Harry had a morning as good as this one.