Web Interface For Lite Argus Control modules
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

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. /*
  3. * Use the host system's local time zone for all PHP date/time formatting.
  4. *
  5. * PHP does not follow the host time zone: without date.timezone in php.ini it uses UTC, so
  6. * report days, session and event times were shown in UTC instead of the local time that
  7. * la_mojo uses for report folders/files (data/reports/YYYY/MM/DD/report_HH.db).
  8. *
  9. * Source of the host zone, in order:
  10. * /etc/localtime symlink (what timedatectl set-timezone maintains), /etc/timezone, TZ variable.
  11. */
  12. function hostTimezoneName(){
  13. $Candidates = array();
  14. $L = @readlink( '/etc/localtime' );
  15. if( $L !== false && ( $P = strpos( $L, 'zoneinfo/' ) ) !== false ){
  16. $Candidates[] = substr( $L, $P + 9 );
  17. };
  18. $T = @file_get_contents( '/etc/timezone' );
  19. if( $T !== false ) $Candidates[] = trim( $T );
  20. $E = getenv( 'TZ' );
  21. if( $E !== false ) $Candidates[] = ltrim( trim( $E ), ':' );
  22. foreach( $Candidates as $C ){
  23. if( $C !== '' && in_array( $C, timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ) ) ) return $C;
  24. };
  25. return NULL;
  26. }
  27. $HOST_TZ = hostTimezoneName();
  28. if( $HOST_TZ !== NULL ) date_default_timezone_set( $HOST_TZ );
  29. ?>