Datetime and TimeSpan shapes should return a <time /> tag optionally
The Datetime and TimeSpan shapes are currently rendering as strings but in an HTML context we should try to render it wrapped with a <time /> tag.
We should probably allow to use a W3C accepted HTML element to make this easier for everyone. It should use <time /> tag in which we can pass/render a datetime or a timespan. At least make it an option to render as a HTML element or a date text but in the end the first should be used more often.
Examples:
For a Datetime shape
Liquid:
{% assign format = "MMMM dd, yyyy" | t %}
{{ "Posted by" | t }} <a href="#">{{ Model.ContentItem.Owner }}</a> {{ "DateTime" | shape_new: utc: Model.ContentItem.CreatedUtc, format: format | time_tag: "on {0}" | t: format }}
Razor:
var format = @T["MMMM dd, yyyy"];
@T["Posted by"] <a href="#">@Model.ContentItem.Owner</a><datetime utc="@Model.ContentItem.CreatedUtc" format="format" >
Should render optionally as :
Posted by <a href="#">Admin</a><time datetime="2019-04-30">on Tue, Apr 30, 2019</time>
For a timeSpan
Liquid:
{{ "TimeSpan" | shape_new: utc: Model.ContentItem.CreatedUtc }}
Razor:
<timespan utc="@Model.ContentItem.CreatedUtc" >
Should render optionally as :
<time datetime="PT15H10M">15 hours and 10 minutes ago</time>
It should render a <time> tag optionally only and it should be backward compatible with what we currently have. Meaning that by default it should not render a time tag.
Looks complicated just to save writing a tag directly. From your examples I couldn't figure out if these were actual html tags or tag helpers in razor. I would assume people would also be confused.
Or maybe create new shapes that render specific tags, like TimeShape
Yeah, somehow DateTime and TimeSpan are distinct in C# but maybe it is not in HTML. So a TimeShapes that would render a <time></time> tag but that would take a TimeSpan or DateTime as parameter.
The other idea was to simply add a param to the actual taghelpers and add an alternate render.