My JS Jabber cohost AJ ONeal wrote an article about how to display the elapsed time since an event in plain English with vanilla JS.
Not sure what I mean? Something like this:
42 seconds ago 1 hour ago 3 weeks ago
AJ does an awesome job breaking down each step of the script.
He also gets into how to extend it a bit to make it more flexible/reusable, and how to modify it to show future times (like “3 weeks from now”), too.
My favorite part of the whole thing, though, is the ethos AJ brings to writing code.
Not a “Library”, but a Scaffold
When something is this small (and especially when you might want to make tweaks that don’t even make sense to try to “DRY” up or modularize), this Go Proverb comes to mind:
“A little copying is better than a little dependency” - Rob Pike’s Go Proverbs
Go check out AJ’s tutorial to learn more.