TimeMathParser { @SuppressWarnings("WeakerAccess") public static int resolutionInSeconds(String resolutionStr) { Matcher matcher = RESOLUTION_PATTERN.matcher(resolutionStr); int output = 0; while (matcher.find()) { output += TimeUnit.MILLISECONDS.toSeconds(convertToMilliseconds(Long.parseLong(matcher.group(1)), matcher.group(2))); } return output; }  @SuppressWarnings({"unused", "WeakerAccess"}) static long nowInSeconds(); @SuppressWarnings("WeakerAccess") static int resolutionInSeconds(String resolutionStr); @SuppressWarnings("WeakerAccess") static long parseTimeInSeconds(String timeStr); @SuppressWarnings("WeakerAccess") static long parseTime(String timeStr, TimeUnit timeUnit); @SuppressWarnings("WeakerAccess") static long parseTimeInSeconds(long now, String timeStr); @SuppressWarnings("WeakerAccess") static long parseTime(long now, String timeStr, TimeUnit timeUnit);  }
@Test public void testResolutionParsing() { String resolution = "60s"; Assert.assertEquals(60, TimeMathParser.resolutionInSeconds(resolution)); resolution = "2m"; Assert.assertEquals(120, TimeMathParser.resolutionInSeconds(resolution)); resolution = "3h"; Assert.assertEquals(10800, TimeMathParser.resolutionInSeconds(resolution)); resolution = "1d"; Assert.assertEquals(86400, TimeMathParser.resolutionInSeconds(resolution)); resolution = "1h3m"; Assert.assertEquals(3780, TimeMathParser.resolutionInSeconds(resolution)); }