It's all about table dynamics for me.
Mind you, I now play almost exclusively live, but even when I played online, it was always about the table dynamics, barring of course irl obligations where I had to leave because I had to go do something.
I think it's a BIG mistake and a common one players make to leave based on money won/lost. I think in general, it's perfectly OK to set a time limit - say you are going to play X number of hours and then quit no matter what, and to some degree, I do that live. I go to a casino, plan on playing 7-8 hours, and then go home, whether I'm up or down. What this does is teaches me discipline, and stops me from either chasing losses or another mistake a lot of players make, leaving when they are up a certain amount of money when the table dictates that you could make so much more.
But even after my 7-8 hour sessions, if the table is just too juicy for me to pass up, and I of course don't have any forthcoming obligations in life, I'll of course stay on more hours if I think I can be profitable doing so.