/** * <p>Formats the time gap as a string.</p> * * <p>The format used is the ISO 8601 period format.</p> * * @param startMillis the start of the duration to format * @param endMillis the end of the duration to format * @return the formatted duration, not null * @throws java.lang.IllegalArgumentException if startMillis is greater than endMillis */ public static String formatPeriodISO(final long startMillis, final long endMillis) { return formatPeriod(startMillis, endMillis, ISO_EXTENDED_FORMAT_PATTERN, false, TimeZone.getDefault()); }
/** * <p>Formats the time gap as a string, using the specified format. * Padding the left hand side of numbers with zeroes is optional. * * @param startMillis the start of the duration * @param endMillis the end of the duration * @param format the way in which to format the duration, not null * @return the formatted duration, not null * @throws java.lang.IllegalArgumentException if startMillis is greater than endMillis */ public static String formatPeriod(final long startMillis, final long endMillis, final String format) { return formatPeriod(startMillis, endMillis, format, true, TimeZone.getDefault()); }
@Test(expected = IllegalArgumentException.class) public void testFormatPeriodeStartGreaterEnd() throws Exception { DurationFormatUtils.formatPeriod(5000, 2500, "yy/MM"); }
@Test public void testLANG815() { final Calendar calendar = Calendar.getInstance(); calendar.set(2012, Calendar.JULY, 30, 0, 0, 0); final long startMillis = calendar.getTimeInMillis(); calendar.set(2012, Calendar.SEPTEMBER, 8); final long endMillis = calendar.getTimeInMillis(); assertEquals("1 9", DurationFormatUtils.formatPeriod(startMillis, endMillis, "M d")); }
private void assertEqualDuration(final String message, final String expected, final int[] start, final int[] end, final String format) { final Calendar cal1 = Calendar.getInstance(); cal1.set(start[0], start[1], start[2], start[3], start[4], start[5]); cal1.set(Calendar.MILLISECOND, 0); final Calendar cal2 = Calendar.getInstance(); cal2.set(end[0], end[1], end[2], end[3], end[4], end[5]); cal2.set(Calendar.MILLISECOND, 0); final long milli1 = cal1.getTime().getTime(); final long milli2 = cal2.getTime().getTime(); final String result = DurationFormatUtils.formatPeriod(milli1, milli2, format); if (message == null) { assertEquals(expected, result); } else { assertEquals(message, expected, result); } }
@SuppressWarnings("deprecation") @Test public void testFormatPeriodISO() { final TimeZone timeZone = TimeZone.getTimeZone("GMT-3"); final Calendar base = Calendar.getInstance(timeZone); base.set(1970, Calendar.JANUARY, 1, 0, 0, 0); base.set(Calendar.MILLISECOND, 0); final Calendar cal = Calendar.getInstance(timeZone); cal.set(2002, Calendar.FEBRUARY, 23, 9, 11, 12); cal.set(Calendar.MILLISECOND, 1); String text; // repeat a test from testDateTimeISO to compare extended and not extended. text = DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), timeZone); assertEquals("2002-02-23T09:11:12-03:00", text); // test fixture is the same as above, but now with extended format. text = DurationFormatUtils.formatPeriod(base.getTime().getTime(), cal.getTime().getTime(), DurationFormatUtils.ISO_EXTENDED_FORMAT_PATTERN, false, timeZone); assertEquals("P32Y1M22DT9H11M12.001S", text); // test fixture from example in http://www.w3.org/TR/xmlschema-2/#duration cal.set(1971, Calendar.FEBRUARY, 3, 10, 30, 0); cal.set(Calendar.MILLISECOND, 0); text = DurationFormatUtils.formatPeriod(base.getTime().getTime(), cal.getTime().getTime(), DurationFormatUtils.ISO_EXTENDED_FORMAT_PATTERN, false, timeZone); assertEquals("P1Y1M2DT10H30M0.000S", text); // want a way to say 'don't print the seconds in format()' or other fields for that matter: // assertEquals("P1Y2M3DT10H30M", text); }
assertEquals("0", DurationFormatUtils.formatPeriod(time1970, time1970, "y")); assertEquals("0", DurationFormatUtils.formatPeriod(time1970, time1970, "M")); assertEquals("0", DurationFormatUtils.formatPeriod(time1970, time1970, "d")); assertEquals("0", DurationFormatUtils.formatPeriod(time1970, time1970, "H")); assertEquals("0", DurationFormatUtils.formatPeriod(time1970, time1970, "m")); assertEquals("0", DurationFormatUtils.formatPeriod(time1970, time1970, "s")); assertEquals("0", DurationFormatUtils.formatPeriod(time1970, time1970, "S")); assertEquals("0000", DurationFormatUtils.formatPeriod(time1970, time1970, "SSSS")); assertEquals("0000", DurationFormatUtils.formatPeriod(time1970, time1970, "yyyy")); assertEquals("0000", DurationFormatUtils.formatPeriod(time1970, time1970, "yyMM")); assertEquals("0", DurationFormatUtils.formatPeriod(time1970, time, "y")); assertEquals("0", DurationFormatUtils.formatPeriod(time1970, time, "M")); assertEquals("0", DurationFormatUtils.formatPeriod(time1970, time, "d")); assertEquals("0", DurationFormatUtils.formatPeriod(time1970, time, "H")); assertEquals("1", DurationFormatUtils.formatPeriod(time1970, time, "m")); assertEquals("60", DurationFormatUtils.formatPeriod(time1970, time, "s")); assertEquals("60000", DurationFormatUtils.formatPeriod(time1970, time, "S")); assertEquals("01:00", DurationFormatUtils.formatPeriod(time1970, time, "mm:ss")); cal.set(Calendar.MILLISECOND, 0); time = cal.getTime().getTime(); assertEquals("36", DurationFormatUtils.formatPeriod(time1970, time, "yM")); assertEquals("3 years 6 months", DurationFormatUtils.formatPeriod(time1970, time, "y' years 'M' months'")); assertEquals("03/06", DurationFormatUtils.formatPeriod(time1970, time, "yy/MM")); assertEquals("310", DurationFormatUtils.formatPeriod(time1970, time, "yM")); assertEquals("3 years 10 months", DurationFormatUtils.formatPeriod(time1970, time, "y' years 'M' months'")); assertEquals("03/10", DurationFormatUtils.formatPeriod(time1970, time, "yy/MM"));
/** * <p>Formats the time gap as a string.</p> * * <p>The format used is the ISO 8601 period format.</p> * * @param startMillis the start of the duration to format * @param endMillis the end of the duration to format * @return the formatted duration, not null * @throws java.lang.IllegalArgumentException if startMillis is greater than endMillis */ public static String formatPeriodISO(final long startMillis, final long endMillis) { return formatPeriod(startMillis, endMillis, ISO_EXTENDED_FORMAT_PATTERN, false, TimeZone.getDefault()); }
/** * <p>Formats the time gap as a string, using the specified format. * Padding the left hand side of numbers with zeroes is optional. * * @param startMillis the start of the duration * @param endMillis the end of the duration * @param format the way in which to format the duration, not null * @return the formatted duration, not null * @throws java.lang.IllegalArgumentException if startMillis is greater than endMillis */ public static String formatPeriod(final long startMillis, final long endMillis, final String format) { return formatPeriod(startMillis, endMillis, format, true, TimeZone.getDefault()); }
/** * <p>Formats the time gap as a string.</p> * * <p>The format used is the ISO 8601 period format.</p> * * @param startMillis the start of the duration to format * @param endMillis the end of the duration to format * @return the formatted duration, not null * @throws java.lang.IllegalArgumentException if startMillis is greater than endMillis */ public static String formatPeriodISO(final long startMillis, final long endMillis) { return formatPeriod(startMillis, endMillis, ISO_EXTENDED_FORMAT_PATTERN, false, TimeZone.getDefault()); }
/** * <p>Formats the time gap as a string, using the specified format. * Padding the left hand side of numbers with zeroes is optional. * * @param startMillis the start of the duration * @param endMillis the end of the duration * @param format the way in which to format the duration, not null * @return the formatted duration, not null * @throws java.lang.IllegalArgumentException if startMillis is greater than endMillis */ public static String formatPeriod(final long startMillis, final long endMillis, final String format) { return formatPeriod(startMillis, endMillis, format, true, TimeZone.getDefault()); }
/** * <p>Formats the time gap as a string.</p> * * <p>The format used is the ISO 8601 period format.</p> * * @param startMillis the start of the duration to format * @param endMillis the end of the duration to format * @return the formatted duration, not null * @throws java.lang.IllegalArgumentException if startMillis is greater than endMillis */ public static String formatPeriodISO(final long startMillis, final long endMillis) { return formatPeriod(startMillis, endMillis, ISO_EXTENDED_FORMAT_PATTERN, false, TimeZone.getDefault()); }
/** * <p>Formats the time gap as a string, using the specified format. * Padding the left hand side of numbers with zeroes is optional. * * @param startMillis the start of the duration * @param endMillis the end of the duration * @param format the way in which to format the duration, not null * @return the formatted duration, not null * @throws java.lang.IllegalArgumentException if startMillis is greater than endMillis */ public static String formatPeriod(final long startMillis, final long endMillis, final String format) { return formatPeriod(startMillis, endMillis, format, true, TimeZone.getDefault()); }
public static String getDuration(Date startDate, Date endDate, String format) { String duration = ""; if (startDate != null && endDate != null && !startDate.after(endDate)) { duration = DurationFormatUtils.formatPeriod( startDate.getTime(), endDate.getTime(), format); } return duration; }
public static String getDuration(Date startDate, Date endDate, String format) { String duration = ""; if (startDate != null && endDate != null && !startDate.after(endDate)) { duration = DurationFormatUtils.formatPeriod( startDate.getTime(), endDate.getTime(), format); } return duration; } }
public boolean run() { long startOfTestsMs = nanoTime(); try { deleteDirectory(output); //noinspection ResultOfMethodCallIgnored output.mkdirs(); return forkRunner.run(); } catch (Exception e) { logger.error("Error while running Fork", e); return false; } finally { long duration = millisSinceNanoTime(startOfTestsMs); logger.info(formatPeriod(0, duration, "'Total time taken:' H 'hours' m 'minutes' s 'seconds'")); adb().terminate(); } } }
final String formatDuration = DurationFormatUtils.formatPeriod(startMillis, endMillis, DURATION_FORMAT, false, getBrowserTimeZone());
final String formatDuration = DurationFormatUtils.formatPeriod(startMillis, endMillis, DURATION_FORMAT, false, getBrowserTimeZone());
} finally { long duration = millisSinceNanoTime(startOfTestsMs); logger.info(formatPeriod(0, duration, "'Total time taken:' H 'hours' m 'minutes' s 'seconds'")); adb.terminate();