Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8142936

Add java.time.Duration methods for days, hours, minutes, seconds, etc.

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b97

      Description

      The Duration class has no methods to obtain the broken down parts of the duration. This has frustrated users, thus it seems wise to add methods to do this:

      - toNanosPart()
      - toMillisPart()
      - toSecondsPart()
      - toMinutesPart()
      - toHoursPart()
      - toDaysPart()

      These would return the breakdown of the duration that is impossible to
      access without user-written maths at present.

      Given a duration of 49H30M20.123S
      - toNanosPart() = 123000000
      - toMillisPart() = 123
      - toSecondsPart() = 20
      - toMinutesPart() = 30
      - toHoursPart() = 1
      - toDaysPart() = 2

      In addition, users have found the lack of a `toSeconds()` method confusing. The method exists, but is named `getSeconds()`, whereas all the similar methods are named `toXxx`. Adding a convenience method here would make the API more usable. Note that this will require renaming an existing private method.

        Issue Links

          Activity

          scolebourne Stephen Colebourne created issue -
          rriggs Roger Riggs made changes -
          Field Original Value New Value
          Fix Version/s 9 [ 14949 ]
          rriggs Roger Riggs made changes -
          Status New [ 10000 ] Open [ 1 ]
          ntv Nadeesh Tv (Inactive) made changes -
          Assignee Roger Riggs [ rriggs ] Nadeesh Tv [ ntv ]
          ntv Nadeesh Tv (Inactive) made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Understanding Fix Understood [ 10001 ]
          rriggs Roger Riggs made changes -
          Summary Additional java.time.Duration methods Add java.time.Duration methods for days, hours, minutes, seconds, etc.
          hgupdate HG Updates made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolved In Build team [ 17324 ]
          Understanding Fix Understood [ 10001 ]
          Resolution Fixed [ 1 ]
          hgupdate HG Updates made changes -
          Resolved In Build team [ 17324 ] master [ 18256 ]
          hgupdate HG Updates made changes -
          Resolved In Build master [ 18256 ] b97 [ 17595 ]
          rriggs Roger Riggs made changes -
          Link This issue relates to JDK-8146489 [ JDK-8146489 ]
          iris Iris Clark made changes -
          Labels jsr379-annex2-tbd
          iris Iris Clark made changes -
          Labels jsr379-annex2-tbd jsr379-annex1
          darcy Joe Darcy made changes -
          Link This issue csr of CCC-8142936 [ CCC-8142936 ]

            People

            • Assignee:
              ntv Nadeesh Tv (Inactive)
              Reporter:
              scolebourne Stephen Colebourne
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: