微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.text.ParsePosition的实例源码

项目:NotifyTools    文件NumberConverter.java   
/**
 * Convert a String into a <code>Number</code> object.
 * @param sourceType the source type of the conversion
 * @param targettype The type to convert the value to
 * @param value The String date value.
 * @param format The NumberFormat to parse the String value.
 *
 * @return The converted Number object.
 * @throws ConversionException if the String cannot be converted.
 */
private Number parse(final Class<?> sourceType,final Class<?> targettype,final String value,final NumberFormat format) {
    final ParsePosition pos = new ParsePosition(0);
    final Number parsednumber = format.parse(value,pos);
    if (pos.getErrorIndex() >= 0 || pos.getIndex() != value.length() || parsednumber == null) {
        String msg = "Error converting from '" + toString(sourceType) + "' to '" + toString(targettype) + "'";
        if (format instanceof DecimalFormat) {
            msg += " using pattern '" + ((DecimalFormat)format).toPattern() + "'";
        }
        if (locale != null) {
            msg += " for locale=[" + locale + "]";
        }
        if (log().isDebugEnabled()) {
            log().debug("    " + msg);
        }
        throw new ConversionException(msg);
    }
    return parsednumber;
}
项目:openjdk-jdk10    文件TestReducedParser.java   
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYear(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR,2,LocalDate.of(2000,1,1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input,pos);
    int actual = parsed.get(YEAR);
    assertEquals(actual,expected,String.format("Wrong date parsed,chrono: %s,input: %s",chrono,input));

}
项目:GitHub    文件NYTimesDataLoader.java   
private void processAndAddData(final Realm realm,final String sectionKey,final List<NYTimesstory> stories) {
    if (stories.isEmpty()) return;

    realm.executeTransactionAsync(r -> {
        for (NYTimesstory story : stories) {
            Date parsedPublishedDate = inputDateFormat.parse(story.getPublishedDate(),new ParsePosition(0));
            story.setSortTimeStamp(parsedPublishedDate.getTime());
            story.setPublishedDate(outputDateFormat.format(parsedPublishedDate));

            // Find existing story in Realm (if any)
            // If it exists,we need to merge the local state with the remote,because the local state
            // contains more info than is available on the server.
            NYTimesstory persistedStory = r.where(NYTimesstory.class).equalTo(NYTimesstory.URL,story.getUrl()).findFirst();
            if (persistedStory != null) {
                // Only local state is the `read` boolean.
                story.setRead(persistedStory.isRead());
            }

            // Only create or update the local story if needed
            if (persistedStory == null || !persistedStory.getUpdatedDate().equals(story.getUpdatedDate())) {
                story.setApiSection(sectionKey);
                r.copyToRealmOrUpdate(story);
            }
        }
    },throwable -> Timber.e(throwable,"Could not save data"));
}
项目:openjdk-jdk10    文件TestNumberParser.java   
@Test(dataProvider="parseData")
public void test_parse_textField(int minWidth,int maxWidth,SignStyle signStyle,int subsequentWidth,String text,int pos,int expectedPos,long expectedValue) {
    ParsePosition ppos = new ParsePosition(pos);
    DateTimeFormatter dtf = getFormatter(DAY_OF_WEEK,minWidth,maxWidth,signStyle);
    if (subsequentWidth > 0) {
        // hacky,to reserve space
        dtf = builder.appendValue(DAY_OF_YEAR,subsequentWidth).toFormatter(locale).withDecimalStyle(decimalStyle);
    }
    TemporalAccessor parsed = dtf.parseUnresolved(text,ppos);
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(),expectedPos);
    } else {
        assertTrue(subsequentWidth >= 0);
        assertEquals(ppos.getIndex(),expectedPos + subsequentWidth);
        assertEquals(parsed.getLong(DAY_OF_WEEK),expectedValue);
        assertEquals(parsed.query(TemporalQueries.chronology()),null);
        assertEquals(parsed.query(TemporalQueries.zoneId()),null);
    }
}
项目:GitHub    文件ISO8601UtilsTest.java   
public void testParseRfc3339Examples() throws java.text.ParseException {
    // Two digit milliseconds.
    Date d = ISO8601Utils.parse("1985-04-12T23:20:50.52Z",new ParsePosition(0));
    assertEquals(newDate(1985,4,12,23,20,50,520,0),d);

    d = ISO8601Utils.parse("1996-12-19T16:39:57-08:00",new ParsePosition(0));
    assertEquals(newDate(1996,19,16,39,57,-8 * 60),d);

    // Truncated leap second.
    d = ISO8601Utils.parse("1990-12-31T23:59:60Z",new ParsePosition(0));
    assertEquals(newDate(1990,31,59,d);

    // Truncated leap second.
    d = ISO8601Utils.parse("1990-12-31T15:59:60-08:00",15,d);

    // Two digit milliseconds.
    d = ISO8601Utils.parse("1937-01-01T12:00:27.87+00:20",new ParsePosition(0));
    assertEquals(newDate(1937,27,870,20),d);
}
项目:Openjsharp    文件DateTimeFormatter.java   
/**
 * Parses and resolves the specified text.
 * <p>
 * This parses to a {@code TemporalAccessor} ensuring that the text is fully parsed.
 *
 * @param text  the text to parse,not null
 * @param position  the position to parse from,updated with length parsed
 *  and the index of any error,null if parsing whole string
 * @return the resolved result of the parse,not null
 * @throws DateTimeParseException if the parse fails
 * @throws DateTimeException if an error occurs while resolving the date or time
 * @throws indexoutofboundsexception if the position is invalid
 */
private TemporalAccessor parseResolved0(final CharSequence text,final ParsePosition position) {
    ParsePosition pos = (position != null ? position : new ParsePosition(0));
    DateTimeParseContext context = parseUnresolved0(text,pos);
    if (context == null || pos.getErrorIndex() >= 0 || (position == null && pos.getIndex() < text.length())) {
        String abbr;
        if (text.length() > 64) {
            abbr = text.subSequence(0,64).toString() + "...";
        } else {
            abbr = text.toString();
        }
        if (pos.getErrorIndex() >= 0) {
            throw new DateTimeParseException("Text '" + abbr + "' Could not be parsed at index " +
                    pos.getErrorIndex(),text,pos.getErrorIndex());
        } else {
            throw new DateTimeParseException("Text '" + abbr + "' Could not be parsed,unparsed text found at index " +
                    pos.getIndex(),pos.getIndex());
        }
    }
    return context.toResolved(resolverStyle,resolverFields);
}
项目:jdk8u-jdk    文件TestReducedParser.java   
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYearOfEra(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR_OF_ERA,1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR_OF_ERA);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input,pos);
    int actual = parsed.get(YEAR_OF_ERA);
    assertEquals(actual,input));

}
项目:jdk8u-jdk    文件TestReducedParser.java   
@Test
public void test_reducedWithLateChronoChange() {
    ThaiBuddhistDate date = ThaiBuddhistDate.of(2543,1);
    DateTimeFormatter df
            = new DateTimeFormatterBuilder()
                    .appendValueReduced(YEAR,1))
                    .appendLiteral(" ")
                    .appendChronologyId()
            .toFormatter();
    int expected = date.get(YEAR);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input,pos);
    assertEquals(pos.getIndex(),input.length(),"Input not parsed completely");
    assertEquals(pos.getErrorIndex(),-1,"Error index should be -1 (no-error)");
    int actual = parsed.get(YEAR);
    assertEquals(actual,parsed.query(TemporalQueries.chronology()),input));

}
项目:swaggy-jenkins    文件JSON.java   
@Override
public java.sql.Date read(JsonReader in) throws IOException {
    switch (in.peek()) {
        case NULL:
            in.nextNull();
            return null;
        default:
            String date = in.nextString();
            try {
                if (dateFormat != null) {
                    return new java.sql.Date(dateFormat.parse(date).getTime());
                }
                return new java.sql.Date(ISO8601Utils.parse(date,new ParsePosition(0)).getTime());
            } catch (ParseException e) {
                throw new JsonParseException(e);
            }
    }
}
项目:fitnotifications    文件TransliteratorParser.java   
/**
 * Implement SymbolTable API.  Parse out a symbol reference
 * name.
 */
