Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Migrate from moment.js to Luxon #25

Open
parkr opened this issue Dec 28, 2020 · 3 comments
Open

Migrate from moment.js to Luxon #25

parkr opened this issue Dec 28, 2020 · 3 comments

Comments

@parkr
Copy link
Owner

parkr commented Dec 28, 2020

We only need to convert one line of moment.js to Luxon:

els[i].dataset.fromDate = moment(els[i].innerText).fromNow();

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.

@parkr
Copy link
Owner Author

parkr commented Dec 28, 2020

Here's an idea of how to accomplish this with Luxon: moment/luxon#274 (comment)

@parkr
Copy link
Owner Author

parkr commented Dec 29, 2020

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.

@zymotik
Copy link

zymotik commented Aug 26, 2021

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'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants