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() {
    assertThat(formatDuration(0)).isEqualTo("0");
    assertThat(formatDuration(ONE_DAY)).isEqualTo("1d");
    assertThat(formatDuration(ONE_HOUR)).isEqualTo("1h");
    assertThat(formatDuration(ONE_MINUTE)).isEqualTo("1min");

    assertThat(formatDuration(5 * ONE_DAY)).isEqualTo("5d");
    assertThat(formatDuration(2 * ONE_HOUR)).isEqualTo("2h");
    assertThat(formatDuration(ONE_MINUTE)).isEqualTo("1min");

    assertThat(formatDuration(5 * ONE_DAY + 3 * ONE_HOUR)).isEqualTo("5d");
    assertThat(formatDuration(3 * ONE_HOUR + 25 * ONE_MINUTE)).isEqualTo("3h");
    assertThat(formatDuration(5 * ONE_DAY + 3 * ONE_HOUR + 40 * ONE_MINUTE)).isEqualTo("5d");
  }