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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Can you specifiy the handlers you are talking about?
Is this really about fieldapi fields or about things like views_handler_filter_date?

ralf.strobel’s picture

Actually 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.

dawehner’s picture

I'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?

ralf.strobel’s picture

Title: gmdate() option for date handlers » Option to override user time zone in date handlers

You 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.

Dmitriy.trt’s picture

Version: 7.x-3.0-rc1 » 7.x-3.x-dev
Status: Active » Needs review
FileSize
3.02 KB

Patch adds timezone selection to date field handler. Site/user timezone is used by default.

tim.plunkett’s picture

Status: Needs review » Needs work
+++ b/handlers/views_handler_field_date.incundefined
@@ -50,6 +51,14 @@ class views_handler_field_date extends views_handler_field {
+      '#default_value' => isset($this->options['timezone']) ? $this->options['timezone'] : '',

This ternary isn't necessary because you set the default in option_definition. Just make it '#default_value' => $this->options['timezone'],

+++ b/handlers/views_handler_field_date.incundefined
@@ -62,6 +71,7 @@ class views_handler_field_date extends views_handler_field {
+      $timezone = empty($this->options['timezone']) ? NULL : $this->options['timezone'];

This ternary is technically necessary, I believe, but switch it to !empty so the NULL is last.

Dmitriy.trt’s picture

FileSize
2.98 KB

Fixed issues mentioned above.

Dmitriy.trt’s picture

Status: Needs work » Needs review
dawehner’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

It would be cool to have some kind of testing for this feature. There is already quite some code in views_handler_field_date.test

Dmitriy.trt’s picture

Status: Needs work » Needs review
FileSize
5.94 KB

Updated patch with the date field test modified to check timezone too.

dawehner’s picture

Version: 7.x-3.x-dev » 8.x-3.x-dev
Component: fieldapi data » Code
Status: Needs review » Patch (to be ported)

Awesome, tests and clean code, let's get it in.

As a lot of things changed i assume the patch needs a backport.

tim.plunkett’s picture

Status: Patch (to be ported) » Needs review
FileSize
5.1 KB

Ported.

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

same

dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Awesome!

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