Computing times with mktime()

Thread Starter

dor

Joined Feb 20, 2009
63
Does the mktime() library function adds an offset of 10 days to the output value?
I tried to implement a mktime() function myself, but noticed the lack of 10 days from the output value.
So, if I convert a (time_t) 1234567890 value to a (struct tm) and later converts it back (with my pseudo mktime() function) to a (time_t), the result is 1233703890 ( = 1234567890 - 10*24*60*60 )

Thank you.
 

Thread Starter

dor

Joined Feb 20, 2009
63
This problem was caused by the leap years.
From 1970 until now, there were 10 leap years. The following PHP script shows that:

Rich (BB code):
header('content-type: text/plain; charset=ASCII');
for($i=1970, $cnt=0; $i<2010; ++$i) {
    if ( !( !($i%4) && $i%100 || !($i%400) ) ) continue;
    echo $i, PHP_EOL;    ++$cnt;
}
echo PHP_EOL, 'Total leap years: ', $cnt;
Output:
Rich (BB code):
1972
1976
1980
1984
1988
1992
1996
2000
2004
2008

Total leap years: 10
 
Top