Skip to content

Commit

Permalink
Improve timezone setting logic
Browse files Browse the repository at this point in the history
Previously, core.php tried to set the default timezone to the value
stored in global configuration, with error suppression. Due to [[1]],
this does not actually prevent the notice from appearing with PHP 8.

Refactored the code to get the system's default time zone if it is not
defined in configuration. A PHP notice is still thrown if the specified
timezone is not valid, as documented in the code.

Also, since PHP 5.4, date_default_timezone_get() no longer throws a
warning so the '@' operator is not needed anymore.

Fixes #27796

[1]: https://bugs.php.net/bug.php?id=80548
  • Loading branch information
dregad committed Dec 30, 2020
1 parent 2db996b commit de1679d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core.php
Expand Up @@ -269,9 +269,12 @@ function autoload_mantis( $p_class ) {
# Set the default timezone
# To reduce overhead, we assume that the timezone configuration is valid,
# i.e. it exists in timezone_identifiers_list(). If not, a PHP NOTICE will
# be raised. Use admin checks to validate configuration.
@date_default_timezone_set( config_get_global( 'default_timezone' ) );
$t_tz = @date_default_timezone_get();
# be raised and we fall back to the system's default timezone.
# Use admin checks to validate configuration.
$t_tz = config_get_global( 'default_timezone' );
if( empty( $t_tz ) || !date_default_timezone_set( $t_tz )) {
$t_tz = date_default_timezone_get();
}
config_set_global( 'default_timezone', $t_tz, true );

if( !defined( 'MANTIS_MAINTENANCE_MODE' ) ) {
Expand Down

0 comments on commit de1679d

Please sign in to comment.