Add handy methods

FEA: ItEr67S04BugFixing
This commit is contained in:
Óscar González Fernández 2011-01-03 13:10:34 +01:00
parent 10007fe114
commit 8fc16549b2
2 changed files with 32 additions and 0 deletions

View file

@ -371,4 +371,20 @@ public class IntraDayDate implements Comparable<IntraDayDate> {
return IntraDayDate.startOfDay(getDate().minusDays(1));
}
/**
* @return the next day or the same day if this {@link IntraDayDate} has no
* duration.
*/
public LocalDate roundUp() {
return asExclusiveEnd();
}
/**
* @return A date resulting of striping this {@link IntraDayDate} of its
* duration
*/
public LocalDate roundDown() {
return date;
}
}

View file

@ -278,4 +278,20 @@ public class IntraDayDateTest {
}
};
}
@Test
public void roundsUpGoesToTheNextLocalDateOrKeepsTheSame() {
assertThat(IntraDayDate.create(today, halfHour).roundUp(),
equalTo(today.plusDays(1)));
assertThat(IntraDayDate.startOfDay(today).roundUp(), equalTo(today));
}
@Test
public void roundDownGoesToPreviousLocalDateOrKeepsTheSame() {
assertThat(IntraDayDate.create(today, halfHour).roundDown(),
equalTo(today));
assertThat(IntraDayDate.startOfDay(today).roundDown(), equalTo(today));
}
}