static String formatDuration(long durationInMinutes) {
    if (durationInMinutes == 0) {
      return ZERO;
    }
    double days = (double) durationInMinutes / DURATION_HOURS_IN_DAY / DURATION_OF_ONE_HOUR_IN_MINUTES;
    if (days > DURATION_ALMOST_ONE) {
      return format(DURATION_DAYS_FORMAT, Math.round(days));
    }
    double remainingDuration = durationInMinutes - (Math.floor(days) * DURATION_HOURS_IN_DAY * DURATION_OF_ONE_HOUR_IN_MINUTES);
    double hours = remainingDuration / DURATION_OF_ONE_HOUR_IN_MINUTES;
    if (hours > DURATION_ALMOST_ONE) {
      return format(DURATION_HOURS_FORMAT, Math.round(hours));
    }
    double minutes = remainingDuration - (Math.floor(hours) * DURATION_OF_ONE_HOUR_IN_MINUTES);
    return format(DURATION_MINUTES_FORMAT, Math.round(minutes));
  }
@Test
  public void format_duration_is_rounding_result() {
    // When starting to add more than 4 hours, the result will be rounded to the next day (as 4 hour is a half day)
    assertThat(formatDuration(5 * ONE_DAY + 4 * ONE_HOUR)).isEqualTo("6d");
    assertThat(formatDuration(5 * ONE_DAY + 5 * ONE_HOUR)).isEqualTo("6d");

    // When starting to add more than 30 minutes, the result will be rounded to the next hour
    assertThat(formatDuration(3 * ONE_HOUR + 30 * ONE_MINUTE)).isEqualTo("4h");
    assertThat(formatDuration(3 * ONE_HOUR + 40 * ONE_MINUTE)).isEqualTo("4h");

    // When duration is close to next unit (0.9), the result is rounded to next unit
    assertThat(formatDuration(7 * ONE_HOUR + 20 + ONE_MINUTE)).isEqualTo("1d");
    assertThat(formatDuration(55 * ONE_MINUTE)).isEqualTo("1h");
  }