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

            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: