Things get confusing really fast when bitcoin code is taken, modified, and the names of important items (methods, pointers, functions, etc. etc.) aren't changed.
I agree figuring out what the code does can be difficult. I've been analyzing it for almost a year, since I was made aware of it's flaws.
Perhaps it would make more sense if I mentioned method's signature:
unsigned int static GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake)
Second input parameter also determines block type on which
pIndexPrev and
pIndexPrevPrev point. When you generate nBits for PoW block, you pass
false.
pIndexPrev then points to PoW block as does
pIndexPrevPrev.
That is why I've written:
The same principle is used for PoS blocks. Just replace all occurences of PoW with PoS in text above.
That really means: "Just pass
true for
fProofOfStake"

...But isn't time counted (on the average) from the moment of the PoS block acceptance?...
Time is taken into account later in the same function. First
nTargetSpacing is calculated. Then
real time difference is
thrown into equation. If those two blocks pointed by
pIndexPrev and
pIndexPrevPrev are less than
nTargetSpacing apart, difficulty is raised (nBits get's lowered).
I have no idea what that means (LOL). Correct score? Trust calculation? What and where are those items?
Chaintrust is what I had in mind. It's
all over there.