Details
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.
- 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
- relates to
-
JDK-8146489 @since tag missed
-
Activity
Field | Original Value | New Value |
---|---|---|
Fix Version/s | 9 [ 14949 ] |
Status | New [ 10000 ] | Open [ 1 ] |
Assignee | Roger Riggs [ rriggs ] | Nadeesh Tv [ ntv ] |
Status | Open [ 1 ] | In Progress [ 3 ] |
Understanding | Fix Understood [ 10001 ] |
Summary | Additional java.time.Duration methods | Add java.time.Duration methods for days, hours, minutes, seconds, etc. |
Status | In Progress [ 3 ] | Resolved [ 5 ] |
Resolved In Build | team [ 17324 ] | |
Understanding | Fix Understood [ 10001 ] | |
Resolution | Fixed [ 1 ] |
Resolved In Build | team [ 17324 ] | master [ 18256 ] |
Resolved In Build | master [ 18256 ] | b97 [ 17595 ] |
Link |
This issue relates to |
Labels | jsr379-annex2-tbd |
Labels | jsr379-annex2-tbd | jsr379-annex1 |
Link | This issue csr of CCC-8142936 [ CCC-8142936 ] |
Since we have both getNano() and toNanos() replacing getSeconds() with toSeconds(), won't it create more confusion?