From 8e04b38189955a2ebc4a07cf2a686eb58a3e03c2 Mon Sep 17 00:00:00 2001 From: Gdhanush_13 Date: Tue, 16 Jun 2026 13:03:20 +0530 Subject: [PATCH] refactor: simplify exclusive timeZone/utcOffset runtime check The original if-else-if-else chain for CronTime initialization had a redundant third branch. After the exclusive parameter check throws for JS users who pass both, at most one of timeZone or utcOffset can be non-null. The logic is simplified to a single ternary. Fixes #704 --- src/job.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/job.ts b/src/job.ts index 4e301194..005a9a95 100644 --- a/src/job.ts +++ b/src/job.ts @@ -93,13 +93,12 @@ export class CronJob { throw new ExclusiveParametersError('timeZone', 'utcOffset'); } - if (timeZone != null) { - this.cronTime = new CronTime(cronTime, timeZone, null); - } else if (utcOffset != null) { - this.cronTime = new CronTime(cronTime, null, utcOffset); - } else { - this.cronTime = new CronTime(cronTime, timeZone, utcOffset); - } + // After the exclusive check above, at most one of timeZone or utcOffset + // is non-null — pass the active one and null for the other. + this.cronTime = + timeZone != null + ? new CronTime(cronTime, timeZone, null) + : new CronTime(cronTime, null, utcOffset ?? null); if (unrefTimeout != null) { this.unrefTimeout = unrefTimeout;