From dffed7a8a9936e5be023ca76d389c258f1746dcd Mon Sep 17 00:00:00 2001 From: Gilmore Davidson Date: Sun, 25 Jun 2023 19:54:35 +1000 Subject: [PATCH] perf: Reduce unnecessary getZone() calls in moment.tz() `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. --- moment-timezone.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/moment-timezone.js b/moment-timezone.js index bc84fae7..dd2f0213 100644 --- a/moment-timezone.js +++ b/moment-timezone.js @@ -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'); }