diff --git a/moment-timezone.js b/moment-timezone.js index c3c0642b..7c7a8afa 100644 --- a/moment-timezone.js +++ b/moment-timezone.js @@ -325,11 +325,13 @@ // use Intl API when available and returning valid time zone try { var intlName = Intl.DateTimeFormat().resolvedOptions().timeZone; - var name = names[normalizeName(intlName)]; - if (name) { - return name; + if (intlName){ + var name = names[normalizeName(intlName)]; + if (name) { + return name; + } + logError("Moment Timezone found " + intlName + " from the Intl api, but did not have that data loaded."); } - logError("Moment Timezone found " + intlName + " from the Intl api, but did not have that data loaded."); } catch (e) { // Intl unavailable, fall back to manual guessing. } diff --git a/tests/moment-timezone/guess.js b/tests/moment-timezone/guess.js index 1f3853a2..0e52ed47 100644 --- a/tests/moment-timezone/guess.js +++ b/tests/moment-timezone/guess.js @@ -89,6 +89,22 @@ exports.guess = { test.done(); }, + "When Intl is available, but timeZone is undefined, should return a guess without logging an error" : function (test) { + var oldError = console.error; + var errors = ''; + console.error = function (message) { + errors += message; + }; + + mockIntlTimeZone(undefined); + mockTimezoneOffset(tz.zone('Europe/London')); + test.equal(tz.guess(true), 'Europe/London'); + test.equal(errors, ''); + + console.error = oldError; + test.done(); + }, + "ensure each zone is represented" : function (test) { var names = tz.names(); var zone, i;