@Override
public String parseReference(String text,ParsePosition pos,int limit) {
    int start = pos.getIndex();
    int i = start;
    while (i < limit) {
        char c = text.charat(i);
        if ((i==start && !UCharacter.isUnicodeIdentifierStart(c)) ||
            !UCharacter.isUnicodeIdentifierPart(c)) {
            break;
        }
        ++i;
    }
    if (i == start) { // No valid name chars
        return null;
    }
    pos.setIndex(i);
    return text.substring(start,i);
}
项目:openjdk-jdk10    文件TCKDateTimeFormatter.java   
@Test
public void test_parse_CharSequence_ParsePosition_resolved() {
    DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
    ParsePosition pos = new ParsePosition(3);
    TemporalAccessor result = test.parse("XXX2012-06-30XXX",13);
    assertEquals(pos.getErrorIndex(),-1);
    assertEquals(result.isSupported(YEAR),true);
    assertEquals(result.isSupported(MONTH_OF_YEAR),true);
    assertEquals(result.isSupported(DAY_OF_MONTH),true);
    assertEquals(result.isSupported(HOUR_OF_DAY),false);
    assertEquals(result.getLong(YEAR),2012L);
    assertEquals(result.getLong(MONTH_OF_YEAR),6L);
    assertEquals(result.getLong(DAY_OF_MONTH),30L);
    assertEquals(result.query(LocalDate::from),LocalDate.of(2012,6,30));
}
项目:openjdk-jdk10    文件DateTimeFormatter.java   
/**
 * Parses and resolves the specified text.
 * <p>
 * This parses to a {@code TemporalAccessor} ensuring that the text is fully parsed.
 *
 * @param text  the text to parse,resolverFields);
}
项目:openjdk-jdk10    文件TestReducedParser.java   
@Test
public void test_reducedWithLateChronoChangeTwice() {
    DateTimeFormatter df
            = new DateTimeFormatterBuilder()
                    .appendValueReduced(YEAR,1))
                    .appendLiteral(" ")
                    .appendChronologyId()
                    .appendLiteral(" ")
                    .appendChronologyId()
            .toFormatter();
    int expected = 2044;
    String input = "44 ThaiBuddhist ISO";
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input,"Input not parsed completely: " + pos);
    assertEquals(pos.getErrorIndex(),input));

}
项目:openjdk-jdk10    文件TestZoneOffsetParser.java   
@Test(dataProvider="bigOffsets")
public void test_parse_bigOffsets(String pattern,String parse,long offsetSecs) throws Exception {
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter(pattern,"").parseUnresolved(parse,parse.length());
    assertEquals(parsed.getLong(OFFSET_SECONDS),offsetSecs);
}
项目:openjdk-jdk10    文件TestTextParser.java   
public void test_parse_noMatch_atEnd() throws Exception {
    ParsePosition pos = new ParsePosition(6);
    TemporalAccessor parsed =
        getFormatter(DAY_OF_WEEK,TextStyle.FULL).parseUnresolved("Monday",pos);
    assertEquals(pos.getErrorIndex(),6);
    assertEquals(parsed,null);
}
项目:GestureFX    文件LenaSample.java   
private static textformatter<String> createDecimalFormatter() {
    DecimalFormat format = new DecimalFormat("#.0");
    format.setNegativePrefix("-");
    return new textformatter<>(c -> {
        if (c.getControlNewText().isEmpty()) return c;
        ParsePosition pos = new ParsePosition(0);
        Number result = format.parse(c.getControlNewText(),pos);
        if (result == null || pos.getIndex() < c.getControlNewText().length()) {
            return null;
        } else return c;
    });
}
项目:openjdk-jdk10    文件TestZoneOffsetParser.java   
@Test(dataProvider="offsets")
public void test_parse_midStringMatch(String pattern,ZoneOffset expected) throws Exception {
    ParsePosition pos = new ParsePosition(5);
    TemporalAccessor parsed = getFormatter(pattern,"Z").parseUnresolved("OTHER" + parse + ":OTHER",parse.length() + 5);
    assertParsed(parsed,expected);
}
项目:jdk8u-jdk    文件TestTextParser.java   
public void test_parse_remainderIgnored() throws Exception {
    ParsePosition pos = new ParsePosition(0);
    assertEquals(getFormatter(DAY_OF_WEEK,TextStyle.SHORT)
                 .parseUnresolved("Wednesday",pos)
                 .getLong(DAY_OF_WEEK),3L);
    assertEquals(pos.getIndex(),3);
}
项目:jdk8u-jdk    文件TestStringLiteralParser.java   
@Test(dataProvider="success")
public void test_parse_success(String s,boolean caseSensitive,int expectedPos) {
    setCaseSensitive(caseSensitive);
    ParsePosition ppos = new ParsePosition(pos);
    TemporalAccessor parsed = getFormatter(s).parseUnresolved(text,ppos);
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getIndex(),expectedPos);
    } else {
        assertEquals(ppos.getIndex(),expectedPos);
        assertEquals(parsed.isSupported(YEAR),false);
        assertEquals(parsed.query(TemporalQueries.chronology()),null);
    }
}
项目:openjdk-jdk10    文件TCKDateTimeFormatters.java   
@Test(dataProvider="sample_isoLocalDateTime")
public void test_parse_isoLocalDateTime(
        Integer year,Integer month,Integer day,Integer hour,Integer min,Integer sec,Integer nano,String offsetId,String zoneId,String input,Class<?> invalid) {
    if (input != null) {
        Expected expected = createDateTime(year,month,day,hour,min,sec,nano);
        assertParseMatch(DateTimeFormatter.ISO_LOCAL_DATE_TIME.parseUnresolved(input,new ParsePosition(0)),expected);
    }
}
项目:jdk8u-jdk    文件TestDateTimeFormatterBuilder.java   
@Test
public void test_appendValue_subsequent2_parse5() throws Exception {
    builder.appendValue(MONTH_OF_YEAR,SignStyle.norMAL).appendValue(DAY_OF_MONTH,2).appendLiteral('4');
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(),"Value(MonthOfYear,norMAL)Value(DayOfMonth,2)'4'");
    TemporalAccessor parsed = f.parseUnresolved("01234",new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR),1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH),23L);
}
项目:openjdk-jdk10    文件TestFractionPrinterParser.java   
@Test(dataProvider="Nanos")
public void test_reverseParse_noDecimalPoint(int minWidth,int value,String result) throws Exception {
    ParsePosition pos = new ParsePosition((result.startsWith(".") ? 1 : 0));
    TemporalAccessor parsed = getFormatter(NANO_OF_SECOND,false).parseUnresolved(result,result.length());
    int expectedValue = fixParsedValue(maxWidth,value);
    assertParsed(parsed,NANO_OF_SECOND,value == 0 && minWidth == 0 ? null : (long) expectedValue);
}
项目:openjdk-jdk10    文件TestTextParser.java   
@Test(dataProvider="parseText")
public void test_parse_strict_caseSensitive_parseUpper(TemporalField field,TextStyle style,String input) throws Exception {
    if (input.equals(input.toupperCase(Locale.ROOT))) {
        // Skip if the given input is all upper case (e.g.,"Q1")
        return;
    }
    setCaseSensitive(true);
    ParsePosition pos = new ParsePosition(0);
    getFormatter(field,style).parseUnresolved(input.toupperCase(Locale.ROOT),0);
}
项目:openjdk-jdk10    文件TestTextParser.java   
public void test_parse_noMatch2() throws Exception {
    ParsePosition pos = new ParsePosition(3);
    TemporalAccessor parsed =
        getFormatter(DAY_OF_WEEK,3);
    assertEquals(parsed,null);
}
项目:lams    文件Extendedmessageformat.java   
/**
 * Insert formats back into the pattern for toPattern() support.
 *
 * @param pattern source
 * @param customPatterns The custom patterns to re-insert,if any
 * @return full pattern
 */
