Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FormatDurationUnitTest {


@Test
public void givenInterval_WhenFormatInterval_formatDuration() {
public void givenInterval_whenFormatInterval_thenFormatDuration() {
long HH = TimeUnit.MILLISECONDS.toHours(38114000);
long MM = TimeUnit.MILLISECONDS.toMinutes(38114000) % 60;
long SS = TimeUnit.MILLISECONDS.toSeconds(38114000) % 60;
Expand All @@ -23,7 +23,16 @@ public void givenInterval_WhenFormatInterval_formatDuration() {
}

@Test
public void givenInterval_WhenFormatUsingDuration_formatDuration() {
public void givenIntMinutes_whenConvertUsingTimeUnit_thenFormatHHMM() {
int totalMinutes = 155;
long hours = TimeUnit.MINUTES.toHours(totalMinutes);
long remainingMinutes = totalMinutes - TimeUnit.HOURS.toMinutes(hours);
String timeInHHMM = String.format("%02d:%02d", hours, remainingMinutes);
assertThat(timeInHHMM).isEqualTo("02:35");
}

@Test
public void givenInterval_whenFormatUsingDuration_thenFormatDuration() {
Duration duration = Duration.ofMillis(38114000);
long seconds = duration.getSeconds();
long HH = seconds / 3600;
Expand All @@ -32,16 +41,15 @@ public void givenInterval_WhenFormatUsingDuration_formatDuration() {
String timeInHHMMSS = String.format("%02d:%02d:%02d", HH, MM, SS);
assertThat(timeInHHMMSS).isEqualTo("10:35:14");
}



@Test
public void givenInterval_WhenFormatDurationUsingApacheCommons_formatDuration() {
public void givenInterval_whenFormatDurationUsingApacheCommons_thenFormatDuration() {
assertThat(DurationFormatUtils.formatDuration(38114000, "HH:mm:ss"))
.isEqualTo("10:35:14");
}

@Test
public void givenInterval_WhenFormatDurationUsingJodaTime_formatDuration() {
public void givenInterval_whenFormatDurationUsingJodaTime_thenFormatDuration() {
org.joda.time.Duration duration = new org.joda.time.Duration(38114000);
Period period = duration.toPeriod();
long HH = period.getHours();
Expand Down