Posted ; Last Updated
I knew for a while that HTML has this thing called "time" tags. They are meant for exactly this kind of purpose: when you have a human readable date in whatever format makes sense to the person reading it, and you still want a machine to be able to understand it. Implementing that was no big deal, just a few minor changes in my backend code and the dates were now properly wrapped in a
<time> tag with a
datetime attribute containing a date and time in ISO 8601 format.
<time> element, so I just opened the console in my browser and started typing
document.getElementByTag... and, as it turns out, it's elements (plural, because it returns more than one (duh)), and does not return an array, but a HTML collection. Why it does this is beyond me, but I sure felt the consequences. More on that later though. As I was writing a function to do the actual magic, though only on a single
time elements, and remember there's this useful thing called
map. Though this isn't 100% the intended use case of the map function, it still provides exactly what I need, except, it doesn't. The problem is, it only works on arrays. Why? who knows, though the more important question should be, why
document.getElementsByTagName doesn't return a normal array in the first place.
In the end I fixed the problem with some terribly ugly code, but the question remains:
Looking on the bright side: the dates are now localized (and above the articles).