private String insertFormats(String pattern,ArrayList customPatterns) {
    if (!containsElements(customPatterns)) {
        return pattern;
    }
    StrBuilder sb = new StrBuilder(pattern.length() * 2);
    ParsePosition pos = new ParsePosition(0);
    int fe = -1;
    int depth = 0;
    while (pos.getIndex() < pattern.length()) {
        char c = pattern.charat(pos.getIndex());
        switch (c) {
        case QUOTE:
            appendQuotedString(pattern,pos,sb,false);
            break;
        case START_FE:
            depth++;
            if (depth == 1) {
                fe++;
                sb.append(START_FE).append(
                        readArgumentIndex(pattern,next(pos)));
                String customPattern = (String) customPatterns.get(fe);
                if (customPattern != null) {
                    sb.append(START_FMT).append(customPattern);
                }
            }
            break;
        case END_FE:
            depth--;
            //$FALL-THROUGH$
        default:
            sb.append(c);
            next(pos);
        }
    }
    return sb.toString();
}
项目:jdk8u-jdk    文件TCKDateTimeFormatterBuilder.java   
@Test
public void test_adjacent_strict_firstvariableWidth_success() throws Exception {
    // succeeds greedily parsing variable width,then fixed width,to non-numeric Z
    DateTimeFormatter f = builder.appendValue(HOUR_OF_DAY).appendValue(MINUTE_OF_HOUR,2).appendLiteral('Z').toFormatter(Locale.UK);
    ParsePosition pp = new ParsePosition(0);
    TemporalAccessor parsed = f.parseUnresolved("12309Z",pp);
    assertEquals(pp.getErrorIndex(),-1);
    assertEquals(pp.getIndex(),6);
    assertEquals(parsed.getLong(HOUR_OF_DAY),123L);
    assertEquals(parsed.getLong(MINUTE_OF_HOUR),9L);
}
项目:jdk8u-jdk    文件TestZoneOffsetParser.java   
public void test_parse_caseInsensitiveUTC_matchedCase() throws Exception {
    setCaseSensitive(false);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter("+HH:MM:ss","Z").parseUnresolved("Z",1);
    assertParsed(parsed,ZoneOffset.UTC);
}
项目:jdk8u-jdk    文件TestZoneOffsetParser.java   
@Test(dataProvider="offsets")
public void test_parse_midStringMatch_EmptyUTC(String pattern,"").parseUnresolved("OTHER" + parse + ":OTHER",expected);
}
项目:jdk8u-jdk    文件TestTextParser.java   
public void test_parse_noMatch_atEnd() throws Exception {
    ParsePosition pos = new ParsePosition(6);
    TemporalAccessor parsed =
        getFormatter(DAY_OF_WEEK,null);
}
项目:jdk8u-jdk    文件TCKDateTimeFormatters.java   
@Test
public void test_parse_weekDate_largeYear() {
    TemporalAccessor parsed = DateTimeFormatter.ISO_WEEK_DATE.parseUnresolved("+123456-W04-5",new ParsePosition(0));
    assertEquals(parsed.getLong(IsoFields.WEEK_BASED_YEAR),123456L);
    assertEquals(parsed.getLong(IsoFields.WEEK_OF_WEEK_BASED_YEAR),4L);
    assertEquals(parsed.getLong(DAY_OF_WEEK),5L);
}
项目:openjdk-jdk10    文件TCKDateTimeFormatters.java   
@Test
public void test_parse_weekDate_largeYear() {
    TemporalAccessor parsed = DateTimeFormatter.ISO_WEEK_DATE.parseUnresolved("+123456-W04-5",5L);
}
项目:openjdk-jdk10    文件TCKDateTimeFormatter.java   
@Test(expectedExceptions=NullPointerException.class)
public void test_toFormat_parSEObject_StringParsePosition_nullString() throws Exception {
    // SimpleDateFormat has this behavior
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    ParsePosition pos = new ParsePosition(0);
    format.parSEObject((String) null,pos);
}
项目:openjdk-jdk10    文件TestZoneOffsetParser.java   
@Test(dataProvider="offsets")
public void test_parse_midStringMatch_EmptyUTC(String pattern,expected);
}
项目:jdk8u-jdk    文件TestZoneOffsetParser.java   
@Test(dataProvider="offsets")
public void test_parse_startStringMatch(String pattern,ZoneOffset expected) throws Exception {
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter(pattern,"Z").parseUnresolved(parse + ":OTHER",parse.length());
    assertParsed(parsed,expected);
}
项目:openjdk-jdk10    文件TCKDateTimeFormatterBuilder.java   
@Test
public void test_adjacent_strict_firstFixedWidth() throws Exception {
    // succeeds because both number elements are fixed width
    DateTimeFormatter f = builder.appendValue(HOUR_OF_DAY,2).appendValue(MINUTE_OF_HOUR,2).appendLiteral('9').toFormatter(Locale.UK);
    ParsePosition pp = new ParsePosition(0);
    TemporalAccessor parsed = f.parseUnresolved("12309",5);
    assertEquals(parsed.getLong(HOUR_OF_DAY),12L);
    assertEquals(parsed.getLong(MINUTE_OF_HOUR),30L);
}
项目:WeiXing_xmu-2016-MrCode    文件DateUtils.java   
public static void main(String[] args) throws ParseException {
        String pat1 = "yyyy-MM-dd HH:mm:ss" ; 
        /*Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(pat1);
        System.out.println(date);*/
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        ParsePosition pos = new ParsePosition(8);
        Date currentTime_2 = formatter.parse(dateString,pos);
        System.out.println(currentTime_2);
//      System.out.println(DateUtils.parseDate(dateTime));
        //System.out.println(DateUtils.parseDate(DateUtils.time(Now())));
        //System.out.println(createDate.toString());
        /*SimpleDateFormat sdf = new SimpleDateFormat(pat1);
        System.out.println(sdf.parse("2016-3-3 13:30:0"));*/
        //Calendar cal = Calendar.getInstance();
//      System.out.println(Now(COMPACT_YMDHMS_FORMAT));
//      System.out.println(time2Str(Now()));
//      System.out.println(DateUtils.time(Now()).toString("yyyy年MM月dd日HH时mm分ss秒"));
        //System.out.println(DateUtils.time(Now()).toString(DEFAULT_YMDHMS_FORMAT));
        /*System.out.println(
                lengthBetween(
                        time("2013-04-20 11:15:15"),time("2013-04-18 11:15:15"),JodaTime.DAY
                )
        );
        System.out.println(time2Str(new Date(),DEFAULT_YMDHMS_FORMAT));
        System.out.println(currentTime());*/
    }
