Merge remote-tracking branch 'origin/master'

This commit is contained in:
yefengeeeeeeeeeee 2026-07-11 16:51:39 +08:00
commit 048dfd2e98

View file

@ -39,34 +39,70 @@ function parseOffset(string $offset) : string|false{
if(ini_get("date.timezone") == ""){ //No Timezone set if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set("GMT"); date_default_timezone_set("GMT");
if(str_contains(" " . strtoupper(php_uname("s")), " WIN")){ if(str_contains(" " . strtoupper(php_uname("s")), " WIN")){ //windows
$keyPath = 'HKLM\\SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation';
$regex = '/(UTC)(\+*\-*\d*\d*\:*\d*\d*)/'; $timezone = 'UTC'; //default
/* /*
* wmic timezone get Caption * Get the timezone offset through the registry
* Get the timezone offset
* *
* Sample Output var_dump * Sample Output var_dump
* array(3) { * array(13) {
* [0] => * [0]=>
* string(7) "Caption" * string(0) ""
* [1] => * [1]=>
* string(20) "(UTC+09:30) Adelaide" * string(71) "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation"
* [2] => * [2]=>
* string(0) "" * string(35) " Bias REG_DWORD 0xfffffe20"
* } * [3]=>
* string(43) " DaylightBias REG_DWORD 0xffffffc4"
* [4]=>
* string(45) " DaylightName REG_SZ @tzres.dll,-571"
* [5]=>
* string(67) " DaylightStart REG_BINARY 00000000000000000000000000000000"
* [6]=>
* string(36) " StandardBias REG_DWORD 0x0"
* [7]=>
* string(45) " StandardName REG_SZ @tzres.dll,-572"
* [8]=>
* string(67) " StandardStart REG_BINARY 00000000000000000000000000000000"
* [9]=>
* string(52) " TimeZoneKeyName REG_SZ China Standard Time"
* [10]=>
* string(51) " DynamicDaylightTimeDisabled REG_DWORD 0x0"
* [11]=>
* string(45) " ActiveTimeBias REG_DWORD 0xfffffe20"
* [12]=>
* string(0) ""
* }
*/ */
exec("wmic timezone get Caption", $output); exec("reg query " . escapeshellarg($keyPath), $output);
$string = trim(implode("\n", $output)); foreach($output as $line){
if(preg_match('/ActiveTimeBias\s+REG_DWORD\s+0x([0-9a-fA-F]+)/', $line, $matches) > 0){
$offsetMinutes = ((int) hexdec(trim($matches[1]))) << 32 >> 32; //sign int
//Detect the Time Zone string if($offsetMinutes === 0){
preg_match($regex, $string, $matches); break; //UTC
}
if(!isset($matches[2]) or ($timezone = parseOffset($matches[2])) === false){ $sign = $offsetMinutes <= 0 ? '+' : '-'; //windows timezone + and - are opposite
$timezone = 'UTC'; $absMinutes = abs($offsetMinutes);
$hours = floor($absMinutes / 60);
$minutes = $absMinutes % 60;
$offset = sprintf(
"%s%02d:%02d",
$sign,
$hours,
$minutes
);
$timezone = parseOffset($offset);
break;
}
} }
if(date_default_timezone_set($timezone)){ if(date_default_timezone_set($timezone)){
ini_set("date.timezone", $timezone); ini_set("date.timezone", $timezone);
} }