Skip to content

Bugfix: Loss of locale due to getLocaleData#45

Open
STK913 wants to merge 8 commits intolennym:masterfrom
STK913:master
Open

Bugfix: Loss of locale due to getLocaleData#45
STK913 wants to merge 8 commits intolennym:masterfrom
STK913:master

Conversation

@STK913
Copy link
Copy Markdown

@STK913 STK913 commented Dec 23, 2020

Hello, when we want to use multiple configurations of "workinghours", we need to use the locale, but since getLocaleData refers to "moment" at the global level, the configuration is lost by calling the nextTransitionTime, isBusinessDay, isWorkingDay and isHoliday methods... (I advise you to check the behavior of each method).

// Here is my test code
bugfix() {
	console.log(moment.localeData()._workinghours); // Return the default configuration

	moment.updateLocale("test", {workinghours: {0: ['04:00:00', '20:00:00'], 1: ['04:00:00', '20:00:00'], 2: ['04:00:00', '20:00:00'], 3: ['04:00:00', '20:00:00'], 4: null, 5: null, 6: null}});
	moment.locale("en"); // To keep the default English locale

	let startMoment = moment().locale("test").nextWorkingTime();
	let endMoment = startMoment.nextTransitionTime().moment;
	console.log(endMoment.toDate()); // Fail
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant