case days < 30: return `${days} day(s) ago`;
This will not work for months with 31 days.
It's a just simple version for that formatter. That's why it shows average time. But it's okay with 31 days. If it's more than 30 days then 1 month;
example
new Date(2021, 0, 31); // now - 2021-01-30T20:00:00.000Z const createdAt = new Date(2021, 0, 1); // 2020-12-31T20:00:00.000Z fromAgo(createdAt); // 1 month(s) ago
You can also replace Date.now() with your own date to check with date.getTime()
Date.now()
date.getTime()
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This will not work for months with 31 days.
It's a just simple version for that formatter. That's why it shows average time.
But it's okay with 31 days. If it's more than 30 days then 1 month;
example
You can also replace
Date.now()
with your own date to check withdate.getTime()