Skip to content

Commit a9d9766

Browse files
CalebKAstonmartijnrusschen
authored andcommitted
Altered the locale methods to hopefully prevent window undefined errors. (Hacker0x01#1723)
1 parent cda4181 commit a9d9766

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/date_utils.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,31 @@ export function getDaysDiff(date1, date2) {
255255
// ** Date Localization **
256256

257257
export function registerLocale(localeName, localeData) {
258-
if (!window.__localeData__) {
259-
window.__localeData__ = {};
258+
const scope = window || global;
259+
260+
if (!scope.__localeData__) {
261+
scope.__localeData__ = {};
260262
}
261-
window.__localeData__[localeName] = localeData;
263+
scope.__localeData__[localeName] = localeData;
262264
}
263265

264266
export function setDefaultLocale(localeName) {
265-
window.__localeId__ = localeName;
267+
const scope = window || global;
268+
269+
scope.__localeId__ = localeName;
266270
}
267271

268272
export function getDefaultLocale() {
269-
return window.__localeId__;
273+
const scope = window || global;
274+
275+
return scope.__localeId__;
270276
}
271277

272278
export function getLocaleObject(localeSpec) {
273279
if (typeof localeSpec === "string") {
274280
// Treat it as a locale name registered by registerLocale
275-
return window.__localeData__ ? window.__localeData__[localeSpec] : null;
281+
const scope = window || global;
282+
return scope.__localeData__ ? scope.__localeData__[localeSpec] : null;
276283
} else {
277284
// Treat it as a raw date-fns locale object
278285
return localeSpec;

0 commit comments

Comments
 (0)