material-ui-pickers icon indicating copy to clipboard operation
material-ui-pickers copied to clipboard

dayjs localization

Open Toub opened this issue 7 years ago • 14 comments

Is your feature request related to a problem? Please describe.

material-ui-pickers documentation mentions date-fns & moment, but nothing about dayjs.

Is it supported, and how to use it?

Configuring dayjs locale globaly before initialization partially works, but formats and weekStart (Sunday or Monday are still default one: english).

  dayjs.extend(utc, {});
  dayjs.locale('fr'); // default locale
  <MuiPickersUtilsProvider utils={DayjsUtils} locale="fr">

image

Describe the solution you'd like

Official support & documentation for dayjs localization would be a must!

Additional context

Not sure if it is related but last date-io version mention support for dayjs localization: https://github.com/dmtrKovalenko/date-io/pull/39

Toub avatar Apr 25 '19 08:04 Toub

Any updates on this?

iakovosvo avatar May 26 '19 11:05 iakovosvo

I'd like an update on this as well. Setting the local shifts the numbers for the days correctly, but the labels keep starting with Sunday instead of Monday.

Studio384 avatar Jul 02 '19 07:07 Studio384

I am not really sure it is possible with dayjs (weekdays shift)

dmtrKovalenko avatar Jul 02 '19 07:07 dmtrKovalenko

There are any ideas? We have roll out material ui pickers with dayjs in production and realised that weekdays shift do not work properly 😅

auwtch avatar Aug 11 '19 15:08 auwtch

It is possible with custom override. You will need to override

dmtrKovalenko avatar Aug 11 '19 15:08 dmtrKovalenko

Snippet?

stunaz avatar Aug 11 '19 16:08 stunaz

@dmtrKovalenko I investigated this a little and I think this is a bug in date-io wrapper around dayjs

  1. DatePicker uses getWeekdays() from date-io
  2. getWeekdays for dayjs something like this:
const getWeekdays = () => [0, 1, 2, ...].map(n => dayjs.set('day', n).format('dd))

You can see it here: https://github.com/dmtrKovalenko/date-io/blob/master/packages/dayjs/src/dayjs-utils.ts#L209

While dayjs docs states that this way you will always get ['su', 'mo', 'tu', ...]: docs Screenshot from 2019-08-11 19-08-24


The solution I see is to use dayjs.startOf('week') in the date-io in the getWeekdays function. In dayjs startOf('week') respects locale

vadzimmaisiuk avatar Aug 11 '19 16:08 vadzimmaisiuk

related issue here https://github.com/dmtrKovalenko/date-io/issues/111

Toub avatar Aug 12 '19 07:08 Toub

It is possible with custom override. You will need to override

@dmtrKovalenko thanks for your answer. So does it mean a "won't fix"?

Toub avatar Aug 12 '19 07:08 Toub

@Toub it works in this patched fork: https://github.com/vmajsuk/date-io

"date-io": "https://github.com/vmajsuk/date-io"
import DayJsUtils from 'date-io/packages/dayjs/build

Waiting for an answer from @dmtrKovalenko about provided patch

auwtch avatar Aug 12 '19 09:08 auwtch

@testarossaaaaa can you please make a PR to the original date-io?

dmtrKovalenko avatar Aug 12 '19 09:08 dmtrKovalenko

@dmtrKovalenko https://github.com/dmtrKovalenko/date-io/pull/113

vadzimmaisiuk avatar Aug 12 '19 10:08 vadzimmaisiuk

Could someone provide an example on how to achieve dayjs localization currently ?

hug0b avatar Oct 14 '19 08:10 hug0b

In case someone is finding this issue because of the missing documentation:

just import the local from dayjs and set the local globally on dayjs:

import "dayjs/locale/de"

dayjs.locale("de")

dayjs docs

HartmannVolker avatar Oct 01 '20 14:10 HartmannVolker