code: private String durationToString(Duration duration) {
          String retVal = null;
          Duration absDuration = duration.abs();
          int days = 0;
          if (absDuration.getSeconds() != 0) {
              days = (int) absDuration.getSeconds() / (24 * 60 * 60);
          }
  
          if (days != 0) {
              Duration durationMinusDays = absDuration.minusDays(days);
              if (durationMinusDays.getSeconds() != 0) {
                  int hours = (int) durationMinusDays.getSeconds() / (60 * 60);
                  int minutes = (int) durationMinusDays.minusHours(hours).getSeconds() / 60;
                  int seconds = (int) durationMinusDays.minusHours(hours).minusMinutes(minutes).getSeconds();
                  if (hours > 0) {
                      if (seconds > 0) {
                          retVal = String.format("P%dDT%dH%dM%dS", days, hours, minutes, seconds);
                      } else {
                          retVal = String.format("P%dDT%dH", days, hours);
                      }
                  } else if (minutes > 0) {
                      retVal = String.format("P%dDT%dM", days, minutes);
                  } else if (seconds > 0) {
                      retVal = String.format("P%dDT%dS", days, seconds);
                  }
              } else {
                  retVal = String.format("P%dD", days);
              }
          } else {
              retVal = absDuration.toString();
          }
  
          if (duration.isNegative()) {
              return "-" + retVal;
          } else {
              return retVal;
          }
      }
docs: As the {@link Duration} implementation doesn't support string representation in days (to avoid
  confusion with {@link Period}), we need to generate a string that does support days.
  
  @param duration a duration instance
  @return a string representation of the duration that is compliant with the RFC5545 specification.