Timezone is applied incorrectly to min and max values

Created on 8 February 2024, 4 months ago
Updated 22 February 2024, 4 months ago

Problem/Motivation

In the filter that does the between calculation, SmartDate forces the site's timezone onto whatever value['min'] and value['max'] have even if they aren't in that timezone.

Steps to reproduce

1. Set the site's timezone to PST.
2. Pass a UTC min and max value to the smart date filter.
The filter treats the times as if they are PST rather than UTC.

Proposed resolution

The problem is here: docroot/modules/contrib/smart_date/src/Plugin/views/filter/Date.php

  /**
   * Override parent method, which deals with dates as integers.
   */
  protected function opBetween($field) {
    $timezone = $this->getTimezone();
    $granularity = $this->options['value']['granularity'];

    // Convert value to DateTimePlus for additional processing.
    $a = new DateTimePlus($this->value['min'], new \DateTimeZone($timezone));
    $b = new DateTimePlus($this->value['max'], new \DateTimeZone($timezone));
    // Granularity requires some conversion.

The between filter should respect the timezone of the min and max values that are passed in.

🐛 Bug report
Status

Needs review

Version

4.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024