Skip to content

Commit

Permalink
Altered the locale methods to hopefully prevent window undefined erro…
Browse files Browse the repository at this point in the history
…rs. (#1723)
  • Loading branch information
CalebKAston authored and martijnrusschen committed May 4, 2019
1 parent 990dfe3 commit 4da00b4
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/date_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,24 +255,31 @@ export function getDaysDiff(date1, date2) {
// ** Date Localization **

export function registerLocale(localeName, localeData) {
if (!window.__localeData__) {
window.__localeData__ = {};
const scope = window || global;

if (!scope.__localeData__) {
scope.__localeData__ = {};
}
window.__localeData__[localeName] = localeData;
scope.__localeData__[localeName] = localeData;
}

export function setDefaultLocale(localeName) {
window.__localeId__ = localeName;
const scope = window || global;

scope.__localeId__ = localeName;
}

export function getDefaultLocale() {
return window.__localeId__;
const scope = window || global;

return scope.__localeId__;
}

export function getLocaleObject(localeSpec) {
if (typeof localeSpec === "string") {
// Treat it as a locale name registered by registerLocale
return window.__localeData__ ? window.__localeData__[localeSpec] : null;
const scope = window || global;
return scope.__localeData__ ? scope.__localeData__[localeSpec] : null;
} else {
// Treat it as a raw date-fns locale object
return localeSpec;
Expand Down

0 comments on commit 4da00b4

Please sign in to comment.