项目:openjdk-jdk10    文件TCKDateTimeFormatter.java   
@Test(expectedExceptions=DateTimeParseException.class)
public void test_parse_CharSequence_ParsePosition_parseError() {
    DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
    ParsePosition pos = new ParsePosition(3);
    try {
        test.parse("XXX2012XXX",pos);
        fail();
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getErrorIndex(),7);
        throw ex;
    }
}
项目:openjdk-jdk10    文件TCKLocalizedFieldParser.java   
@Test(dataProvider = "adjacentValuePatterns1")
public void test_adjacentValuePatterns1(String pattern,TemporalField field1,TemporalField field2,int expected1,int expected2) {
    DateTimeFormatter df = new DateTimeFormatterBuilder()
            .appendPattern(pattern).toFormatter(Locale.US);
    ParsePosition ppos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(text,ppos);
    assertEquals(parsed.get(field1),expected1);
    assertEquals(parsed.get(field2),expected2);
}
项目:openjdk-jdk10    文件TCKDateTimeFormatters.java   
@Test(dataProvider="sample_isoInstant")
public void test_parse_isoInstant(
        long instantSecs,Class<?> invalid) {
    if (input != null) {
        TemporalAccessor parsed = DateTimeFormatter.ISO_INSTANT.parseUnresolved(input,new ParsePosition(0));
        assertEquals(parsed.getLong(INSTANT_SECONDS),instantSecs);
        assertEquals(parsed.getLong(NANO_OF_SECOND),(nano == null ? 0 : nano));
    }
}
项目:jdk8u-jdk    文件TCKDateTimeFormatter.java   
@Test
public void test_parseUnresolved_StringParsePosition_duplicateFieldSameValue() {
    DateTimeFormatter test = new DateTimeFormatterBuilder()
            .appendValue(MONTH_OF_YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).toFormatter();
    ParsePosition pos = new ParsePosition(3);
    TemporalAccessor result = test.parseUnresolved("XXX6-6",6);
    assertEquals(pos.getErrorIndex(),-1);
    assertEquals(result.getLong(MONTH_OF_YEAR),6);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。