Skip to content

fix: replace moment with dayjs #737

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

fix: replace moment with dayjs #737

wants to merge 6 commits into from

Conversation

touchRED
Copy link
Contributor

@touchRED touchRED commented Mar 21, 2023

#731

Replaces Moment with DayJS, a 2kb library with an almost identical API.

Note:

  • DayJS doesn't ship with an equivalent to Moment's parseFormat method used here. I'm not quite sure how long it could take to recreate this method, and I don't believe the moment-parseformat plugin can function without Moment installed. Thoughts?

@touchRED touchRED requested a review from johnholdun March 21, 2023 19:08
@touchRED touchRED marked this pull request as draft March 21, 2023 19:10
@johnholdun
Copy link
Contributor

Nice! There are tons of examples of real-world timestamps in the fixture files which we can test here as well. I think the best we can aim for here is an equal success rate against all those timestamps to what we were getting with moment.

@touchRED
Copy link
Contributor Author

@johnholdun yep i'm running through all the tests now, realized moment was called in more of those than I expected. More to come!


import cleanDatePublished, { cleanDateString } from './date-published';

describe('cleanDatePublished(dateString)', () => {
it('returns a date', () => {
const datePublished = cleanDatePublished('published: 1/1/2020');

assert.equal(datePublished, moment('1/1/2020', 'MM/DD/YYYY').toISOString());
assert.equal(datePublished, dayjs('1/1/2020', 'M/D/YYYY').toISOString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is how the old tests were too, but can we change all these expected dates into hard-coded strings? I think that would make the functionality we're testing more clear: we expect strings of varying format and quality, and we always return a string in a specific format.

So this line would become:

assert.equal(datePublished, '2020-01-01T00:00:00.000Z');

I think with that change we could probably remove dayjs as a dependency from this test file entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly, i'll have a commit with these changes shortly ✅

@touchRED touchRED force-pushed the fix-remove-moment-js branch from 1b4cc52 to 6a5f892 Compare March 27, 2023 19:58
@touchRED touchRED force-pushed the fix-remove-moment-js branch from bdda1bb to 9cf23f1 Compare March 29, 2023 17:30
@touchRED
Copy link
Contributor Author

@johnholdun clearly the updates we spoke about last week took significantly longer than I expected! Now that test-node is passing I'm going to clean things up, leave comments, etc. Question for you: in order to get test-web to pass, do I need to run yarn release and push up new dist files?

@appinteractive
Copy link

Hey is this issue still be worked on?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants