Skip to content

bug(common): date pipe rounds up date when fractional second is more than 3 digits #37989

@antoinebrault

Description

@antoinebrault

Hi,

I believe I've come across a bug in the date parsing.
I haven't seen any indications that this is expected behavior, so I'm opening an issue here.

🐞 bug report

Affected Package

@angular/common
Seems to be in every version I tested. Angular 6, 9, 10

const ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);

Is this a regression?

Not that I've seen.

Description

The Date pipe has some unexpected behavior when second fractions have more than 3 digits.

ISO 8601 format is not capped on fractional second number of digits.
https://www.w3.org/TR/NOTE-datetime
https://en.wikipedia.org/wiki/ISO_8601#:~:text=There%20is%20no%20limit%20on%20the%20number%20of%20decimal%20places%20for%20the%20decimal%20fraction
https://momentjs.com/docs/#:~:text=Fractional%20Second
https://date-fns.org/v2.14.0/docs/format#:~:text=Fraction%20of%20second

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-date-fractional-second-test

  3 digits: {{ '2020-08-01T23:59:59.999' | date: 'yyyy-MM-dd' }} 
  <br>
  4 digits: {{ '2020-08-01T23:59:59.9999' | date: 'yyyy-MM-dd' }}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions