View Single Post
Old 11-17-2012, 02:13 AM   PM User | #15
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
OH MAN! I *DO* apologize!

I actually had *NOT* seen your post from today!

I had looked at the thread earlier in the day and realized I had a typo in the code I showed you. So I fixed it and then checked to make sure it worked.

And then I got to thinking about the problem and realized that the hard part was that, as I had mentioned, you need a zero-based number of days when dividing by years but you want a 1-based number of days for the days in months. That's when I hit on doing
Code:
    var quads = Math.floor( (nDays-1) / 1461 ); // 1461 days in 4 years
    nDays -= quads * 1461;
It was more a matter of surrendering to my own stubborness than anything else.

Even AFTER I posted I didn't scroll up and see your post with the right answer!

PLEASE...it was just blindness and my own stubbornness at finally understanding the meat of the problem that drove me to write the code.

I have *STILL* not tested your answer. I am assuming it works and you have tested it.

And here I was so happy at myself for coming up with that "quads" trick.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
Durakken (11-17-2012)