DateTimeUtil { public static Calendar parseDate(final String date, final boolean withTime) { return parseDate(date, withTime ? PATTERN_CZ_DATETIME : PATTERN_CZ_DATE); } private  DateTimeUtil(); static String formatDuration(final long duration, final boolean longFormat, final boolean trimZeros); static Date now(); static Date nowZeroSec(); static Calendar nowCalendar(); static Date today(); static Calendar todayCalendar(); static Date yesterday(); static Calendar yesterdayCalendar(); static Date addTime(final Date date, final int period, final int amount); static Calendar addTimeCalendar(final Calendar calendar, final int period, final int amount); static Calendar date2calendar(final Date date); static Calendar parseDate(final String date, final boolean withTime); static Calendar parseDate(final String date, final String pattern); static Calendar parseISODateTime(final String dateTime); static Calendar parseDefaultISODateTime(final String dateTime); static String formatDate(final Date date, final boolean withTime); static String formatDate(final Date date, final String pattern); static String formatDateByLocale(final Date date, Locale locale, int style); static String formatDateTimeByLocale(final Date date, Locale locale, int style); static int extractYear(final Date date); static int getFirstDayOfWeek(Locale locale); static boolean inPast(Date time); static Date getMidnight(Date time); static final String PATTERN_CZ_DATE; static final String PATTERN_CZ_DATETIME; static final String PATTERN_CZ_TIME; static final String PATTERN_LOG; }
@Test public void testParseDateStringBoolean() { assertNull(DateTimeUtil.parseDate(null, true)); assertNull(DateTimeUtil.parseDate(null, true)); try { DateTimeUtil.parseDate("30.12.2010 13:59:59.999", true); fail(); } catch (IllegalArgumentException expected) { } assertEquals(testDateTime.getMillis(), DateTimeUtil.parseDate("30.12.2010 13:59:59", true).getTimeInMillis()); assertEquals(testDate.getMillis(), DateTimeUtil.parseDate("30.12.2010", false).getTimeInMillis()); }
@Test public void testParseDateStringString() { assertNull(DateTimeUtil.parseDate(null, DateTimeUtil.PATTERN_CZ_DATE)); assertNull(DateTimeUtil.parseDate("", null)); try { DateTimeUtil.parseDate("30.12.2010 13:59:59.999", DateTimeUtil.PATTERN_CZ_DATETIME); fail(); } catch (IllegalArgumentException expected) { } assertEquals(testDateTime.getMillis(), DateTimeUtil.parseDate("30.12.2010 13:59:59", DateTimeUtil.PATTERN_CZ_DATETIME) .getTimeInMillis()); assertEquals(testDate.getMillis(), DateTimeUtil.parseDate("30.12.2010", DateTimeUtil.PATTERN_CZ_DATE).getTimeInMillis()); }