dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

UpdateLocale Plugin does not allow partial updates to locale

Open stefanbinder opened this issue 5 years ago • 2 comments

Describe the enhancement While using the UpdateLocale Plugin, it isn't possible to just update one single value in a nested value. For example I just want to update the format.L value:

dayjs.extend(UpdateLocale);
dayjs.updateLocale('de', {
  formats: {
    L: 'D.M.YYYY',
  },
});

Like this other formats LL, LLL, ... are getting lost.

Expected behavior I want to pass in an object, which updates the locale information partially.

Information

  • Day.js Version [e.g. v1.9.1]
  • OS: [e.g. iOS]

PS:
If the issue is accepted as a bug/enhancement, I would like to contribute and create a PR for that issue 😃

stefanbinder avatar Oct 08 '20 13:10 stefanbinder

Agreed. Will update this feature later.

iamkun avatar Oct 10 '20 15:10 iamkun

The issue still persists with version "1.11.4". updateLocal drops all other keys from the object.

My workaround:

const relativeTime = {
  relativeTime: {
    ...dayjs.Ls[nextLocale].relativeTime,
    future: "custom text",
    past: "custom text"
  } 
};
dayjs.updateLocale(nextLocale, relativeTime);

habela97 avatar Aug 01 '22 09:08 habela97

Trying to fix here https://github.com/iamkun/dayjs/pull/2075 @iamkun

ajisulist avatar Sep 29 '22 02:09 ajisulist