0

I've been attaching Timeago script to my themes and it requires dates to be formatted like this.

<time class="timeago" datetime="2008-07-17T09:24:17Z">July 17, 2008</time>

In a view, I have one field set to rewrite as follows.

<time class="timeago" datetime="{{ Created_1 }}">{{ Created }}</time>

The previous version of the script made use of the Unix Epoch time format (U), but the most recent one available shifted to ISO:8601 (c). I found out today after updating the script that the view is converting the ISO dates within every time tag into double zeros (00).

The resulting html will be like this in both of the admin and site themes:

 <time class="timeago" datetime="00">

For some reason I can get the ISO date to print outside of the time tag but not within the datetime portion of the time tag.

How do I stop it from doing that?

My reasoning for using time ago is that it is more linguistically accurate than the format supplied by Drupal. For example, check the difference in formats between Arabic and English. Is something like this achievable solely through the translation interface? It would be nice to know if it is.

  • What do you mean by "double zeros"? Does this mean that the only text within the field is 00? Or that the time is zero-prefixed? Or that the microsends are all zeros? You should be as specific as possible about the output that you actually see. – mradcliffe Mar 14 at 12:38
  • 1
    The resulting html will be like this: <time class="timeago" datetime="00"> in both of the admin and site themes. For some reason I can get the ISO date to print outside of the time tag but not within the datetime portion of the time tag. – Jed_BH Mar 14 at 14:29
  • I think your datetime attribute value might got filtered, for example, by xss:filter or something like that during the rendering process, because of the punctuation (dash and colon). Especially you mentioned that it was working fine when it's a simple timestamp value. One workaround would be trying to see if you are able to do this in the views without rewriting this field. – cchen Mar 15 at 2:23
  • That might be it. I did some googling earlier and found this topic: Xss::filterAdmin() incorrectly filters time elements drupal.org/project/drupal/issues/2692451 What other ways are there to output a datetime field as a time tag? Do I have to come up with my own field plugin or twig filter? – Jed_BH Mar 15 at 16:24
  • 1
    In your formatter, instead of returning a '#markup', you can return a 'inline_template', this will keep it from getting filtered. See drupal.stackexchange.com/questions/184963/… for an example. – cchen Mar 26 at 14:42

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.