vis-timeline icon indicating copy to clipboard operation
vis-timeline copied to clipboard

moment.js is deprecated and should be replaced

Open mojoaxel opened this issue 4 years ago • 12 comments

moment.js consideres itself now deprecated.

moment.js takes up over 10% of the bundle size:

-----------------------------
Rollup File Analysis
-----------------------------
bundle size:    1.456 MB
original size:  1.414 MB
code reduction: 0 %
module count:   509

/node_modules/moment/moment.js
█████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 10.48 % (152.665 KB)
/node_modules/vis-util/esnext/esm/vis-util.js
████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 8.92 % (129.931 KB)
/lib/timeline/component/ItemSet.js
███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 6.79 % (98.892 KB)
/node_modules/vis-data/esnext/esm/vis-data.js
██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 5.82 % (84.813 KB)
/node_modules/@egjs/hammerjs/dist/hammer.esm.js
██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 5.15 % (75.003 KB)
/lib/timeline/Core.js
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 3.83 % (55.844 KB)
/lib/timeline/component/Group.js
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 3.02 % (43.997 KB)
/lib/timeline/component/LineGraph.js
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 2.51 % (36.608 KB)
/lib/timeline/Range.js
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 2.29 % (33.327 KB)
/lib/timeline/Timeline.js
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 2.11 % (30.676 KB)

The vis.js universe should switch to a different library (e.g. Luxon, Day.js, date-fns, js-Joda)

mojoaxel avatar Sep 15 '20 20:09 mojoaxel

See https://github.com/visjs/vis-timeline/issues/12#issuecomment-579963603

Glandos avatar Dec 15 '20 11:12 Glandos

Maybe as well use Intl native object as much as possible?

imagoiq avatar Jun 25 '21 08:06 imagoiq

I propose to use dayjs instead of moment.js in the future. Dayjs has a good support for locals and is very small. An alternative would be to use native date functionalities (e.g. Intl) wherever possible and sprinkle in some function from date-fns wherever necessary. But using dayjs will definitely be easier!

https://github.com/you-dont-need/You-Dont-Need-Momentjs

mojoaxel avatar Oct 11 '21 09:10 mojoaxel

I would suggest the following procedure:

  • find all the places moment is used. (Here eslint-plugin-you-dont-need-momentjs can help)
  • replace all moment-operations with functions from the DateUtil. If functions are missing add them to the DateUtils.
  • Create intensive tests for all function within the DateUtils!
  • Remove moment from the DateUtils-function one by one while running and improving the test to ensure everything works like expected.
  • In the end remove moment from global space and all the documentation.
  • this than needs to be released a mayor release!

mojoaxel avatar Oct 11 '21 09:10 mojoaxel

Any progress on this? Momentjs is a big ball of ugly bloat.

Fanna1119 avatar Nov 16 '21 13:11 Fanna1119

I am in favour of day.js ... can I take the responsible person for this PR?

michealroberts avatar Sep 26 '22 15:09 michealroberts

Instead on just using dayjs we could introduce a neutral adapter layer. Similar of what chart.js is doing with their "adapters". That way people could choose an adapter with a library they already use in their project.

This is not a trivial task to do, but well-tested PRs are very welcomed!

mojoaxel avatar Sep 26 '22 15:09 mojoaxel

@mojoaxel What about date.io? https://github.com/dmtrKovalenko/date-io

michealroberts avatar Sep 26 '22 15:09 michealroberts

date-io looks really promising. It looks like it does not support tree-shaking, but that is maybe a price we should pay!?

merge-requests welcome!

mojoaxel avatar Sep 26 '22 16:09 mojoaxel

Hi All, is this still in the roadmap ?

krishna217 avatar Dec 20 '23 12:12 krishna217

Bump

eg9y avatar Jan 05 '24 03:01 eg9y

https://github.com/visjs/vis-timeline/pull/1569

This should help, it's merged but is unfortunately not released yet

rubennaatje avatar Feb 05 '24 11:02 rubennaatje