〜とき
When…, at the time of… (time clause)machine translation
FormationPlain form + とき / Noun + の + とき / な-adjective + な + とき
とき means "when, the time of." Put a clause in plain form (or a noun + の, or an adjective) before とき and you get a "when…" clause: 日本へ行くとき (when going to Japan), 子どものとき (when I was a child), 暇なとき (when I'm free). At its core, this is a clause modifying the noun とき — the same mechanism as the noun-modification pattern you've already learned.
The most important point is the form of the verb before とき: the る-form means THAT action was not yet finished when the main action happened; the た-form means it was finished. Compare: 日本へ行くとき、かばんを買いました — bought the bag before going (while still at home); 日本へ行ったとき、お寺を見ました — saw the temples after having arrived in Japan.
The form of the verb before とき is independent of the tense at the end of the sentence — look at the before/after relationship between the two actions; don't translate mechanically from the ます/ました ending.
Examples
日本へ行くとき、新しいかばんを買いました。
When I was about to go to Japan, I bought a new bag.
日本へ行ったとき、京都のお寺を見ました。
When I went to Japan, I saw the temples in Kyoto.
子どものとき、よく川で泳ぎました。
When I was a child, I often swam in the river.