code: private String periodToString(Period period) {
          String retVal;
          if (period.getYears() > 0) {
              int weeks = Math.abs(period.getYears()) * 52;
              if (period.getYears() < 0) {
                  weeks = -weeks;
              }
              retVal = String.format("P%dW", weeks);
          } else if (period.getMonths() > 0) {
              int weeks = Math.abs(period.getMonths()) * 4;
              if (period.getMonths() < 0) {
                  weeks = -weeks;
              }
              retVal = String.format("P%dW", weeks);
          } else if (period.getDays() % 7 == 0) {
              int weeks = Math.abs(period.getDays()) / 7;
              if (period.getDays() < 0) {
                  weeks = -weeks;
              }
              retVal = String.format("P%dW", weeks);
          } else {
              retVal = period.toString();
          }
          return retVal;
      }
docs: As the {@link Period} implementation doesn't support string representation in weeks, but does support
  years and months, we need to generate a string that converts years, months and days to weeks.
  
  @param period a period instance
  @return a string representation of the period that is compliant with the RFC5545 specification.