title: How to convert ISO 8601 period to a string readable by humans [Android Studio]?
body: <p>Any suggestions on how to convert the <a href="https://en.wikipedia.org/wiki/ISO_8601#Durations" rel="noreferrer">ISO 8601 duration</a> format  <code>PnYnMnDTnHnMnS</code> (ex: P1W, P5D, P3D) to number of days?</p>
  
  <p>I'm trying to set the text of a button in a way that the days of free trial are displayed to the user.</p>
  
  <p>Google provides the billing information in the ISO 8601 duration format  through the key "freeTrialPeriod", but I need it in numbers the user can actually read.</p>
  
  <p>The current minimum API level of the app is 18, so the Duration and Period classes from Java 8 won't help, since they are meant for APIs equal or greater than 26.</p>
  
  <p>I have set the following method as a workaround, but it doesn't look like the best solution:</p>
  
  <pre><code>private String getTrialPeriodMessage() {
          String period = "";
  
          try {
              period = subsInfoObjects.get(SUBS_PRODUCT_ID).getString("freeTrialPeriod");
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          switch (period) {
              case "P1W":
                  period = "7";
                  break;
              case "P2W":
                  period = "14";
                  break;
              case "P3W":
                  period = "21";
                  break;
              case "P4W":
                  period = "28";
                  break;
              case "P7D":
                  period = "7";
                  break;
              case "P6D":
                  period = "6";
                  break;
              case "P5D":
                  period = "5";
                  break;
              case "P4D":
                  period = "4";
                  break;
              case "P3D":
                  period = "3";
                  break;
              case "P2D":
                  period = "2";
                  break;
              case "P1D":
                  period = "1";
          }
  
          return getString(R.string.continue_with_free_trial, period);
      }
  </code></pre>
  
  <p>Any suggestions on how to improve it?</p>
  
  <p>Thanks!</p>