From 335ef2ebe8c1765c5bbd3f1547678b08c7b60e61 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Wed, 28 Dec 2016 11:23:33 -0800 Subject: [PATCH] warn when trying to use a non-existent locale --- strftime.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/strftime.js b/strftime.js index 4d1fce3..398f2a5 100644 --- a/strftime.js +++ b/strftime.js @@ -239,9 +239,7 @@ var _deprecationWarnings = {}; function deprecationWarning(name, instead) { if (!_deprecationWarnings[name]) { - if (typeof console !== 'undefined' && typeof console.warn == 'function') { - console.warn("[WARNING] " + name + " is deprecated and will be removed in version 1.0. Instead, use `" + instead + "`."); - } + warn("[WARNING] " + name + " is deprecated and will be removed in version 1.0. Instead, use `" + instead + "`."); _deprecationWarnings[name] = true; } } @@ -414,9 +412,7 @@ // ':' else if (currentCharCode === 58) { if (extendedTZ) { - if (typeof console !== 'undefined' && typeof console.warn == 'function') { - console.warn("[WARNING] detected use of unsupported %:: or %::: modifiers to strftime"); - } + warn("[WARNING] detected use of unsupported %:: or %::: modifiers to strftime"); } extendedTZ = true; continue; @@ -739,6 +735,10 @@ strftime.localizeByIdentifier = function(localeIdentifier) { var locale = Locales[localeIdentifier]; + if (!locale) { + warn('[WARNING] No locale found with identifier "' + localeIdentifier + '".'); + return strftime; + } return strftime.localize(locale); }; @@ -847,4 +847,10 @@ return (date.getTimezoneOffset() || 0) * 60000; } + function warn(message) { + if (typeof console !== 'undefined' && typeof console.warn == 'function') { + console.warn(message) + } + } + }());