Not the "right" answer, but the rude as fuck and honest answer that I'd give:

It's Friday, a feature you're working on is due on Monday and all you have is some spaghetti code and that academic paper you don't understand. What do you do?

First, if the writer of the spaghetti code is still with the company, I go over and ask him (politely; maybe this was his deadline code) to explain why he wrote his code in such a way. (Maybe there's a good reason for it and the problem isn't bad code but a lack of understanding on my end.) I let him know that I'm going to have to spend an entire weekend on a critical feature and ask him to make himself available, if not work with me, while we figure this out. Involving him will radically improve my chances of success at meeting the deadline.

I've had enough experience to know that even with great people making solid efforts, most deadlines slip. It's not like school where deadlines are exceedingly well-tested and failing one is usually a reflection on the student, not the situation. Just out of professional responsibility, I have to let my boss know that I may not be able to succeed by Monday.

I may not do it, but it's my job to work as hard as I can. That said, the most important thing is bringing in the developer who wrote the original "spaghetti code". Working alone, it's more likely than not that, even with great effort, I'll fail it: new features are always more complicated than they look. If I can involve the writer of the "spaghetti code" in my weekend rush, that's a huge benefit and I just might make it.

It's possible that the writer of the code is gone. This is scarier. If the guy was fired, then I congratulate the trigger-puller on her good sense, but I ask why we're still using terrible code of someone who was fired. If it'll take me less than 6 hours to replace it, I do. I'll make that time up over the weekend because dealing with shitty code is exhausting and infuriating and will cost me more than that.

If the code is so terrible, I tell the manager that this code really needs to be replaced and that it is a very high priority because it's necessary for a critical feature and an unmaintainable mess. If I get the feeling that she doesn't care about source quality, I GTFO of the company.

In terms of how I manage my own time, I work till 10 on Friday night, get a good night's sleep, work out at 7 and start working at 8. The morning (8 - 12) I spend reading the paper and the code (when I'm sharpest, because reading code is harder than writing) and the afternoon (2 - 10) I spend writing. No all-nighter on Friday or Saturday because that's fucking stupid-- you pay for it the next day, and productivity in a double-all-nighter is negative. All-nighter on Sunday if needed. Take Monday off, except possibly to verify that the feature worked, if I work past 10:00pm on Sunday.

If we're established enough that "vacation days" exist in a limited allotment and bad things happen to you if you take more, I better get 2 vacation days for the weekend I worked or I am fucking quitting. I don't mind working weekends but I won't be taken advantage of.

I also mandate that I'll be allowed to spend Tuesday and Wednesday cleaning up my shitty code that I produced to meet the deadline. I'm very good, but my deadline code stinks as much as anyone else's.

Finally, I ask why the feature was "due" on Monday. Who made this promise, and why? Can we stop making unrealistic promises to clients and focus on delivering what we understand, well? Weekend heroics are occasionally necessary, but if they become a common occurrence and management starts requiring or relying on them, that's a bad sign. There are a lot of companies (some startups, some not) that exist to take advantage of dumb young people who don't know their rights but I am 27 and far too old for that shit.

Maybe I make the deadline and maybe I don't. Maybe I even get fired when I tell the management not to make unrealistic promises to clients anymore. Most often it's unintentional when things like this happen, but there is a really fucking parasitic (I don't put it this way; I'm not that rude) anti-pattern you sometimes see where client-relations guy makes unrealistic promises and becomes a star while inflicting suffering (impossible deadlines, perpetual crunch) on technical people. You know how unskilled programmers always inline because "it makes the code go faster"? Unskilled managers always create "crunch" or "urgent" conditions because "it makes people work harder". Client-facing people who make unrealistic promises are the enablers of those shitty managers.

If that particular anti-pattern is in place: in a startup, I leave if I can't get the CR guy out because he'll bleed talent and the startup has no future because its clients don't respect it. In a mid-size company, I try to get the parasite plucked out-- but am most likely to fail; the fact that he's in client relations means he has better social skills than I do. Still, it's always worth a try to make a company better, no?

"He's single" but I'm guessing half of my readers can see why. New York based.