Refine search
@Override public StdDateFormat clone() { // Although there is that much state to share, we do need to // orchestrate a bit, mostly since timezones may be changed return new StdDateFormat(_timezone, _locale, _lenient, _tzSerializedWithColon); }
private static long parseDateToMillisecs(String valueAsText) { try { return Long.parseLong(valueAsText); } catch (NumberFormatException nfe) { try { return new StdDateFormat().parse(valueAsText).getTime(); } catch (ParseException pe) { throw new IllegalArgumentException("Unable to parse this string as a date: " + valueAsText); } } }
protected Date _parseDate(String dateStr, ParsePosition pos) throws ParseException { if (looksLikeISO8601(dateStr)) { // also includes "plain" return parseAsISO8601(dateStr, pos); } // Also consider "stringified" simple time stamp int i = dateStr.length(); while (--i >= 0) { char ch = dateStr.charAt(i); if (ch < '0' || ch > '9') { // 07-Aug-2013, tatu: And [databind#267] points out that negative numbers should also work if (i > 0 || ch != '-') { break; } } } if ((i < 0) // let's just assume negative numbers are fine (can't be RFC-1123 anyway); check length for positive && (dateStr.charAt(0) == '-' || NumberInput.inLongRange(dateStr, false))) { return _parseDateFromLong(dateStr, pos); } // Otherwise, fall back to using RFC 1123. NOTE: call will NOT throw, just returns `null` return parseAsRFC1123(dateStr, pos); }
/** * "Mutant factory" method that will return an instance that has specified leniency * setting: either {@code this} instance (if setting would not change), or newly * constructed instance. * * @since 2.9 */ public StdDateFormat withLenient(Boolean b) { if (_equals(b, _lenient)) { return this; } return new StdDateFormat(_timezone, _locale, b, _tzSerializedWithColon); }
@Override public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { if (_formatISO8601 == null) { _formatISO8601 = _cloneFormat(DATE_FORMAT_ISO8601, DATE_FORMAT_STR_ISO8601, _timezone, _locale); } return _formatISO8601.format(date, toAppendTo, fieldPosition); }
protected Date parseAsRFC1123(String dateStr, ParsePosition pos) { if (_formatRFC1123 == null) { _formatRFC1123 = _cloneFormat(DATE_FORMAT_RFC1123, DATE_FORMAT_STR_RFC1123, _timezone, _locale, _lenient); } return _formatRFC1123.parse(dateStr, pos); }
df = _formatPlain; if (df == null) { df = _formatPlain = _cloneFormat(DATE_FORMAT_PLAIN); df = _formatISO8601_z = _cloneFormat(DATE_FORMAT_ISO8601_Z); if (hasTimeZone(dateStr)) { c = dateStr.charAt(len-3); if (c == ':') { // remove optional colon df = _formatISO8601 = _cloneFormat(DATE_FORMAT_ISO8601); df = _formatISO8601_z; if (df == null) { df = _formatISO8601_z = _cloneFormat(DATE_FORMAT_ISO8601_Z); return df.parse(dateStr, pos);
private DateFormat _force(DateFormat df, TimeZone tz) { if (df instanceof StdDateFormat) { return ((StdDateFormat) df).withTimeZone(tz); } // we don't know if original format might be shared; better create a clone: df = (DateFormat) df.clone(); df.setTimeZone(tz); return df; } }
/** * {@inheritDoc} */ @Override public Date deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { final DateFormat format = new StdDateFormat(); final String text = parser.getText(); if (StringUtils.isBlank(text)) { return null; } try { return format.parse(text); } catch (final ParseException pe) { throw new IOException(pe); } } }
final Locale loc = format.hasLocale() ? format.getLocale() : ctxt.getLocale(); StdDateFormat std = (StdDateFormat) df; std = std.withTimeZone(tz); std = std.withLocale(loc); if (lenient != null) { std = std.withLenient(lenient); df = (DateFormat) df.clone(); df.setTimeZone(tz); if (lenient != null) { df.setLenient(lenient); std = std.withLenient(lenient); df = std; pattern = std.toPattern(); } else {
final Locale loc = format.hasLocale() ? format.getLocale() : ctxt.getLocale(); StdDateFormat std = (StdDateFormat) df; std = std.withTimeZone(tz); std = std.withLocale(loc); df = std; } else { df = (DateFormat) df.clone(); df.setTimeZone(tz);
@Override public Date parse(String dateStr, ParsePosition pos) { if (looksLikeISO8601(dateStr)) { // also includes "plain" return parseAsISO8601(dateStr, pos); } /* 14-Feb-2010, tatu: As per [JACKSON-236], better also * consider "stringified" simple time stamp */ int i = dateStr.length(); while (--i >= 0) { char ch = dateStr.charAt(i); if (ch < '0' || ch > '9') break; } if (i < 0) { // all digits if (NumberInput.inLongRange(dateStr, false)) { return new Date(Long.parseLong(dateStr)); } } // Otherwise, fall back to using RFC 1123 return parseAsRFC1123(dateStr, pos); }
/** * Create instance of ISO-8601 date time format using following pattern: * "yyyy-MM-dd'T'HH:mm:ss.SSSZ" Time zones in ISO-8601 are represented as * local time (with the location unspecified), as UTC, or as an offset from * UTC. If no UTC relation information is given with a time representation, * the time is assumed to be in local time. Examples, when local Time Zone * is +2: * * <pre> * 2016-12-31T22:00:00 corresponds to 2016-12-31T22:00:00+0200 in local Time Zone * 2016-12-31T22:00:00Z corresponds to 2017-01-01T00:00:00+0200 in local Time Zone * 2016-12-31T22:00:00+0200 corresponds to 2016-12-31T22:00:00+0200 in local Time Zone * 2016-12-31T22:00:00+0300 corresponds to 2016-12-31T21:00:00+0200 in local Time Zone * </pre> * * @see <a href= * "https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators">ISO-8601 * Time zone designators</a> * @return */ private static DateFormat getISO8601Format() { StdDateFormat iso8601Format = new StdDateFormat(); iso8601Format.setTimeZone(TimeZone.getDefault()); return iso8601Format; }
/** * Method for getting a non-shared DateFormat instance * that uses specified timezone and can handle simple ISO-8601 * compliant date format. * * @since 2.4 * * @deprecated Since 2.9 */ @Deprecated // since 2.9 public static DateFormat getISO8601Format(TimeZone tz, Locale loc) { return _cloneFormat(DATE_FORMAT_ISO8601, DATE_FORMAT_STR_ISO8601, tz, loc, null); }
protected Date getDate(JsonNode json, String name) throws ParseException { String date = json.path(name).asText(); if (date.isEmpty()) return null; return STD_DATE_FORMAT.parse(date); }
StdDateFormat std = (StdDateFormat) df0; if (format.hasLocale()) { std = std.withLocale(format.getLocale()); std = std.withTimeZone(format.getTimeZone());
@Override protected boolean looksLikeISO8601(String dateStr) { return super.looksLikeISO8601(dateStr); }
@Override public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { if (_formatISO8601 == null) { _formatISO8601 = _cloneFormat(DATE_FORMAT_ISO8601); } return _formatISO8601.format(date, toAppendTo, fieldPosition); }
protected Date parseAsRFC1123(String dateStr, ParsePosition pos) { if (_formatRFC1123 == null) { _formatRFC1123 = _cloneFormat(DATE_FORMAT_RFC1123, DATE_FORMAT_STR_RFC1123, _timezone, _locale); } return _formatRFC1123.parse(dateStr, pos); }
df = _formatPlain; if (df == null) { df = _formatPlain = _cloneFormat(DATE_FORMAT_PLAIN); df = _formatISO8601_z = _cloneFormat(DATE_FORMAT_ISO8601_Z); if (hasTimeZone(dateStr)) { c = dateStr.charAt(len-3); if (c == ':') { // remove optional colon df = _formatISO8601 = _cloneFormat(DATE_FORMAT_ISO8601); df = _formatISO8601_z; if (df == null) { df = _formatISO8601_z = _cloneFormat(DATE_FORMAT_ISO8601_Z); return df.parse(dateStr, pos);