-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(common): DatePipe doesn't throw for NaN #14117
Conversation
@@ -103,7 +103,7 @@ export class DatePipe implements PipeTransform { | |||
transform(value: any, pattern: string = 'mediumDate'): string { | |||
let date: Date; | |||
|
|||
if (isBlank(value)) return null; | |||
if (isBlank(value) || (<any>Number).isNaN(value)) return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need cast Number
to <any>
here? How about using value != value
(https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/isNaN)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not simply use isNaN(value)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isNaN
has false-positives - check the article I've linked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not simply use isNaN(value)?
Because isNaN
is broken and to fix it they introduced Number.isNaN
in es2015
Why do we need cast Number to here?
because angular doesn't allow to use es2015 types (at least for Object
)
How about using value != value
yeah, it's a good option, just not obvious why it's required vs Number.isNaN
266a2a3
to
9a23b40
Compare
cb3fbe4
to
8e17b7e
Compare
unrelated to this PR, I'm just trying to get hold of Dzmitry: hi @DzmitryShylovich, can you please email me at iminar@google ? thanks |
Related to this PR: LGTM |
@IgorMinar I sent you an email |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes #14103