iSavedFieldsShared = false; sort(savedFields, count); if (count > 0) { DurationField first = savedFields[0].iField.getDurationField(); if (compareReverse(first, months) >= 0 && compareReverse(first, days) <= 0) { saveField(DateTimeFieldType.year(), iDefaultYear); return computeMillis(resetFields, text); if (!savedFields[i].iField.isLenient()) { millis = savedFields[i].set(millis, i == (count - 1)); millis -= iOffset; } else if (iZone != null) { int offset = iZone.getOffsetFromLocal(millis); millis -= offset; if (offset != iZone.getOffset(millis)) { String message = "Illegal instant due to time zone offset transition (" + iZone + ')'; if (text != null) {
InternalParser parser = requireParser(); Chronology chrono = selectChronology(null).withUTC(); // always use UTC, avoiding DST gaps DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear); int newPos = parser.parseInto(bucket, text, 0); if (newPos >= 0) { if (newPos >= text.length()) { long millis = bucket.computeMillis(true, text); if (bucket.getOffsetInteger() != null) { // treat withOffsetParsed() as being true int parsedOffset = bucket.getOffsetInteger(); DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset); chrono = chrono.withZone(parsedZone); } else if (bucket.getZone() != null) { chrono = chrono.withZone(bucket.getZone());
/** * Parses a datetime from the given text, returning the number of * milliseconds since the epoch, 1970-01-01T00:00:00Z. * <p> * The parse will use the ISO chronology, and the default time zone. * If the text contains a time zone string then that will be taken into account. * * @param text the text to parse, not null * @return parsed value expressed in milliseconds since the epoch * @throws UnsupportedOperationException if parsing is not supported * @throws IllegalArgumentException if the text to parse is invalid */ public long parseMillis(String text) { InternalParser parser = requireParser(); Chronology chrono = selectChronology(iChrono); DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear); return bucket.doParseMillis(parser, text); }
int length = parsers.length; final Object originalState = bucket.saveState(); boolean isOptional = false; bestValidState = bucket.saveState(); bucket.restoreState(originalState); bucket.restoreState(bestValidState);
boolean isTooLong = (firstDotIndex == -1 ? text.length() : firstDotIndex) > estimateParsedLength(); if (bucket.getZone() != DateTimeZone.UTC) { String format = hasMilliSecondPrecision ? "epoch_millis" : "epoch_second"; throw new IllegalArgumentException("time_zone must be UTC for format [" + format + "]"); bucket.saveField(DateTimeFieldType.year(), dt.getYear()); bucket.saveField(DateTimeFieldType.monthOfYear(), dt.getMonthOfYear()); bucket.saveField(DateTimeFieldType.dayOfMonth(), dt.getDayOfMonth()); bucket.saveField(DateTimeFieldType.hourOfDay(), dt.getHourOfDay()); bucket.saveField(DateTimeFieldType.minuteOfHour(), dt.getMinuteOfHour()); bucket.saveField(DateTimeFieldType.secondOfMinute(), dt.getSecondOfMinute()); bucket.saveField(DateTimeFieldType.millisOfSecond(), dt.getMillisOfSecond()); bucket.setZone(DateTimeZone.UTC); } catch (Exception e) { return -1;
public int parseInto(DateTimeParserBucket bucket, CharSequence text, int position) { DateTimeField field = iFieldType.getField(bucket.getChronology()); long n = field.getDurationField().getUnitMillis() * 10; int length = 0; while (length < limit) { DateTimeFieldType.millisOfSecond(), MillisDurationField.INSTANCE, field.getDurationField()); bucket.saveField(parseField, (int) value);
bucket.saveField(iType, value); return position; if (bucket.getPivotYear() != null) { pivot = bucket.getPivotYear().intValue(); bucket.saveField(iType, year); return position + 2;
@SuppressWarnings("unchecked") public int parseInto(DateTimeParserBucket bucket, CharSequence text, int position) { Locale locale = bucket.getLocale(); validValues.put(property.getAsText(locale).toUpperCase(locale), Boolean.TRUE); if ("en".equals(locale.getLanguage()) && iFieldType == DateTimeFieldType.era()) { String match = text.subSequence(position, i).toString(); if (validValues.containsKey(match)) { bucket.saveField(iFieldType, match, locale); return i;
/** * Parses a datetime from the given text, returning the number of * milliseconds since the epoch, 1970-01-01T00:00:00Z. * <p> * The parse will use the ISO chronology, and the default time zone. * If the text contains a time zone string then that will be taken into account. * * @param text text to parse * @return parsed value expressed in milliseconds since the epoch * @throws UnsupportedOperationException if parsing is not supported * @throws IllegalArgumentException if the text to parse is invalid */ public long parseMillis(String text) { DateTimeParser parser = requireParser(); Chronology chrono = selectChronology(iChrono); DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear); int newPos = parser.parseInto(bucket, text, 0); if (newPos >= 0) { if (newPos >= text.length()) { return bucket.computeMillis(true, text); } } else { newPos = ~newPos; } throw new IllegalArgumentException(FormatUtils.createErrorMessage(text, newPos)); }
/** * Constucts a bucket, with the option of specifying the pivot year for * two-digit year parsing. * * @param instantLocal the initial millis from 1970-01-01T00:00:00, local time * @param chrono the chronology to use * @param locale the locale to use * @param pivotYear the pivot year to use when parsing two-digit years * @since 1.1 */ public DateTimeParserBucket(long instantLocal, Chronology chrono, Locale locale, Integer pivotYear) { super(); chrono = DateTimeUtils.getChronology(chrono); iMillis = instantLocal; iChrono = chrono.withUTC(); iLocale = (locale == null ? Locale.getDefault() : locale); setZone(chrono.getZone()); iPivotYear = pivotYear; }
public int parseInto(DateTimeParserBucket bucket, String text, int position) { String substr = text.substring(position); Matcher matcher = numericMatcher.get(); matcher.reset(substr); if (!matcher.matches()) { return -1; } // Joda DateTime only has precision to millis, cut off any fractional portion long millis = Long.parseLong(matcher.group(1)); DateTime dt = new DateTime(millis, ISOChronology.getInstanceUTC()); for (DateTimeFieldType field : dateTimeFields) { bucket.saveField(field, dt.get(field)); } return substr.length(); } }
/** * Computes the parsed datetime by setting the saved fields. * This method is idempotent, but it is not thread-safe. * * @return milliseconds since 1970-01-01T00:00:00Z * @throws IllegalArgumentException if any field is out of range */ public long computeMillis() { return computeMillis(false, (CharSequence) null); }
public int parseInto(DateTimeParserBucket bucket, CharSequence text, int position) { Map<String, DateTimeZone> parseLookup = iParseLookup; parseLookup = (parseLookup != null ? parseLookup : DateTimeUtils.getDefaultTimeZoneNames()); String matched = null; for (String name : parseLookup.keySet()) { if (csStartsWith(text, position, name)) { if (matched == null || name.length() > matched.length()) { matched = name; } } } if (matched != null) { bucket.setZone(parseLookup.get(matched)); return position + matched.length(); } return ~position; } }
public int parseInto(DateTimeParserBucket bucket, CharSequence text, int position) { InternalParser p = getFormatter(bucket.getLocale()).getParser0(); return p.parseInto(bucket, text, position); }
public int parseInto(DateTimeParserBucket bucket, CharSequence text, int position) { DateTimeField field = iFieldType.getField(bucket.getChronology()); long n = field.getDurationField().getUnitMillis() * 10; int length = 0; while (length < limit) { DateTimeFieldType.millisOfSecond(), MillisDurationField.INSTANCE, field.getDurationField()); bucket.saveField(parseField, (int) value);
bucket.saveField(iType, value); return position; if (bucket.getPivotYear() != null) { pivot = bucket.getPivotYear().intValue(); bucket.saveField(iType, year); return position + 2;