DateTimeUtils { static public long parseDuration(String strDuration) { String[] durations = strDuration.split("\\s"); long duration = 0; for (String singleDuration : durations) { StringBuilder bldvalue = new StringBuilder(""); for (int i = 0; i < singleDuration.length(); i++) { char c = strDuration.charAt(i); if (Character.isDigit(c)) { bldvalue.append(c); } else if (Character.isLetter(c) && !bldvalue.toString().isEmpty()) { duration += calcDuration(Integer.parseInt(bldvalue.toString()), c); bldvalue.setLength(0); bldvalue.append(""); break; } } } return duration; } private  DateTimeUtils(); static String timestampToHumanDateAndTimeLocal(long timestamp); static String timestampToHumanDateAndTimeAde(long timestamp); static String timestampToHumanDateAndTimeUTC(long timestamp); static String millisecondsToHumanTime(long period); static String millisecondsToDecimalHumanTime(long period); static long getDayStartTimeLocal(long startTime); static String timestampToHumanDateAndTimeAndStampLocal(long time); static String timestampToHumanDateAndTimeAndStampUTC(long time); static long getTimeStampLocal(int year, int month, int day, double frac); static Date getCurrentDate(); static TimeZone parseTimeZone(String id); static SimpleDateFormat getNewGmtSimpleDateFormat(String format); static SimpleDateFormat getNewGmtSimpleDateFormat(String format, boolean lenient); static Calendar getGmtGregorianCalendar(); static Calendar getGmtGregorianCalendar(int year, int month, int dayOfMonth); static long parseDuration(String strDuration); static final long SECONDS_IN_MINUTE; static final long MINUTES_IN_HOUR; static final long HOURS_IN_DAY; static final long DAYS_IN_WEEK; static final long MILLIS_IN_SECOND; static final long HALF_MILLIS_IN_SECOND; static final long MILLIS_IN_MINUTE; static final long MILLIS_IN_HOUR; static final long MILLIS_IN_DAY; static final long MILLIS_IN_WEEK; static final TimeZone GMT_TIMEZONE; static final LazyObj<TimeZone> ADE_TIMEZONE; }
@Test public void testParseDurationEmpty() throws AdeUsageException{ assertEquals("Parsing duration with an empty string ",0,DateTimeUtils.parseDuration("")); }
@Test public void testParseDurationBadString() throws AdeUsageException{ assertEquals("Parsing duration with a bad string ",0,DateTimeUtils.parseDuration("abc")); }
@Test public void testParseDurationDigit() throws AdeUsageException{ assertEquals("Parsing duration with a digit as a string ",0,DateTimeUtils.parseDuration("1")); }
@Test public void testParseDurationLetter() throws AdeUsageException{ assertEquals("Parsing duration with a letter as a string ",0,DateTimeUtils.parseDuration("A")); }
@Test public void testParseDuration1m() throws AdeUsageException{ assertEquals("Parsing duration 1m (minute) ",60000,DateTimeUtils.parseDuration("1m")); }
@Test public void testParseDuration1H() throws AdeUsageException{ assertEquals("Parsing duration 1H (1 hour) ",3600000,DateTimeUtils.parseDuration("1H")); }
@Test public void testParseDuration1D() throws AdeUsageException{ assertEquals("Parsing duration 1D (1 day) ",86400000,DateTimeUtils.parseDuration("1D")); }
@Test public void testParseDuration1W() throws AdeUsageException{ assertEquals("Parsing duration 1W (1 week)",604800000,DateTimeUtils.parseDuration("1W")); }
@Test(expected = IllegalArgumentException.class) public void testParseDurationBadInput() throws AdeUsageException{ assertEquals("Parsing duration with a bad input ",0,DateTimeUtils.parseDuration("1a")); }