Skip to content

refactor: simplify exclusive timeZone/utcOffset runtime check#1067

Open
Gdhanush-13 wants to merge 1 commit into
kelektiv:mainfrom
Gdhanush-13:fix/exclusive-params-runtime-check
Open

refactor: simplify exclusive timeZone/utcOffset runtime check#1067
Gdhanush-13 wants to merge 1 commit into
kelektiv:mainfrom
Gdhanush-13:fix/exclusive-params-runtime-check

Conversation

@Gdhanush-13

Copy link
Copy Markdown

Problem

The CronTime initialization after the exclusive parameter check (#704) had a redundant third else branch:

if (timeZone != null) {
    this.cronTime = new CronTime(cronTime, timeZone, null);
} else if (utcOffset != null) {
    this.cronTime = new CronTime(cronTime, null, utcOffset);
} else {
    // Both are null/undefined here - same as the else-if result
    this.cronTime = new CronTime(cronTime, timeZone, utcOffset);
}

After the ExclusiveParametersError throw, both timeZone and utcOffset are guaranteed to not be non-null simultaneously. The third else branch is therefore always equivalent to the else if branch (both pass null/undefined), making it redundant.

Solution

Simplify to a ternary - timeZone != null is the only branch needed; the fallthrough handles all other cases:

this.cronTime =
    timeZone != null
        ? new CronTime(cronTime, timeZone, null)
        : new CronTime(cronTime, null, utcOffset ?? null);

No behavior changes - existing tests pass unchanged.

Fixes #704

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 kelektiv#704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor runtime check & typings of exclusive parameters timeZone & utcOffset

1 participant