We use Past Perfect Continuous when action started in the past, continued for some time, and finished before a point in time in the past.
1. Action started in the past
2. Action continued for a period of time
3. Action stopped before or by a point in time in the past
For a period of time in the past:
We can use for, since, all morning to show that an action was ongoing for a period of time.
She had been watching TV for 2 hours before he came.
They had been working since 2 pm, that’s why they looked so tired.
Up until a moment in the past:
We need to show that an action was ongoing up until something happened. Use before, when, by the time and their synonyms or synonymous expressions.
She had been watching TV for 2 hours before he came.
They had been working for 2 hours when she came.
Point in time in the past is:
another action (usually in Past Simple)
They had been working for 2 hours when she came.
event
They had been working for 2 days before his visit.
contextual time (not explicitly indicated, however, we can understand it from context)
They looked so tired. They had been working for 2 days. (= they had been working for 2 days before that moment when they looked tired)
Recap: Past Perfect Continuous
We use Past Perfect Continuous when an action started in the past, continued for some time, and normally, it was interrupted at a point in time in the past.
They had been living in the city for already 9 years when the war began.
Did they continue living in the city? It’s a topic of discussion. Many reputable sites say that an action continued for some time and was interrupted, or in other words, it stopped, can we understand it this way? Well, definitely a good living was interrupted, but did the action stop? It’s an interesting question.
Also on Past Perfect Continuous: