Block filtering by current timezone and not UTC

Created on 17 February 2023, almost 2 years ago
Updated 7 April 2023, over 1 year ago

Problem/Motivation

The notifications are not showing as soon as they're created. This seems to be an issue with timezones.

Steps to reproduce

  • Create a new notification message entity, the admin shows 02/17/23 4:24:02 AM
  • This is actually saved in the database as UTC time, which is then 2023-02-17T11:24:02
  • The block creates a date with 'now', but no timezone specified. This will then default to site timezone. The current time will then be 02/17/23 4:24:02 AM, (or maybe a little later, matching the new entity with a delay)
  • The query then uses that date literally, with no conversion, and will not show the message because it's comparing 11am to 4am.

Proposed resolution

The now() function in the controller needs to specify UTC.

πŸ› Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States asherry

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

Comments & Activities

  • Issue created by @asherry
  • Status changed to Needs review almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States asherry
  • πŸ‡ΊπŸ‡ΈUnited States asherry

    error with my first patch, sorry

  • πŸ‡ΊπŸ‡ΈUnited States JCL324 Portland, OR

    @asherry, I actually found this bug back in October and fixed it as part of this issue: https://www.drupal.org/project/notification_message/issues/3315255 πŸ› Message won't dismiss Fixed . See my commit here: https://git.drupalcode.org/project/notification_message/-/merge_requests...

    Our code is very similar, I'm sure yours works fine, but know that my issue has already been RTBC by solideogloria and ready to be merged into dev. Maybe take a look at this patch and see if it works for you? https://git.drupalcode.org/project/notification_message/-/merge_requests...

  • Status changed to Closed: duplicate almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States asherry

    I see, thanks for letting me know. I had looked through the issue queue, your issue is still titled "Message won't dismiss". The change for the timezone fix wasn't dependent on the other commits so I would recommend having separated that out into another ticket. It's easier to QA for maintainers, and then it's easier to find for other people to use.

    I like the use of the interface for the STORAGE_TIMEZONE, you can actually simplify the statement even more to:

    $now = new DrupalDateTime('now', DateTimeItemInterface::STORAGE_TIMEZONE);
    

    The DrupalDateTime object actually already converts the timezone to an object.

  • πŸ‡ΊπŸ‡ΈUnited States JCL324 Portland, OR

    Sure, I'm kind of new at all this forking/issue stuff and have been finding all these little issues and bugs while trying to use this module on a site that's about to launch. I am up to 3 issues now and it's all getting really hard to manage, especially on my end. We really need the maintainers to chime in here and help corral all these changes and give feedback. Aren't they also at Aten like you?

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

    I'm sorry it's frustrating, I know how you feel. Things can move very slowly in the contrib world, we're all in the same boat. We give as much time as we can, especially when we're using it for a client's site.

    I appreciate your work and contributions. If making a patch would be easier than a pull request, that's still a very legitimate way to contribute.

    If you want to create one issue with all the bugs then that's also completely valid too. I just suggested making sure the title is up to date so that I know it's not a one-purpose issue.

  • πŸ‡ΊπŸ‡ΈUnited States JCL324 Portland, OR

    @asherry, sorry, just getting back to this, yes time gets away from us all! In reviewing my issue/patch for Message won't dismiss β†’ , I noticed in my writeup that I said I only changed 3 files so the snippet that was included about the time zone issue was probably just a hold over from me fixing something else. I totally agree that it shouldn't be in there, has nothing to do with fixing the dismissal issue. Once I have a chance to get back to this, I'll redo it and incorporate your patch here so no need to update the title :)

Production build 0.71.5 2024