These methods don't just do the same thing; they are specified as doing the same thing in the documentation (linked in your question):
public long toDays()
Gets the number of days in this duration.
This returns the total number of days in the duration by dividing the number of seconds by 86400. This is based on the standard definition of a day as 24 hours.
This instance is immutable and unaffected by this method call.
Returns:
the number of days in the duration, may be negative
public long toDaysPart()
Extracts the number of days in the duration.
This returns the total number of days in the duration by dividing the number of seconds by 86400. This is based on the standard definition of a day as 24 hours.
This instance is immutable and unaffected by this method call.
Returns:
the number of days in the duration, may be negative
The only difference is the word "gets" vs. "extracts" in the descriptive summary. These words don't have different meanings in this context, and the rest is word-for-word identical, in particular the parts specifying what the methods return are identical. In fact, the (OpenJDK) documentation for toDaysPart
was recently changed to clarify that these methods do the same thing. So yes, they are redundant.
According to the relevant issue on the issue tracker, all of the to...Part
methods were added together and there wasn't any comment on the fact that toDaysPart
would be redundant; so we can only speculate about the rationale for adding the redundant method.
toSeconds()
andgetSeconds()
are the same too. And (sidestepping) IMHO that system of methods is generally ill-named.getXxxPart
would have been better, or even justgetXxx()
so it had been consistent withPeriod.getMonths()
and.getDays()
. – Sueannsuede