Hacker News new | past | comments | ask | show | jobs | submit login

This is worth proposing. A tag where fallback text is provided within which can be overridden by the browser with a formatted date string would be excellent.



It exists: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ti...

As a nearby comment indicates, it's not clear any browser makes use of it.


I used the <time> element in a subscription dashboard.

All times on the page are in UTC and are wrapped in a <time> element. The raw UTC time is on the datetime attribute and a fallback more easily readable time is inside the tags. Some JS on the page removes whatever text is inside the tag and replaces it with the user's locale specific format (no libraries required, it's a part of the browser standards).

User friendly times wasn't actually the reason we implemented it.

Our largest concern was our E2E testing. We needed to make sure that the dates/times displayed were always right (and since subscriptions involve money, we wanted to make sure that part of the website was the most tested.) The E2E testing simply ignores whatever is inside the tag and reads the datetime attribute instead. Then we can fastforward or rewind the simulated time inside the test to make sure everything is working as expected.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: