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

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

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 9
    • core-libs
    • b97

      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.

            ntv Nadeesh Tv
            scolebourne Stephen Colebourne
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: