static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int) mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
private Optional<Timestamp> tryParseWithFormat(String strValue) { checkState(fmt != null); if (startingDateValue != null) { // reset value in case any date fields are missing from the date pattern MutableDateTime mdt = new MutableDateTime( startingDateValue, ISOChronology.getInstanceUTC()); // Using parseInto() avoids throwing exception when parsing, // allowing fallback to default timestamp parsing if custom patterns fail. int ret = fmt.parseInto(mdt, strValue, 0); // Only accept parse results if we parsed the entire string if (ret == strValue.length()) { return Optional.of(Timestamp.ofEpochMilli(mdt.getMillis())); } return Optional.empty(); } try { LocalDateTime dt = fmt.parseLocalDateTime(strValue); return Optional.of( Timestamp.ofEpochMilli( dt.toDateTime(ISOChronology.getInstanceUTC().getZone()).getMillis())); } catch (IllegalArgumentException e) { return Optional.empty(); } }
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
private long parseDateTime(String value, DateTimeZone timeZone, boolean roundUpIfNoTime) { DateTimeFormatter parser = dateTimeFormatter.parser; if (timeZone != null) { parser = parser.withZone(timeZone); } try { MutableDateTime date; // We use 01/01/1970 as a base date so that things keep working with date // fields that are filled with times without dates if (roundUpIfNoTime) { date = new MutableDateTime(1970, 1, 1, 23, 59, 59, 999, DateTimeZone.UTC); } else { date = new MutableDateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); } final int end = parser.parseInto(date, value, 0); if (end < 0) { int position = ~end; throw new IllegalArgumentException("Parse failure at index [" + position + "] of [" + value + "]"); } else if (end != value.length()) { throw new IllegalArgumentException("Unrecognized chars at the end of [" + value + "]: [" + value.substring(end) + "]"); } return date.getMillis(); } catch (IllegalArgumentException e) { throw new ElasticsearchParseException("failed to parse date field [{}] with format [{}]", e, value, dateTimeFormatter.pattern()); } }
@Override public Date parse(final String source, final ParsePosition pos) { final MutableDateTime mutableDateTime = new MutableDateTime(); this.dateTimeFormatter.parseInto(mutableDateTime, source, pos.getIndex()); return mutableDateTime.toDate(); } }
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
private long parseDateTime(String value, DateTimeZone timeZone, boolean roundUpIfNoTime) { DateTimeFormatter parser = dateTimeFormatter.parser(); if (timeZone != null) { parser = parser.withZone(timeZone); } try { MutableDateTime date; // We use 01/01/1970 as a base date so that things keep working with date // fields that are filled with times without dates if (roundUpIfNoTime) { date = new MutableDateTime(1970, 1, 1, 23, 59, 59, 999, DateTimeZone.UTC); } else { date = new MutableDateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); } final int end = parser.parseInto(date, value, 0); if (end < 0) { int position = ~end; throw new IllegalArgumentException("Parse failure at index [" + position + "] of [" + value + "]"); } else if (end != value.length()) { throw new IllegalArgumentException("Unrecognized chars at the end of [" + value + "]: [" + value.substring(end) + "]"); } return date.getMillis(); } catch (IllegalArgumentException e) { throw new ElasticsearchParseException("failed to parse date field [{}] with format [{}]", e, value, dateTimeFormatter.format()); } }
private long parseDateTime(String value, DateTimeZone timeZone, boolean roundUpIfNoTime) { DateTimeFormatter parser = dateTimeFormatter.parser(); if (timeZone != null) { parser = parser.withZone(timeZone); } try { MutableDateTime date; // We use 01/01/1970 as a base date so that things keep working with date // fields that are filled with times without dates if (roundUpIfNoTime) { date = new MutableDateTime(1970, 1, 1, 23, 59, 59, 999, DateTimeZone.UTC); } else { date = new MutableDateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); } final int end = parser.parseInto(date, value, 0); if (end < 0) { int position = ~end; throw new IllegalArgumentException("Parse failure at index [" + position + "] of [" + value + "]"); } else if (end != value.length()) { throw new IllegalArgumentException("Unrecognized chars at the end of [" + value + "]: [" + value.substring(end) + "]"); } return date.getMillis(); } catch (IllegalArgumentException e) { throw new ElasticsearchParseException("failed to parse date field [{}] with format [{}]", e, value, dateTimeFormatter.format()); } }
private long parseDateTime(String value, DateTimeZone timeZone, boolean roundUpIfNoTime) { DateTimeFormatter parser = dateTimeFormatter.parser(); if (timeZone != null) { parser = parser.withZone(timeZone); } try { MutableDateTime date; // We use 01/01/1970 as a base date so that things keep working with date // fields that are filled with times without dates if (roundUpIfNoTime) { date = new MutableDateTime(1970, 1, 1, 23, 59, 59, 999, DateTimeZone.UTC); } else { date = new MutableDateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); } final int end = parser.parseInto(date, value, 0); if (end < 0) { int position = ~end; throw new IllegalArgumentException("Parse failure at index [" + position + "] of [" + value + "]"); } else if (end != value.length()) { throw new IllegalArgumentException("Unrecognized chars at the end of [" + value + "]: [" + value.substring(end) + "]"); } return date.getMillis(); } catch (IllegalArgumentException e) { throw new ElasticsearchParseException("failed to parse date field [{}] with format [{}]", e, value, dateTimeFormatter.format()); } }
private long parseDateTime(String value, DateTimeZone timeZone, boolean roundUpIfNoTime) { DateTimeFormatter parser = dateTimeFormatter.parser(); if (timeZone != null) { parser = parser.withZone(timeZone); } try { MutableDateTime date; // We use 01/01/1970 as a base date so that things keep working with date // fields that are filled with times without dates if (roundUpIfNoTime) { date = new MutableDateTime(1970, 1, 1, 23, 59, 59, 999, DateTimeZone.UTC); } else { date = new MutableDateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); } final int end = parser.parseInto(date, value, 0); if (end < 0) { int position = ~end; throw new IllegalArgumentException("Parse failure at index [" + position + "] of [" + value + "]"); } else if (end != value.length()) { throw new IllegalArgumentException("Unrecognized chars at the end of [" + value + "]: [" + value.substring(end) + "]"); } return date.getMillis(); } catch (IllegalArgumentException e) { throw new ElasticsearchParseException("failed to parse date field [{}] with format [{}]", e, value, dateTimeFormatter.format()); } }
private Optional<Timestamp> tryParseWithFormat(String strValue) { checkState(fmt != null); if (startingDateValue != null) { // reset value in case any date fields are missing from the date pattern MutableDateTime mdt = new MutableDateTime( startingDateValue, ISOChronology.getInstanceUTC()); // Using parseInto() avoids throwing exception when parsing, // allowing fallback to default timestamp parsing if custom patterns fail. int ret = fmt.parseInto(mdt, strValue, 0); // Only accept parse results if we parsed the entire string if (ret == strValue.length()) { return Optional.of(Timestamp.ofEpochMilli(mdt.getMillis())); } return Optional.empty(); } try { LocalDateTime dt = fmt.parseLocalDateTime(strValue); return Optional.of( Timestamp.ofEpochMilli( dt.toDateTime(ISOChronology.getInstanceUTC().getZone()).getMillis())); } catch (IllegalArgumentException e) { return Optional.empty(); } }