Skip to content

Commit dffed7a

Browse files
committed
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.
1 parent f7d8fc2 commit dffed7a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

moment-timezone.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,10 @@
591591
function tz (input) {
592592
var args = Array.prototype.slice.call(arguments, 0, -1),
593593
name = arguments[arguments.length - 1],
594-
zone = getZone(name),
595-
out = moment.utc.apply(null, args);
594+
out = moment.utc.apply(null, args),
595+
zone;
596596

597-
if (zone && !moment.isMoment(input) && needsOffset(out)) {
597+
if (!moment.isMoment(input) && needsOffset(out) && (zone = getZone(name))) {
598598
out.add(zone.parse(out), 'minutes');
599599
}
600600

0 commit comments

Comments
 (0)