Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

DzmitryShylovich
Copy link
Contributor

Fixes #14103

@@ -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;

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)

Copy link
Contributor

@dejour dejour Jan 26, 2017

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)?

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.

Copy link
Contributor Author

@DzmitryShylovich DzmitryShylovich Jan 26, 2017

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

@pkozlowski-opensource pkozlowski-opensource added the area: common Issues related to APIs in the @angular/common package label Jan 26, 2017
@pkozlowski-opensource pkozlowski-opensource self-assigned this Jan 26, 2017
@IgorMinar
Copy link
Contributor

IgorMinar commented Jan 26, 2017

unrelated to this PR, I'm just trying to get hold of Dzmitry: hi @DzmitryShylovich, can you please email me at iminar@google ? thanks

@pkozlowski-opensource
Copy link
Member

Related to this PR: LGTM

@pkozlowski-opensource pkozlowski-opensource added pr_state: LGTM action: merge The PR is ready for merge by the caretaker labels Jan 26, 2017
@DzmitryShylovich
Copy link
Contributor Author

@IgorMinar I sent you an email

@mhevery mhevery closed this in 7ad616a Jan 27, 2017
@DzmitryShylovich DzmitryShylovich deleted the gh/14103 branch January 27, 2017 19:12
mhevery pushed a commit that referenced this pull request Jan 27, 2017
juleskremer pushed a commit to juleskremer/angular that referenced this pull request Aug 28, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: common Issues related to APIs in the @angular/common package cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DatePipe milliseconds
5 participants