ている/ていた時 understanding


I understand how 時 works with plain present/plain past (e.g. 食べる/食べた時) but I'm
a little unsure of ている/ていた時.

Also what's the difference between these two sentences:

> 私がお風呂に入っ **ている時** 電話が鳴った。
>
> 私がお風呂に入っ **ていた時** 電話が鳴った。

In a textbook apparently they both translate as "When I was taking a bath, the
telephone rang." But I don't understand why.

If someone could please explain this for me I'd really appreciate it! (I hope
it's not too broad a question.)

