### Question:
TimeParser { static long parsePeriod(final String period) throws ParseException { final int length = period.length(); if (length!=0 && Character.toUpperCase(period.charAt(0)) != 'P') { throw new ParseException(Errors.format(Errors.Keys.UnparsableString_2, period, period.substring(0,1)), 0); } long millis = 0; boolean time = false; int lower = 0; while (++lower < length) { char letter = Character.toUpperCase(period.charAt(lower)); if (letter == 'T') { time = true; if (++lower >= length) { break; } } int upper = lower; letter = period.charAt(upper); while (!Character.isLetter(letter) || letter == 'e' || letter == 'E') { if (++upper >= length) { throw new ParseException(Errors.format(Errors.Keys.UnexpectedEndOfString), lower); } letter = period.charAt(upper); } letter = Character.toUpperCase(letter); final String number = period.substring(lower, upper); final double value; try { value = Double.parseDouble(number); } catch (NumberFormatException exception) { final ParseException e = new ParseException(Errors.format( Errors.Keys.UnparsableNumber_1, number), lower); e.initCause(exception); throw e; } final double factor; if (time) { switch (letter) { case 'S': factor = 1000; break; case 'M': factor = 60*1000; break; case 'H': factor = 60*60*1000; break; default: throw new ParseException("Unknown time symbol: " + letter, upper); } } else { switch (letter) { case 'D': factor = MILLIS_IN_DAY; break; case 'W': factor = 7 * MILLIS_IN_DAY; break; case 'M': factor = 30 * MILLIS_IN_DAY; break; case 'Y': factor = 365.25 * MILLIS_IN_DAY; break; default: throw new ParseException("Unknown period symbol: " + letter, upper); } } millis += Math.round(value * factor); lower = upper; } return millis; } private  TimeParser(final String pattern); static void parse(String value, final long defaultPeriod, final List<Date> dates); static Date toDate(final String strTime); @Override boolean equals(final Object other); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void testPeriod() throws ParseException { final long millisInDay = TimeParser.MILLIS_IN_DAY; assertEquals( millisInDay, TimeParser.parsePeriod("P1D")); assertEquals( 3*millisInDay, TimeParser.parsePeriod("P3D")); assertEquals( 14*millisInDay, TimeParser.parsePeriod("P2W")); assertEquals( 8*millisInDay, TimeParser.parsePeriod("P1W1D")); assertEquals( millisInDay, TimeParser.parsePeriod("PT24H")); assertEquals(Math.round(1.5*millisInDay), TimeParser.parsePeriod("P1.5D")); }