Replace moment-mini
/moment
date library with dayjs
#4153
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📑 Summary
Replace Mermaid's dependency on
moment
/moment-mini
withdayjs
.Moment is now in maintenance mode, and they don't recommend using it.
Dayjs is also much smaller, with the core library only being "2kB" when gzipped (although we have to use some plugins for backwards compatibility, which will increase the bundle size slightly).
Should hopefully resolve emersonbottero/vitepress-plugin-mermaid#33 (@emersonbottero, feel free to confirm).
Discussed in #4094 (comment)
📏 Design Decisions
Dayjs has almost exactly the same API as moment, and is still currently being maintained. Unlike moment, dayjs objects are immutable, which makes our life much easier (we never need to call
dayjs.clone()
), but we need to doa = a.add(1, "day")
instead of justa.add(1, "day")
.We can't use
dayjs.duration
, because unlikemoment.duration
, dayjs duration always degrade to ms. This causes issues with daylight savings, since it assumes that each day is 24 hours, when some days have 23/25 hours with daylight savings. (it also assumes that each month is 30 days).However,
dayjs.add(1, "d");
correctly adds 1 days, even when that day is only 23 hours long, so we can use that instead.Issues:
All unit tests and e2e tests pass.
However, the following e2e test has a change:
mermaid/cypress/integration/rendering/gantt.spec.js
Line 95 in 8b5cb75
Does anybody have any ideas what might be different? I wonder if it's a daylight savings issue, since this Gantt chart seems to be one of the longest ones.
📋 Tasks
Make sure you
1d
is 25 hours long on 2020-11-01, which because of daylight savings, has 25 hours in California.develop
branch