You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.1 KiB
30 lines
1.1 KiB
<?php
|
|
/*
|
|
* Use the host system's local time zone for all PHP date/time formatting.
|
|
*
|
|
* PHP does not follow the host time zone: without date.timezone in php.ini it uses UTC, so
|
|
* report days, session and event times were shown in UTC instead of the local time that
|
|
* la_mojo uses for report folders/files (data/reports/YYYY/MM/DD/report_HH.db).
|
|
*
|
|
* Source of the host zone, in order:
|
|
* /etc/localtime symlink (what timedatectl set-timezone maintains), /etc/timezone, TZ variable.
|
|
*/
|
|
function hostTimezoneName(){
|
|
$Candidates = array();
|
|
$L = @readlink( '/etc/localtime' );
|
|
if( $L !== false && ( $P = strpos( $L, 'zoneinfo/' ) ) !== false ){
|
|
$Candidates[] = substr( $L, $P + 9 );
|
|
};
|
|
$T = @file_get_contents( '/etc/timezone' );
|
|
if( $T !== false ) $Candidates[] = trim( $T );
|
|
$E = getenv( 'TZ' );
|
|
if( $E !== false ) $Candidates[] = ltrim( trim( $E ), ':' );
|
|
foreach( $Candidates as $C ){
|
|
if( $C !== '' && in_array( $C, timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ) ) ) return $C;
|
|
};
|
|
return NULL;
|
|
}
|
|
|
|
$HOST_TZ = hostTimezoneName();
|
|
if( $HOST_TZ !== NULL ) date_default_timezone_set( $HOST_TZ );
|
|
?>
|