-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathutil.php
34 lines (29 loc) · 1.02 KB
/
util.php
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
<?php
// from http://php.net/manual/de/function.date-default-timezone-set.php#113864
function setTimezone($default) {
$timezone = "";
// On many systems (Mac, for instance) "/etc/localtime" is a symlink
// to the file with the timezone info
if (is_link("/etc/localtime")) {
// If it is, that file's name is actually the "Olsen" format timezone
$filename = readlink("/etc/localtime");
$pos = strpos($filename, "zoneinfo");
if ($pos) {
// When it is, it's in the "/usr/share/zoneinfo/" folder
$timezone = substr($filename, $pos + strlen("zoneinfo/"));
} else {
// If not, bail
$timezone = $default;
}
}
else {
// On other systems, like Ubuntu, there's file with the Olsen time
// right inside it.
$timezone = file_get_contents("/etc/timezone");
if (!strlen($timezone)) {
$timezone = $default;
}
}
date_default_timezone_set($timezone);
}
?>