$this->
config('system.date'
) ->
set('timezone.user.configurable', 0
) ->
set('timezone.default', NULL
) ->
save();
// Detect the system timezone.
$system_timezone =
date_default_timezone_get();
// Create a date object with an unspecified timezone, which should
// end up using the system timezone.
$date =
new DrupalDateTime($date_string);
$timezone =
$date->
getTimezone()->
getName();
$this->
assertSame($system_timezone,
$timezone, 'DrupalDateTime uses the system timezone when there is no site timezone.'
);
// Create a date object with a specified timezone.
$date =
new DrupalDateTime($date_string, 'America/Yellowknife'
);
$timezone =
$date->
getTimezone()->
getName();
$this->
assertSame('America/Yellowknife',
$timezone, 'DrupalDateTime uses the specified timezone if provided.'
);
// Set a site timezone.
$this->
config('system.date'
)->
set('timezone.default', 'Europe/Warsaw'
)->
save();
// Create a date object with an unspecified timezone, which should