The amount of time humanity would have would largely depend on the velocity of the earth after the slingshot and/or the time it takes for the slingshot to occur. The thing to keep in mind is the sun wasn't snuffed out, the earth is just moving further and further away from it. The sun will still provide light and heat just in lower and lower amounts as the distance the earth travels from its normal orbit increases. Think about how long it takes for a spacecraft to reach say the orbit of Mars from earth orbit. Some of the faster craft would take several months at closest approach, but if you are bearly hitting solar system escape velocity, it would take closer to a year. If you had a slow enough escape velocity you would have time to implement drastic plans to buy you even more time to build colony ships, underground or underwater cities, etc. For example, you could intentionally release as much greenhouse gasses as possible in the atmosphere to offset the cooling for a time by doing drastic things like burning all the forests on the planet (they were going to die anyway) or converting chemical plants into massive greenhouse gas emitters, etc. Also, there is the possibility that the slingshot would take the earth closer to the sun for a time before it passes the sun and continues on to escape the solar system. So you could have the opposite effect where the earth superheats for a while and then dies an icy death. Either way, you should have more than a few weeks if you assume the slingshot was not so powerful it killed all the people on the planet by its self.