Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: replace moment with dayjs #737

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 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
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?

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

Successfully merging this pull request may close these issues.

None yet

3 participants