UTC timezone causes PHP Warnings

Created on 31 January 2023, almost 2 years ago
Updated 4 May 2024, 7 months ago

Problem/Motivation

I'm getting a bunch of PHP warnings relating to the new ViewsIcalHelper->AddTimezone() method. I'm not sure what the purpose of various parts of the code are but the problem is that the code expects there to be more than one item in the $transitions array. I have a fairly vanilla set up using date_recur module and that array only has a single entry.

Proposed resolution

If it is correct to only have one transition sometimes then code like this needs to be wrapped in an isset check

$prevTransition = $transitions[$midpoint-1];
...
$vTimezoneRule->setTzOffsetFrom($this->convertOffset($prevTransition['offset']));

However, if there should always be more than one transition, I guess there is a problem with this bit:

    $secondsInYear = 18410000;
    $transitions = $timezone->getTransitions(
      // Subtract two years (probably only need 18 months, just to be sure we include all of the previous transition, so we can start THIS one at the right time)
      $datetime->getTimestamp() - $secondsInYear - $secondsInYear - $secondsInYear,
      $datetime->getTimestamp() + $secondsInYear) ;

This comment makes me wonder if the problem could be avoided by ditching the binary search and tweaking that second bit of code above?

// binary search was written before realizing that getTransitions() could be passed arguments... Just kept it though.
πŸ› Bug report
Status

Needs review

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom very_random_man

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

Comments & Activities

  • Issue created by @very_random_man
  • πŸ‡¬πŸ‡§United Kingdom very_random_man

    On further reflection after having a look at what this actually does and a bit of RTFM, I think the issue is that it is getting foxed by the UTC timezone which has no Daylight Savings Time so it legitimately only has one entry in the transitions array.

  • πŸ‡ΊπŸ‡ΈUnited States joshuasosa

    I'm getting same thing on 8.x-1.0-alpha12. Lots of warnings blowing up the logs to hundreds of pages. This site is for AZ, US which has no time zone change throughout the year.

    Warning: Undefined array key -1 in Drupal\views_ical\ViewsIcalHelper->addTimezone() (line 380 of /drupal/web/modules/contrib/views_ical/src/ViewsIcalHelper.php)

    Warning: Trying to access array offset on value of type null in Drupal\views_ical\ViewsIcalHelper->addTimezone() (line 427 of /drupal/web/modules/contrib/views_ical/src/ViewsIcalHelper.php)

    Warning: Trying to access array offset on value of type null in Drupal\views_ical\ViewsIcalHelper->addTimezone() (line 435 of /drupal/web/modules/contrib/views_ical/src/ViewsIcalHelper.php)

    Warning: Undefined array key -1 in Drupal\views_ical\ViewsIcalHelper->addTimezone() (line 434 of /drupal/web/modules/contrib/views_ical/src/ViewsIcalHelper.php)

    Warning: Undefined array key "timezone_override" in Drupal\views_ical\Plugin\views\row\IcalFieldsWizard->render() (line 88 of /drupal/web/modules/contrib/views_ical/src/Plugin/views/row/IcalFieldsWizard.php)

  • πŸ‡ΊπŸ‡ΈUnited States joshuasosa

    Attached is a temporary patch against -dev just to suppress the warnings. It'd probably be better to properly handle them, but at least my logs won't keep blowing up for now.

  • Status changed to Needs review 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States bburg Washington D.C.

    I took a swing at properly checking values and using some null coalescing operators. Please test and confirm.

    Apply to the "8.x-1.x" branch. not the "-dev" one. Which seems to erroneously be listed as the default dev branch on the module page.

  • πŸ‡ΊπŸ‡ΈUnited States joshuasosa

    Testing the patch in #6 gives these warnings:

    Warning: Undefined array key "timezone_override" in Drupal\views_ical\Plugin\views\row\IcalFieldsWizard->render() (line 88 of /web/modules/contrib/views_ical/src/Plugin/views/row/IcalFieldsWizard.php)
    #0 /web/core/includes/bootstrap.inc(164): _drupal_error_handler_real()
    #1 /web/modules/contrib/views_ical/src/Plugin/views/row/IcalFieldsWizard.php(88): _drupal_error_handler()
    #2 /web/core/modules/views/src/Plugin/views/style/StylePluginBase.php(504): Drupal\views_ical\Plugin\views\row\IcalFieldsWizard->render()
    #3 /web/core/modules/views/src/Plugin/views/style/StylePluginBase.php(464): Drupal\views\Plugin\views\style\StylePluginBase->renderGroupingSets()
    #4 /web/modules/contrib/views_ical/src/Plugin/views/style/IcalWizard.php(250): Drupal\views\Plugin\views\style\StylePluginBase->render()
    #5 /web/core/modules/views/src/Plugin/views/display/Feed.php(190): Drupal\views_ical\Plugin\views\style\IcalWizard->render()
    #6 /web/core/modules/views/src/ViewExecutable.php(1548): Drupal\views\Plugin\views\display\Feed->render()
    #7 /web/core/modules/views/src/Plugin/views/display/Feed.php(173): Drupal\views\ViewExecutable->render()
    #8 /web/core/modules/views/src/ViewExecutable.php(1677): Drupal\views\Plugin\views\display\Feed->preview()
    #9 /web/core/modules/views_ui/src/ViewUI.php(612): Drupal\views\ViewExecutable->preview()
    #10 /web/core/modules/views_ui/src/ViewPreviewForm.php(62): Drupal\views_ui\ViewUI->renderPreview()
    #11 /web/core/lib/Drupal/Core/Entity/EntityForm.php(107): Drupal\views_ui\ViewPreviewForm->form()
    #12 /web/core/modules/views_ui/src/ViewFormBase.php(41): Drupal\Core\Entity\EntityForm->buildForm()
    #13 [internal function]: Drupal\views_ui\ViewFormBase->buildForm()
    #14 /web/core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array()
    #15 /web/core/lib/Drupal/Core/Form/FormBuilder.php(375): Drupal\Core\Form\FormBuilder->retrieveForm()
    #16 /web/core/lib/Drupal/Core/Form/FormBuilder.php(633): Drupal\Core\Form\FormBuilder->rebuildForm()
    #17 /web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm()
    #18 /web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
    #19 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
    #20 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
    #21 /web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #22 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
    #23 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
    #24 /vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #25 /vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
    #26 /web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
    #27 /web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
    #28 /web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
    #29 /web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
    #30 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
    #31 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
    #32 /web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
    #33 /web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
    #34 /web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
    #35 /web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
    #36 /web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
    #37 /web/index.php(19): Drupal\Core\DrupalKernel->handle()
    #38 {main}

Production build 0.71.5 2024