Skip to content

Use Number.isNaN instead of global isNaN in dates utility - #1236

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/dates-isnan-type-safety
Open

Use Number.isNaN instead of global isNaN in dates utility#1236
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/dates-isnan-type-safety

Conversation

@pavankumar-vh

Copy link
Copy Markdown

Overview

Fix type safety issue in common/src/util/dates.ts by using Number.isNaN instead of the global isNaN function.

Bug Description

The global isNaN() function coerces non-numbers to numbers first, which can lead to unexpected results.

Fix

Changed isNaN(diffMs) to Number.isNaN(diffMs) for more predictable and safer type checking.

Testing

No existing tests for this function, but the fix improves type safety.

Files Changed

  • common/src/util/dates.ts - Use Number.isNaN instead of global isNaN

Scope

This change only touches common/ which is an approved contribution area per the Contributing Guide.

The global isNaN() function coerces non-numbers to numbers first, which can
lead to unexpected results. Using Number.isNaN is more predictable and safer
for type checking.
@codebuff-team

Copy link
Copy Markdown
Contributor

This is a minor but legitimate improvement. diffMs is already a number (result of subtracting two .getTime() calls), so Number.isNaN is strictly more correct here since it skips the coercion step of the global isNaN. Behaviorally identical in this specific case since diffMs is always a number, but using Number.isNaN is better practice and guards against future refactors that might pass a non-number in.

The change is small, scoped, and safe - easy to port by hand. No tests needed for a one-line type-safety tightening like this. Nothing to flag as risky.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants