Improve up/down variable naming

This commit is contained in:
David Kellum 2018-03-04 18:27:36 -08:00
parent b5acb0ed95
commit 74ec7aa5b2
1 changed files with 9 additions and 9 deletions

View File

@ -27,13 +27,13 @@ where T: Timelike + Add<Duration, Output=T> + Sub<Duration, Output=T>
{
fn round(self, digits: u16) -> T {
let span = span_for_digits(digits);
let rem = self.nanosecond() % span;
if rem > 0 {
let rev = span - rem;
if rev <= rem {
self + Duration::nanoseconds(rev.into()) // up
let delta_down = self.nanosecond() % span;
if delta_down > 0 {
let delta_up = span - delta_down;
if delta_up <= delta_down {
self + Duration::nanoseconds(delta_up.into())
} else {
self - Duration::nanoseconds(rem.into()) // down
self - Duration::nanoseconds(delta_down.into())
}
} else {
self // unchanged
@ -42,9 +42,9 @@ where T: Timelike + Add<Duration, Output=T> + Sub<Duration, Output=T>
fn trunc(self, digits: u16) -> T {
let span = span_for_digits(digits);
let rem = self.nanosecond() % span;
if rem > 0 {
self - Duration::nanoseconds(rem.into()) // truncate
let delta_down = self.nanosecond() % span;
if delta_down > 0 {
self - Duration::nanoseconds(delta_down.into())
} else {
self // unchanged
}