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

DatePipe milliseconds #14103

Closed
D-Thrane opened this issue Jan 25, 2017 · 13 comments
Closed

DatePipe milliseconds #14103

D-Thrane opened this issue Jan 25, 2017 · 13 comments
Labels
area: common Issues related to APIs in the @angular/common package area: i18n

Comments

@D-Thrane
Copy link

D-Thrane commented Jan 25, 2017

I'm submitting a ... (check one with "x")

[ x ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

I have a google map where I click a unit. When I click a unit I get some data about the unit from a REST through a service. I then get StartToday witch is in seconds. I then want to show it as HH:mm:ss. My StartToday returns 360.

{{unit.StartToday * 1000}} // Works is 360000
{{360000 | date: "HH:mm:ss"}} // Works is 01:06:00
{{unit.StartToday * 1000 | date: "HH:mm:ss"}} // Does not work 

I get this error:

EXCEPTION: Error in ./MapComponent class MapComponent - inline template:11:12 caused by: Invalid argument 'NaN' for pipe 'DatePipe' ORIGINAL EXCEPTION: Invalid argument 'NaN' for pipe 'DatePipe'

@DzmitryShylovich
Copy link
Contributor

Pls provide a plunkr with reproduction

@pkozlowski-opensource pkozlowski-opensource added area: common Issues related to APIs in the @angular/common package area: i18n needs reproduction This issue needs a reproduction in order for the team to investigate further labels Jan 25, 2017
@D-Thrane
Copy link
Author

@pkozlowski-opensource
Copy link
Member

The problem is that you are using an async service so your get 360000 value only after some time, asynchronously. Initially your value is NaN and hence the error. Check this plunk and see the flash of NaN -> 3600.

We could change the date pipe to ignore NaN (@DzmitryShylovich, WDYT?) but the crux of the problem is that you are passing NaN to the pipe and this is an invalid argument as clearly stated in the error message.

@pkozlowski-opensource pkozlowski-opensource removed the needs reproduction This issue needs a reproduction in order for the team to investigate further label Jan 26, 2017
@DzmitryShylovich
Copy link
Contributor

We could change the date pipe to ignore NaN

I think it makes sense to just ignore NaN instead of throwing an error.

@pkozlowski-opensource
Copy link
Member

I think it makes sense to just ignore NaN instead of throwing an error.

Yeh, this wouldn't hurt. PR?

DzmitryShylovich added a commit to DzmitryShylovich/angular that referenced this issue Jan 26, 2017
@D-Thrane
Copy link
Author

Thanks. I'm new to Angular. How do I fix this to wait until data i ready?

@DzmitryShylovich
Copy link
Contributor

http://plnkr.co/edit/30STyW3UJM7rqBQOhrzx?p=preview

DzmitryShylovich added a commit to DzmitryShylovich/angular that referenced this issue Jan 26, 2017
DzmitryShylovich added a commit to DzmitryShylovich/angular that referenced this issue Jan 26, 2017
@D-Thrane
Copy link
Author

Why is 360000 Milliseconds shown as 01:06:00. It's only 6 minutes?

@DzmitryShylovich
Copy link
Contributor

Try new Date(360000) in a browser console

@D-Thrane
Copy link
Author

It also looks like it remembers the first date pipe result and add this value to the next.
http://plnkr.co/edit/46PdAjWsH5bk4KFIsvpV?p=preview

@D-Thrane
Copy link
Author

new Date(360000) in console gives me "Thu Jan 26 2017 20:21:31 GMT+0100 (CET)"

mhevery pushed a commit that referenced this issue Jan 27, 2017
@D-Thrane
Copy link
Author

So was there a date problem or?
http://plnkr.co/edit/46PdAjWsH5bk4KFIsvpV?p=preview

juleskremer pushed a commit to juleskremer/angular that referenced this issue 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
area: common Issues related to APIs in the @angular/common package area: i18n
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants