Skip to content

Commit

Permalink
perf: Reduce unnecessary getZone() calls in moment.tz()
Browse files Browse the repository at this point in the history
`getZone(name)` was called on every call to `moment.tz()`, even though it
wasn't needed in a lot of cases. This changes the call to only be made if
it's needed for the `if` condition.
  • Loading branch information
gilmoreorless committed Jun 25, 2023
1 parent f7d8fc2 commit dffed7a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions moment-timezone.js
Expand Up @@ -591,10 +591,10 @@
function tz (input) {
var args = Array.prototype.slice.call(arguments, 0, -1),
name = arguments[arguments.length - 1],
zone = getZone(name),
out = moment.utc.apply(null, args);
out = moment.utc.apply(null, args),
zone;

if (zone && !moment.isMoment(input) && needsOffset(out)) {
if (!moment.isMoment(input) && needsOffset(out) && (zone = getZone(name))) {
out.add(zone.parse(out), 'minutes');
}

Expand Down

0 comments on commit dffed7a

Please sign in to comment.