Optimized a bit.

This commit is contained in:
Loïc Chapeaux
2002-03-30 08:24:04 +00:00
parent 68cc8f059f
commit d1e484b312

View File

@@ -53,46 +53,29 @@ class zipfile
/** /**
* Converts the date y/n/d and time h:m:s to a four byte DOS date and time * Converts an Unix timestamp to a four byte DOS date and time format (date
* format (date in high two bytes, time in low two bytes allowing magnitude * in high two bytes, time in low two bytes allowing magnitude comparison).
* comparison).
* *
* @param integer the current year * @param integer the current Unix timestamp
* @param integer the current month
* @param integer the current day
* @param integer the current hour
* @param integer the current minut
* @param integer the current second
* *
* @return integer the current date in a four byte DOS format * @return integer the current date in a four byte DOS format
* *
* @access public * @access private
*/
function dosTime($year, $month, $day, $hour, $minute, $second) {
return ($year < 1980)
? dosTime(1980, 1, 1, 0, 0, 0)
: (($year - 1980) << 25) | ($month << 21) | ($day << 16) |
($hour << 11) | ($minute << 5) | ($second >> 1);
} // end of the 'dosTime()' method
/**
* Returns the Unix time $unixtime in DOS format, rounded up to the next
* two second boundary.
*
* @param integer the current timestamp
*
* @return integer the current date in a four byte DOS format
*
* @access public
*
* @see DOSTime()
*/ */
function unix2DosTime($unixtime = 0) { function unix2DosTime($unixtime = 0) {
$timearray = ($unixtime == 0) ? getdate() : getdate($unixtime); $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
return $this->dosTime($timearray['year'], $timearray['mon'], $timearray['mday'], if ($timearray['year'] < 1980) {
$timearray['hours'], $timearray['minutes'], $timearray['seconds']); $timearray['year'] = 1980;
$timearray['mon'] = 1;
$timearray['mday'] = 1;
$timearray['hours'] = 0;
$timearray['minutes'] = 0;
$timearray['seconds'] = 0;
} // end if
return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
} // end of the 'unix2DosTime()' method } // end of the 'unix2DosTime()' method
@@ -109,7 +92,7 @@ class zipfile
{ {
$name = str_replace('\\', '/', $name); $name = str_replace('\\', '/', $name);
$dtime = dechex ($this->unix2DosTime($time)); $dtime = dechex($this->unix2DosTime($time));
$hexdtime = '\x' . $dtime[6] . $dtime[7] $hexdtime = '\x' . $dtime[6] . $dtime[7]
. '\x' . $dtime[4] . $dtime[5] . '\x' . $dtime[4] . $dtime[5]
. '\x' . $dtime[2] . $dtime[3] . '\x' . $dtime[2] . $dtime[3]