Before Sarpeidon's sun went nova, its people escaped into their planet's history through the atavachron, and Kirk, Spock and McCoy were trapped in its past.
In 2269 the Enterprise reached Sarpeidon shortly before its star was due to explode. The only person left was the librarian Mr. Atoz, who had used a time-portal device called the atavachron to send the population into chosen periods of the planet's past. When the landing party entered, Kirk went to a period resembling 17th-century England, while Spock and McCoy were sent to an ice age about five thousand years earlier.
In the past Spock began acting as ancient Vulcans did, and he fell in love with Zarabeth, a woman exiled there. The three men found their way back to the library just before the star exploded.