With regards to this thread, I've developed a partial solution:
function strtosecs($time,$now=null){
static $LEAPDIFF=86400;
$time=strtotime($time,$now);
return $time-(round((date('Y',$time)-1968)/4)*$LEAPDIFF);
}
The function is supposed to get the number of seconds given a string without checking leap-years.
It does this calculating the number of leap-years 1970 [(year-1986)/4], multiplying it by the difference in seconds between a leap-year and a normal year (which in the end, it's just the number of seconds in a day).
Finally, I simply remove all those excess leap-year seconds from the calculated time. Here's some examples of the inputs/outputs:
// test code
echo strtosecs('+20 years',0).'=>'.(strtosecs('+20 years',0)/31536000);
echo strtosecs('+1 years',0).'=>'.(strtosecs('+1 years',0)/31536000);
// test output
630676800 => 19.998630136986
31471200 => 0.99794520547945
You will probably ask why am I doing a division on the output? It's to test it out; 31536000 is the number of seconds in a year, so that 19.99... should be 20 and 0.99... should be a 1. Sure, I could round it all and get "correct" answer, but I'm worried about the inaccuracies.
Edit1: Since it doesn't seem obvious, my problem is with inveteracies; you just don't ask PHP for 20 years and it gives you 19.99..., right?
Edit2: It all seems to boil down to the part about 1968;
- 1970; found it accurate in all tests I've tried.
- 1969; Found it used here (
...ex: (2008-1969)/4 = 9.75...
) as well as mentioned here. Accurate after the 2nd year (+3 years) onwards. - 1968; as detailed below, this is "year zero" of leap years from unix time (1970). It sounds "right" (to me) but it isn't accurate, at all.