Skip to content

Conversation

@ryceg
Copy link
Collaborator

@ryceg ryceg commented May 2, 2025

This pull request removes the MomentJS dependency, and replaces it with the much lighter DayJS, which has a largely identical API.

This has resulted in a package bundle size reduction of 630Kb. DayJS is not tree-shakeable, and we could get an ever so slightly smaller bundle size if we went with date-fns, but I figured that the 1:1 nature of the migration makes DayJS the clear winner.

Instead of completely remove the .moment api from the context, I've added .dayjs() in case there are some corners of the project which I've missed- I've Ctrl+F'd and replaced it wherever found it (but did NOT find and replace to change the dependency, as that would overwrite properties in loop.js.

@sulkaharo
Copy link
Member

I tried this earlier and at that point bumped into issues with DayJS having significant issues with date math & time zones. Seems some of this has been fixed, but curious to hear how extensively you've tested this? See iamkun/dayjs#1805

@ryceg
Copy link
Collaborator Author

ryceg commented May 2, 2025

I've only done preliminary testing- haven't run it through its paces yet, figured it would be useful to gather some feedback prior. Sounds like I was right. The idempotency issue is definitely something I could've missed, I'll let you know how I go with it!

@dnzxy
Copy link

dnzxy commented May 2, 2025

I tried this earlier and at that point bumped into issues with DayJS having significant issues with date math & time zones. Seems some of this has been fixed, but curious to hear how extensively you've tested this? See iamkun/dayjs#1805

We have gone through similar issues at work, where we heavily rely on moment for a very date arithmetic and timezone reliant heavy software bundle we maintain. Careful with just swapping this, especially if (like here) there was not just reliance on moment but also moment-tz.

@ryceg
Copy link
Collaborator Author

ryceg commented May 18, 2025

Minor question @bewest; currently, the API rejects illegal date formats;

it('should reject invalid date - illegal format', async () => {
    let res = await self.instance.post(self.url, self.jwt.create)
      .send(Object.assign({}, self.validDoc, { date: '2019-20-60T50:90:90' }))
      .expect(400);

    res.body.status.should.equal(400);
    res.body.message.should.equal('Bad or missing date field');
  });

However, DayJS is a little more lenient than MomentJS is with its parsing- it can parse that as a valid date, 2020-10-01T03:31:30. The dayjs api isn't flexible enough to let us disallow correcting those "overflows" while keeping the rest of the parsing, so our other option is spelling out every "allowed" date format that we want to allow in. Considering the relative infrequency of date malformation via overflows, what's your feeling on removing the assertion that it rejects an overflowed date?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.