Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Handlers should be able to use gmdate() instead of date(), if the user wishes so.
I'm having problems with a birth date database column stored as a GMT timestamp. Depending on the time zone the viewing user is located in, the displayed date often ends up being off by one day.
Comment | File | Size | Author |
---|---|---|---|
#12 | views-1273946-12.patch | 5.1 KB | tim.plunkett |
#10 | views-1273946-10.diff | 5.94 KB | Dmitriy.trt |
#7 | views-1273946-7.patch | 2.98 KB | Dmitriy.trt |
#5 | views-1273946-5.patch | 3.02 KB | Dmitriy.trt |
Comments
Comment #1
dawehnerCan you specifiy the handlers you are talking about?
Is this really about fieldapi fields or about things like views_handler_filter_date?
Comment #2
ralf.strobel CreditAttribution: ralf.strobel commentedActually all kinds of handlers. Most importantly views_handler_field_date, but also views_handler_sort_date, views_handler_filter_date and views_handler_argument_date.
If I'm in the wrong component, please correct.
Comment #3
dawehnerI'm not sure whether you actually looked into the files, but there just the core function format_date is used which should do everything here. It uses a date object so it is quite flexible and you shouldn't need gmdate, or?
Comment #4
ralf.strobel CreditAttribution: ralf.strobel commentedYou have a point. But in that case it only changes the method of my request...
format_date() has an argument $timezone, which defaults to the selected time zone of the user.
It is currently not passed at all by the handlers.
There should be a handler option to pass "GMT" instead - or maybe even more general a selector for an override time zone to use.
Comment #5
Dmitriy.trt CreditAttribution: Dmitriy.trt commentedPatch adds timezone selection to date field handler. Site/user timezone is used by default.
Comment #6
tim.plunkettThis ternary isn't necessary because you set the default in option_definition. Just make it
'#default_value' => $this->options['timezone'],
This ternary is technically necessary, I believe, but switch it to !empty so the NULL is last.
Comment #7
Dmitriy.trt CreditAttribution: Dmitriy.trt commentedFixed issues mentioned above.
Comment #8
Dmitriy.trt CreditAttribution: Dmitriy.trt commentedComment #9
dawehnerIt would be cool to have some kind of testing for this feature. There is already quite some code in views_handler_field_date.test
Comment #10
Dmitriy.trt CreditAttribution: Dmitriy.trt commentedUpdated patch with the date field test modified to check timezone too.
Comment #11
dawehnerAwesome, tests and clean code, let's get it in.
As a lot of things changed i assume the patch needs a backport.
Comment #12
tim.plunkettPorted.
Comment #13
aspilicious CreditAttribution: aspilicious commentedsame
Comment #14
dawehnerAwesome!