/** * Thread safe utility method to parse a Date with {@link #userDateFormats} first, then {@link #DEFAULT_DATE_FORMATS}. * <p> * Returns <code>null</code> if dateAsString parameter is <code>null</code>. * * @param dateAsString the string to parse as a Date with {@link #userDateFormats} * @return the corresponding Date, null if dateAsString parameter is null. * @throws AssertionError if the string can't be parsed as a Date */ @VisibleForTesting Date parse(String dateAsString) { if (dateAsString == null) return null; // parse with date format specified by user if any, otherwise use default formats // no synchronization needed as userCustomDateFormat is thread local Date date = parseDateWith(dateAsString, userDateFormats.get()); if (date != null) return date; // no matching user date format, let's try default format date = parseDateWithDefaultDateFormats(dateAsString); if (date != null) return date; // no matching date format, throw an error throw new AssertionError(String.format("Failed to parse %s with any of these date formats:%n %s", dateAsString, info.representation().toStringOf(dateFormatsInOrderOfUsage()))); }
/** * Thread safe utility method to parse a Date with {@link #userDateFormats} first, then {@link #DEFAULT_DATE_FORMATS}. * <p> * Returns <code>null</code> if dateAsString parameter is <code>null</code>. * * @param dateAsString the string to parse as a Date with {@link #userDateFormats} * @return the corresponding Date, null if dateAsString parameter is null. * @throws AssertionError if the string can't be parsed as a Date */ @VisibleForTesting Date parse(String dateAsString) { if (dateAsString == null) return null; // parse with date format specified by user if any, otherwise use default formats // no synchronization needed as userCustomDateFormat is thread local Date date = parseDateWith(dateAsString, userDateFormats.get()); if (date != null) return date; // no matching user date format, let's try default format date = parseDateWithDefaultDateFormats(dateAsString); if (date != null) return date; // no matching date format, throw an error throw new AssertionError(String.format("Failed to parse %s with any of these date formats:%n %s", dateAsString, info.representation().toStringOf(dateFormatsInOrderOfUsage()))); }
/** * Thread safe utility method to parse a Date with {@link #userDateFormats} first, then {@link #DEFAULT_DATE_FORMATS}. * <p> * Returns <code>null</code> if dateAsString parameter is <code>null</code>. * * @param dateAsString the string to parse as a Date with {@link #userDateFormats} * @return the corresponding Date, null if dateAsString parameter is null. * @throws AssertionError if the string can't be parsed as a Date */ @VisibleForTesting Date parse(String dateAsString) { if (dateAsString == null) return null; // parse with date format specified by user if any, otherwise use default formats // no synchronization needed as userCustomDateFormat is thread local Date date = parseDateWith(dateAsString, userDateFormats.get()); if (date != null) return date; // no matching user date format, let's try default format date = parseDateWithDefaultDateFormats(dateAsString); if (date != null) return date; // no matching date format, throw an error throw new AssertionError("Failed to parse " + dateAsString + " with any of these date formats: " + info.representation().toStringOf(dateFormatsInOrderOfUsage())); }