dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

Dayjs locales are very limited compared to MomentJS

Open NicHaley opened this issue 5 years ago • 5 comments

Describe the bug Not a bug but a feature request. The day.js locales only have a small subset of the data compared to MomentJS. This can result in unexpected behaviour when migrating from MomentJS to day.js.

For example, consider the de translations for day.js and MomentJS. MomentJS has calendar values. This makes it possible to output things like "Tomorrow at 12:30pm".

Expected behavior Day.js should provide the same locale data as MomentJS.

Information

  • Day.js Version: 1.8.36
  • OS: MacOS Catalina
  • Browser: FireFox
  • Time zone: EST

NicHaley avatar Sep 22 '20 21:09 NicHaley

Hi, you can pass specifying calendar output formats as the second parameter. https://day.js.org/docs/en/display/calendar-time

We don't have a conclusion about whether to bundle the calendar locale inside or let our users passed in right now, it might not worth doing this because it's not a very important locale part.

You can check some of our previous discussion https://github.com/iamkun/dayjs/pull/570

iamkun avatar Sep 23 '20 01:09 iamkun

Thanks for sharing the link! For now I will add on my own, but to add my two cents I don't think adding the calendar keys would increase the bundle size an appreciable amount. Additionally, I assume most apps don't require every locale. Ours for example uses 28 locales, and we only dynamically import locales when needed. The difference in gzipped bundle size for each locale would only be a few bytes.

NicHaley avatar Sep 23 '20 02:09 NicHaley

Alternatively, as you suggested in the previous thread even having a part and full version for each locale would be useful.

NicHaley avatar Sep 23 '20 02:09 NicHaley

Agreed. Will see if there's something we could do to improve this.

iamkun avatar Sep 23 '20 02:09 iamkun

Curious if there's been any traction here? This feels like a bit gotcha for folks trying to migrate off of a moment.js.

At the very least, it would be nice to have some sort of suggested guidelines on handling overrides. Particularly, it's not clear to me how we should handle Spanish when the moment locales use a function instead of a string:

https://github.com/moment/moment/blob/develop/locale/es.js#L70-L90

et avatar Mar 25 '24 16:03 et