I have an interesting challenge surrounding Views Rewrite Result using Twig for Date/Time Range.

So I have a View listing Events that have a Date/Times Range field for Begin and End Times (it's actually a little more complex than that, but I hope the problem can be resolved with this easier example).

The content editor user enters a bunch of Events. The events display to the public within a View I wrote.

I used 'Rewrite Result' - 'Override the output of this field with custom text' for this field along with extensive use of Twig. (I am really not asking for another 'work-around' solution not using Rewrite and Twig... even if there is one, I am interested in the challenge at hand.)

So with Twig I output the Date, then The Begin Time and the End Time. Works Great. Of course, using various expressions of the Twig equivalent to the php date() function:

{{ EventDateTimeRange|date("g:i a") }}

So for an Event that takes place on September 21, 2018 from 1:30pm to 5:00pm it displays:

Fri Sep 21 1:30 pm • 5:00 pm

The challenge presents when you look a couple months later! For an Event that takes place on November 8, 2018 from 1:30pm to 5:00pm it displays:

Thu Nov 8 2:30 pm • 6:00 pm

OK, in one sense, this is exactly what one would want: The actual time is the actual time, and time entered for November 8th as 1:30 pm to 5:00 pm is properly expressed currently as 2:30 pm to 6:00 pm, and then will read as normal after DST.

However: Users deciding whether to attend will want to know what time it will be on November 8, 2018 and not the proper rendering of the Non-DST expression before DST.

As I mention above, I am NOT looking for a workaround, such as another field holding a String Description, or one field for the Date and another field for the Time. I want this as Data, an actual Date/Time Range. Then I want to manipulate that core, accurate, and flexible data to express to the end user the information that they need to make a decision about whether to attend.

I am tempted to meander about this problem, but since I feel so flummoxed -- I understand both sides and don't know how to resolve the discrepancy -- I am going to resist and hope that better minds can assist.

BTW, this is a D8 site, and New York time zone if it matters.

  • Did you ever find a solution to this problem? – Travis Aug 9 at 17:23

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.