Skip to content

Commit

Permalink
Return error if timezone name is not a string
Browse files Browse the repository at this point in the history
  • Loading branch information
ellenaua committed Jun 18, 2018
1 parent ae6eaaa commit 8a35aff
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions moment-timezone.js
Expand Up @@ -29,9 +29,13 @@
links = {},
names = {},
guesses = {},
cachedGuess,
cachedGuess;

momentVersion = moment.version.split('.'),
if (!moment || typeof moment.version !== 'string') {
logError('Moment Timezone requires Moment.js. See https://momentjs.com/timezone/docs/#/use-it/browser/');
}

var momentVersion = moment.version.split('.'),
major = +momentVersion[0],
minor = +momentVersion[1];

Expand Down Expand Up @@ -394,7 +398,7 @@

function getZone (name, caller) {
if (typeof name !== 'string') {
throw new Error('Timezone name must be a string, not ' + name.toString() + ' (' + typeof name + ')');
throw new Error('Time zone name must be a string, got ' + name + ' [' + typeof name + ']');
}

name = normalizeName(name);
Expand Down Expand Up @@ -555,9 +559,6 @@

fn.tz = function (name, keepTime) {
if (name) {
if (typeof name !== 'string'){
throw new Error('First parameter must be a timezone name, got ' + name.toString() + ' (' + typeof name + ')');
}
this._z = getZone(name);
if (this._z) {
moment.updateOffset(this, keepTime);
Expand Down

0 comments on commit 8a35aff

Please sign in to comment.