Needs work
Project:
Drupal core
Version:
main
Component:
views.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
2 Feb 2024 at 09:32 UTC
Updated:
31 Jan 2025 at 10:28 UTC
Jump to comment: Most recent, Most recent file


Comments
Comment #2
akhil babuThanks for the detailed issue decsription. I tried to recreate this issue with the given view configuration in Drupal 10.2.2 & Drupal 11 versions and these are the observations.
If custom date format is selected and 'U' is given as the format, Timestamp value of the date appeares correctly in the response.


If another custom date format is used (Eg: m/d/Y), date gets correctly formated in the response.
So, the date appears in the configured format (I am not sure why it is enclosed within
<time>tags) in the REST export.Comment #3
lendudeFeels similar to #3383219: Views RSS Feed Fields adds <time> tag. and probably also caused by #2921810: Allow TimestampFormatter to show as a fully cacheable time difference with JS
Comment #5
rudolfbyker@Lendude those issues look similar, indeed, but they are marked as fixed, while I can still reproduce this issue by importing the attached `views.view.test.yml` file into a fresh Drupal 10.3.2 instance.
@akhil babu you are correct. With the latest Drupal version, the "Date format" is respected, but the whole thing is still wrapped in HTML. I'll update the title and description of this issue.
Partial workaround: Enable "Strip HTML tags" and "Remove whitespace" under "Rewrite results" when configuring the views field. The only problem is that it's still a string instead of an int when using "U" as the "Date format".
Comment #6
rudolfbykerComment #7
steven snedker commented@rudolfbyker has correctly identified a bug that should be squashed.
When exporting your nodes as json, you'd probably want to be able to easily export your dates in some easily machine-readable format.
For a project I'm currently working on
05.12.2024 - 17:11is WAY superior to
<time datetime="2024-12-05T17:11:05+01:00">05.12.2024 - 17:11</time>\nSilly workaround that works for me, but should only be temporary:
In the view, configuring the date fields: rewrite the result. Remove HTML tags and trim it to 18 characters (no ellipsis).
Another workaround:
Ask for "raw output" at Format - Fields - Config.
This will give you a timestamp, no HTML.
The correct solution:
Configuring the field, you should be able to set Formatter as "raw/no html markup"
Comment #10
niranjan_panem commentedRemoved the tag for unix timestamp in views rest export, below is the patch for it.
tag removed code
Comment #11
niranjan_panem commentedComment #12
steven snedker commented@niranjan_panem the patch in #10 is probably better than nothing, but it's not a long term useful solution.
Before patching:
Ask for "raw output" at Format - Fields - Config. This will give you a timestamp, no HTML.
After patching:
Ask or Custom: U at Date Format. This will give you a timestamp, no HTML.
What we need is
The correct solution:
Configuring the field, you should be able to set Formatter as "raw/no html markup"
Default/Time Ago just doesn't cut it as formatting options.
Comment #13
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.