function bin2ddword($data) { $result = 0; for ($i = 7; $i >= 0; $i--) { $result *= 256; $result += ord($data[$i]); } return $result; } function tnef_getDate($size, &$buf) // timo: translated from ytnef.c { $startingdate = 0; $days_in_year = 365; $months = array(31,28,31,30,31,30,31,31,30,31,30,31); $data = tnef_getx($size, &$buf); $ddword_tmp = bin2ddword($data); $ddword_tmp = $ddword_tmp /10; // micro-s $ddword_tmp /= 1000; // ms $ddword_tmp /= 1000; // s $ddword_tmp = floor($ddword_tmp); $seconds = ($ddword_tmp - floor($ddword_tmp/60)* 60); $ddword_tmp /= 60; // seconds to minutes $ddword_tmp = floor($ddword_tmp); $minutes = ($ddword_tmp - floor($ddword_tmp/60)* 60); $ddword_tmp /= 60; //minutes to hours $ddword_tmp = floor($ddword_tmp); $hours = ($ddword_tmp % 24); $ddword_tmp /= 24; // Hours to days $ddword_tmp = floor($ddword_tmp); // Now calculate the year based on # of days $wYear = 1601; $startingdate = 1; while($ddword_tmp >= $days_in_year) { $ddword_tmp-=$days_in_year; $wYear++; $days_in_year = 365; $startingdate++; if (($wYear % 4) == 0) { if (($wYear % 100) == 0) { // if the year is 1700,1800,1900, etc, then it is only // a leap year if exactly divisible by 400, not 4. if (($wYear % 400) == 0) { $startingdate++; $days_in_year = 366; } } else { $startingdate++; $days_in_year = 366; } } $startingdate %= 7; } // the remaining number is the day # in this year // So now calculate the Month, & Day of month if (($wYear % 4) == 0) { // 29 days in february in a leap year $months[2] = 29; } $tmp_date = (int)$ddword_tmp; $wDayOfWeek = ($tmp_date + $startingdate) % 7; $wMonth = 0; while ($tmp_date > $months[$wMonth]) { $tmp_date -= $months[$wMonth]; $wMonth++; } $wMonth++; $wDay = $tmp_date+1; return mktime($hours, $minutes, $seconds, $wMonth, $wDay, $wYear); }