Open parkr opened 3 years ago
Here's an idea of how to accomplish this with Luxon: https://github.com/moment/luxon/issues/274#issuecomment-729126515
Dang, Luxon.min.js is 68K and moment.min.js is only 58K. For simplicity's sake, I'll stay with moment until it's truly retired.
Luxon v2 - https://moment.github.io/luxon/#/moment?id=humanization
import { DateTime } from 'luxon';
const isoDate = '2021-08-26T08:19:40.342+00:00';
const ago = DateTime.fromISO(isoDate).toRelative();
console.log(ago); // '8 hours ago'
We only need to convert one line of moment.js to Luxon:
https://github.com/parkr/gossip/blob/d2258b10f1d0c020888986f05dcff6f769df833c/public/assets/messages.js#L18
All this code is doing is taking an ISO date and converting it to a human "ago" phrase like "3 minutes ago" or "1 year ago", etc.