Search in sources :

Example 66 with ParsePosition

use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.

the class TestTextParser method test_parse_short_strict_number_noMatch.

public void test_parse_short_strict_number_noMatch() throws Exception {
    setStrict(true);
    ParsePosition pos = new ParsePosition(0);
    getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).parseUnresolved("1", pos);
    assertEquals(pos.getErrorIndex(), 0);
}
Also used : ParsePosition(java.text.ParsePosition)

Example 67 with ParsePosition

use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.

the class TestTextParser method test_parse_strict_caseSensitive_parseUpper.

//-----------------------------------------------------------------------
@Test(dataProvider = "parseText")
public void test_parse_strict_caseSensitive_parseUpper(TemporalField field, TextStyle style, int value, 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), pos);
    assertEquals(pos.getErrorIndex(), 0);
}
Also used : ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 68 with ParsePosition

use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.

the class TestTextParser method test_parseText.

@Test(dataProvider = "parseText")
public void test_parseText(TemporalField field, TextStyle style, int value, String input) throws Exception {
    ParsePosition pos = new ParsePosition(0);
    assertEquals(getFormatter(field, style).parseUnresolved(input, pos).getLong(field), (long) value);
    assertEquals(pos.getIndex(), input.length());
}
Also used : ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 69 with ParsePosition

use of java.text.ParsePosition in project lucene-solr by apache.

the class NumberFormatTransformer method parseNumber.

private Number parseNumber(String val, NumberFormat numFormat) throws ParseException {
    ParsePosition parsePos = new ParsePosition(0);
    Number num = numFormat.parse(val, parsePos);
    if (parsePos.getIndex() != val.length()) {
        throw new ParseException("illegal number format", parsePos.getIndex());
    }
    return num;
}
Also used : ParseException(java.text.ParseException) ParsePosition(java.text.ParsePosition)

Example 70 with ParsePosition

use of java.text.ParsePosition in project logging-log4j2 by apache.

the class FastDateParser_MoreOrLessTest method testInputHasWhitespace.

@Test
public void testInputHasWhitespace() {
    final FastDateParser parser = new FastDateParser("M/d/y", TimeZone.getDefault(), Locale.getDefault());
    //SimpleDateFormat parser = new SimpleDateFormat("M/d/y");
    final ParsePosition parsePosition = new ParsePosition(0);
    final Date date = parser.parse(" 3/ 23/ 1961", parsePosition);
    Assert.assertEquals(12, parsePosition.getIndex());
    final Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    Assert.assertEquals(1961, calendar.get(Calendar.YEAR));
    Assert.assertEquals(2, calendar.get(Calendar.MONTH));
    Assert.assertEquals(23, calendar.get(Calendar.DATE));
}
Also used : Calendar(java.util.Calendar) Date(java.util.Date) ParsePosition(java.text.ParsePosition) Test(org.junit.Test)

Aggregations

ParsePosition (java.text.ParsePosition)694 Test (org.junit.Test)250 Date (java.util.Date)213 TemporalAccessor (java.time.temporal.TemporalAccessor)163 SimpleDateFormat (java.text.SimpleDateFormat)117 DateTimeFormatter (java.time.format.DateTimeFormatter)94 Test (org.testng.annotations.Test)88 ParseException (java.text.ParseException)71 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)49 SimpleDateFormat (android.icu.text.SimpleDateFormat)39 FieldPosition (java.text.FieldPosition)32 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)25 Calendar (android.icu.util.Calendar)23 ULocale (android.icu.util.ULocale)23 NumberFormat (java.text.NumberFormat)23 Calendar (java.util.Calendar)23 Format (java.text.Format)21 DecimalFormat (java.text.DecimalFormat)19 GregorianCalendar (android.icu.util.GregorianCalendar)18 JapaneseCalendar (android.icu.util.JapaneseCalendar)17