Skip to content

DatePipe milliseconds #14103

Closed
Closed

Description

@D-Thrane

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'

Activity

  1. DzmitryShylovich commented on Jan 25, 2017

    @DzmitryShylovich
    Contributor

    Pls provide a plunkr with reproduction

  2. added
    area: commonIssues related to APIs in the @angular/common package
    area: i18nIssues related to localization and internationalization
    needs reproductionThis issue needs a reproduction in order for the team to investigate further
    on Jan 25, 2017
  3. D-Thrane commented on Jan 26, 2017

    @D-Thrane
    Author
  4. pkozlowski-opensource commented on Jan 26, 2017

    @pkozlowski-opensource
    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.

  5. DzmitryShylovich commented on Jan 26, 2017

    @DzmitryShylovich
    Contributor

    We could change the date pipe to ignore NaN

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

  6. pkozlowski-opensource commented on Jan 26, 2017

    @pkozlowski-opensource
    Member

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

    Yeh, this wouldn't hurt. PR?

  7. D-Thrane commented on Jan 26, 2017

    @D-Thrane
    Author

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

  8. DzmitryShylovich commented on Jan 26, 2017

    @DzmitryShylovich
    Contributor
  9. D-Thrane commented on Jan 26, 2017

    @D-Thrane
    Author

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

  10. DzmitryShylovich commented on Jan 26, 2017

    @DzmitryShylovich
    Contributor

    Try new Date(360000) in a browser console

  11. D-Thrane commented on Jan 26, 2017

    @D-Thrane
    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

  12. D-Thrane commented on Jan 26, 2017

    @D-Thrane
    Author

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

  13. added a commit that references this issue on Jan 27, 2017
    32cc675
  14. D-Thrane commented on Feb 11, 2017

    @D-Thrane
    Author
  15. added a commit that references this issue on Aug 28, 2017
    e5cbde5
  16. angular-automatic-lock-bot commented on Sep 10, 2019

    @angular-automatic-lock-bot

    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.

  17. locked and limited conversation to collaborators on Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: commonIssues related to APIs in the @angular/common packagearea: i18nIssues related to localization and internationalization

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions