### Question:
PeriodUtilities { public long getTimeFromPeriodDescription(String periodDescription) { long time = 0; periodDescription = periodDescription.substring(1); if (periodDescription.indexOf('Y') != -1) { final int nbYear = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('Y'))); time += nbYear * YEAR_MS; periodDescription = periodDescription.substring(periodDescription.indexOf('Y') + 1); } if ( periodDescription.indexOf('M') != -1 && (periodDescription.indexOf('T') == -1 || periodDescription.indexOf('T') > periodDescription.indexOf('M')) ) { final int nbMonth = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); time += nbMonth * MONTH_MS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('W') != -1) { final int nbWeek = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('W'))); time += nbWeek * WEEK_MS; periodDescription = periodDescription.substring(periodDescription.indexOf('W') + 1); } if (periodDescription.indexOf('D') != -1) { final int nbDay = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('D'))); time += nbDay * DAY_MS; periodDescription = periodDescription.substring(periodDescription.indexOf('D') + 1); } if (periodDescription.indexOf('T') != -1) { periodDescription = periodDescription.substring(1); } if (periodDescription.indexOf('H') != -1) { final int nbHour = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('H'))); time += nbHour * HOUR_MS; periodDescription = periodDescription.substring(periodDescription.indexOf('H') + 1); } if (periodDescription.indexOf('M') != -1) { final int nbMin = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); time += nbMin * MINUTE_MS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('S') != -1) { if (periodDescription.indexOf('.') != -1) { final int nbSec = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('.'))); time += nbSec * SECOND_MS; periodDescription = periodDescription.substring(periodDescription.indexOf('.') + 1); final int nbMSec = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('S'))); time += nbMSec; periodDescription = periodDescription.substring(periodDescription.indexOf('S') + 1); } else { final int nbSec = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('S'))); time += nbSec * SECOND_MS; periodDescription = periodDescription.substring(periodDescription.indexOf('S') + 1); } } if (periodDescription.length() != 0) { throw new IllegalArgumentException("The period descritpion is malformed"); } return time; } PeriodUtilities(final DateFormat dateFormat); String getDatesRespresentation(final SortedSet<Date> dates); String getPeriodDescription(final SortedSet<Date> dates, long gap); SortedSet<Date> getDatesFromPeriodDescription(final String periods); long getTimeFromPeriodDescription(String periodDescription);  }### Answer:
@Test public void getTimeFromPeriodDescription() { DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); df.setTimeZone(TimeZone.getTimeZone("GMT+0")); PeriodUtilities instance = new PeriodUtilities(df); String periodDescription = "P1W1D"; long expResult = 604800000L + 86400000L; long result = instance.getTimeFromPeriodDescription(periodDescription); assertEquals(expResult, result); }