Skip to content

Duration.toISOString() should use a set precision for seconds #2366

Closed
@creedasaurus

Description

@creedasaurus

Describe the bug

Problem: The Duration.toISOString() will format an ISO string with arbitrary precision floating point seconds. Although the specification doesn't define the precision the seconds field should have, it would likely be better to keep to some common format. The moment library uses the millisecond precision, as does the Java Duration.

I noticed this behavior when moving from moment. We were sending ISO durations to our Java backend and it quickly started throwing exceptions trying to parse the durations.

Expected behavior

Example:

Input: duration(2/3)
Expected: PT0.001S
Actual: PT0.0006666666666666666S

Information

  • Day.js Version [e.g. v1.11.8]
  • OS: All
  • Browser All
  • Time zone: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions