Follow-up to #2429443: Date format form is unusable

Problem/Motivation

When trying to format a timestamp with timezone details, there is a unnecessary call to drupal_get_user_timezone().

Proposed resolution

Make drupal_get_user_timezone() only when necessary.

Remaining tasks

1. Patch
2. Test

User interface changes

N/A

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vijaycs85’s picture

Initial patch...

vijaycs85’s picture

Status: Active » Needs review
vijaycs85’s picture

FileSize
789 bytes

Much cleaner, as per @alexpott suggestion.

Status: Needs review » Needs work

The last submitted patch, 3: 2457251-unneccessary-timezone-call-3.patch, failed testing.

The last submitted patch, 1: 2457251-unneccessary-timezone-call-1.patch, failed testing.

Status: Needs work » Needs review
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

This looks great!

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

What test is this functionality covered by?

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

\Drupal\system\Tests\Datetime\DrupalDateTimeTest has

    // Create a date object with an unspecified timezone, which should
    // end up using the user timezone.
    $date = new DrupalDateTime($date_string);
    $timezone = $date->getTimezone()->getName();
    $this->assertTrue($timezone == 'Asia/Manila', 'DrupalDateTime uses the user timezone, if configurable timezones are used and it is set.');

Locally I commented out this bit and that assertion failed:

diff --git a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php
index ac22dab..54564b3 100644
--- a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php
+++ b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php
@@ -62,10 +62,12 @@ public function __construct($time = 'now', $timezone = NULL, $settings = array()
    * knowledge of the preferred user timezone.
    */
   protected function prepareTimezone($timezone) {
+    /*
     $user_timezone = drupal_get_user_timezone();
     if (empty($timezone) && !empty($user_timezone)) {
       $timezone = $user_timezone;
     }
+    //*/
     return parent::prepareTimezone($timezone);
   }
 

I would consider that sufficient, I don't think this optimization needs a whole unit test to back it.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

@tim.plunkett yep thanks for the sleuthing I just wanted to be sure it was covered - thanks!

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 47e418f and pushed to 8.0.x. Thanks!

  • alexpott committed 47e418f on 8.0.x
    Issue #2457251 by vijaycs85: Remove unnecessary call to...
vijaycs85’s picture

Yay! Thanks @alexpott and @tim.plunkett

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.