adjust modified dates to the correct timezone

This commit is contained in:
Robin Appelman 2013-09-08 14:31:26 +02:00
commit f8bc64f097
4 changed files with 33 additions and 2 deletions

View file

@ -130,4 +130,12 @@ class Server {
return new Share($this, $name); return new Share($this, $name);
} }
} }
/**
* @return string
*/
public function getTimeZone() {
$command = 'net time zone -S ' . escapeshellarg($this->getHost());
return exec($command);
}
} }

View file

@ -24,6 +24,8 @@ class Share {
*/ */
private $connection; private $connection;
private $serverTimezone;
/** /**
* @param Server $server * @param Server $server
* @param string $name * @param string $name
@ -58,6 +60,13 @@ class Share {
return $this->parseOutput($output); return $this->parseOutput($output);
} }
private function getServerTimeZone() {
if (!$this->serverTimezone) {
$this->serverTimezone = $this->server->getTimeZone();
}
return $this->serverTimezone;
}
/** /**
* List the content of a remote folder * List the content of a remote folder
* *
@ -84,7 +93,7 @@ class Share {
$content[$name] = array( $content[$name] = array(
'size' => intval(trim($size)), 'size' => intval(trim($size)),
'type' => (strpos($type, 'D') !== false) ? 'dir' : 'file', 'type' => (strpos($type, 'D') !== false) ? 'dir' : 'file',
'time' => strtotime($time) 'time' => strtotime($time . ' ' . $this->getServerTimeZone())
); );
} }
} }

View file

@ -48,4 +48,9 @@ class Server extends \PHPUnit_Framework_TestCase {
$server = new \SMB\Server(uniqid(), $this->config->user, $this->config->password); $server = new \SMB\Server(uniqid(), $this->config->user, $this->config->password);
$server->listShares(); $server->listShares();
} }
public function testGetTimeZone() {
$timeZone = $this->server->getTimeZone();
$this->assertEquals('+0200', $timeZone);
}
} }

View file

@ -266,7 +266,16 @@ class Share extends \PHPUnit_Framework_TestCase {
/** /**
* @expectedException \SMB\NotFoundException * @expectedException \SMB\NotFoundException
*/ */
public function testRmDirNonExisting(){ public function testRmDirNonExisting() {
$this->share->rmdir('/foobar/asd'); $this->share->rmdir('/foobar/asd');
} }
public function testModifiedDate() {
$now = time();
$this->share->put($this->getTextFile(), $this->root . '/foo.txt');
$dir = $this->share->dir($this->root);
$mtime = $dir['foo.txt']['time'];
$this->assertTrue(abs($now - $mtime) <= 1, 'Modified time differs by ' . abs($now - $mtime) . ' seconds');
$this->share->del($this->root . '/foo.txt');
}
} }