blob: f1d2c38f634ed8ecb388c578487b0397650fe10f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
<?php
/**
* SPDX-FileCopyrightText: 2015 Robin Appelman <robin@icewind.nl>
* SPDX-License-Identifier: MIT
*/
namespace Icewind\SMB;
class TimeZoneProvider implements ITimeZoneProvider {
/**
* @var string[]
*/
private $timeZones = [];
/**
* @var ISystem
*/
private $system;
/**
* @param ISystem $system
*/
public function __construct(ISystem $system) {
$this->system = $system;
}
public function get(string $host): string {
if (!isset($this->timeZones[$host])) {
$timeZone = null;
$net = $this->system->getNetPath();
// for local domain names we can assume same timezone
if ($net && $host && strpos($host, '.') !== false) {
$command = sprintf(
'%s time zone -S %s',
$net,
escapeshellarg($host)
);
$timeZone = exec($command);
}
if (!$timeZone) {
$date = $this->system->getDatePath();
if ($date) {
$timeZone = exec($date . " +%z");
} else {
$timeZone = date_default_timezone_get();
}
}
$this->timeZones[$host] = $timeZone;
}
return $this->timeZones[$host];
}
}
|