Skip to content

Commit

Permalink
Return more self-explaining error messages when timezone name is not …
Browse files Browse the repository at this point in the history
…a string
  • Loading branch information
ellenaua committed Jun 18, 2018
1 parent 05a93be commit ae6eaaa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions moment-timezone.js
Expand Up @@ -393,6 +393,10 @@
}

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

name = normalizeName(name);

var zone = zones[name];
Expand Down Expand Up @@ -551,6 +555,9 @@

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 ae6eaaa

Please sign in to comment.