-
Notifications
You must be signed in to change notification settings - Fork 34
Duration Java 9 methods #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* the number of seconds parts in the duration, may be negative | ||
* @since 9 | ||
*/ | ||
def toSecondsPart: Int = (toSeconds / SECONDS_PER_MINUTE).toInt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, shouldn't this be using %
to get the remainder instead of /
? Why doesn't the test suite catch this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, it say so on the docs 😄 the test suite is not good enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch I added a fix
* the number of hours part in the duration, may be negative | ||
* @since 9 | ||
*/ | ||
def toHoursPart: Int = (toHours / HOURS_PER_DAY).toInt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should all be remainders except toMillis
@armanbilge I amended the implementation and added new tests to surface what was working wrong earlier in case you want to take a look |
* @return | ||
* the nanoseconds within the second part of the length of the duration, from 0 to 999,999,999 | ||
* @since 9 | ||
*/ | ||
def toNanosPart: Int = (nanos / Duration.NANOS_PER_SECOND).toInt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I still don't understand the calculation here. According to the constructor, nanos
should always be between 0 and 999,999,999. So why do we need to do any calculation here?
scala-java-time/core/shared/src/main/scala/org/threeten/bp/Duration.scala
Lines 495 to 501 in bee7f13
* @param seconds | |
* the length of the duration in seconds, positive or negative | |
* @param nanos | |
* the nanoseconds within the second, from 0 to 999,999,999 | |
*/ | |
@SerialVersionUID(3078945930695997490L) | |
final class Duration private (private val seconds: Long, private val nanos: Int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, let's delete toNanosPart
and release, If somebody needs it PRs are welcome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I don't think it needed to be deleted. I think the correct implementation is to just return nanos
here :)
a1ad3e9
to
0f5f39a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
0f5f39a
to
d2da535
Compare
Partially fixes #254