1

The DateTimeFormatterBase class is performing a ->setTimeZone incorrectly for my use case. How do I access the node values from where the $date passed to setTimeZone originated? Strange question I know, but I need to get to an entity reference field value to find the right time zone for the date.
Simple use case that I can't make work:
3 Fire Station nodes in Content Type FireHouses.
1 Content type Alarms with entity reference to FireHouses.
Station#, Address, City, Timezone
Station 1, 123 Main St, New York City, America/New_York
Station 1, 321 Any St, Chicago, America/Chicago
Station 1, 567 Hollywood, Los Angeles, America/Los_Angeles

Alarms come into all 3 stations at the same time (let's say just after midnight in New York) and Drupal sets Authored On field to same UTC time on all 3 Alarm nodes.

Views Report with Grouping by City:
New York:
Fire at 987 street, 2019/01/25 12:01 am
.
.
Chicago:
Medical Emergency, 2019/01/24 11:01 pm
.
.
Los Angeles:
Fire at 567 Hollywood, 2019/01/24 09:01 pm
.

This really simple use case/report fails because Drupal provides System Timezone, User Timezone, Field Display widget TZ (whole entity, not node level), Views TZ override and none apply here. 3 alarms, each in a different time zone but at the same time and I've found no way to override core functionality at the FormatterBase level because I can't traverse up (from $date) to the FireHouse entity level to get the correct TZ to provide to $date->setTimeZone function. Inside PHPStorm I can see the memory cache with node ids that I could use to get back to the FireHouse but I can't access them in code. My module must override core at this level so all displays of a date anywhere in the application are for the local time where the incident occurred.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.