Search in sources :

Example 16 with ParsePosition

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

the class TCKDateTimeFormatters method test_parse_weekDate_largeYear.

@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);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 17 with ParsePosition

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

the class TCKDateTimeFormatterBuilder method test_adjacent_strict_fractionFollows.

//-----------------------------------------------------------------------
@Test
public void test_adjacent_strict_fractionFollows() throws Exception {
    // succeeds because hour/min are fixed width
    DateTimeFormatter f = builder.appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2).appendFraction(NANO_OF_SECOND, 0, 3, false).toFormatter(Locale.UK);
    ParsePosition pp = new ParsePosition(0);
    TemporalAccessor parsed = f.parseUnresolved("1230567", pp);
    assertEquals(pp.getErrorIndex(), -1);
    assertEquals(pp.getIndex(), 7);
    assertEquals(parsed.getLong(HOUR_OF_DAY), 12L);
    assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L);
    assertEquals(parsed.getLong(NANO_OF_SECOND), 567_000_000L);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 18 with ParsePosition

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

the class TCKDateTimeFormatterBuilder method test_adjacent_lenient_firstVariableWidth_success.

@Test
public void test_adjacent_lenient_firstVariableWidth_success() throws Exception {
    // succeeds greedily parsing variable width, then fixed width, to non-numeric Z
    DateTimeFormatter f = builder.parseLenient().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);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 19 with ParsePosition

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

the class TCKDateTimeFormatterBuilder method test_adjacent_lenient_fractionFollows_0digit.

@Test
public void test_adjacent_lenient_fractionFollows_0digit() throws Exception {
    // succeeds because hour/min are fixed width
    DateTimeFormatter f = builder.parseLenient().appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2).appendFraction(NANO_OF_SECOND, 3, 3, false).toFormatter(Locale.UK);
    ParsePosition pp = new ParsePosition(0);
    TemporalAccessor parsed = f.parseUnresolved("1230", pp);
    assertEquals(pp.getErrorIndex(), -1);
    assertEquals(pp.getIndex(), 4);
    assertEquals(parsed.getLong(HOUR_OF_DAY), 12L);
    assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 20 with ParsePosition

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

the class TCKDateTimeFormatterBuilder method test_adjacent_strict_firstVariableWidth_success.

@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);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Aggregations

ParsePosition (java.text.ParsePosition)704 Test (org.junit.Test)253 Date (java.util.Date)221 TemporalAccessor (java.time.temporal.TemporalAccessor)163 SimpleDateFormat (java.text.SimpleDateFormat)125 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 Calendar (java.util.Calendar)26 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)25 Calendar (android.icu.util.Calendar)23 ULocale (android.icu.util.ULocale)23 NumberFormat (java.text.NumberFormat)23 Format (java.text.Format)21 DecimalFormat (java.text.DecimalFormat)19 GregorianCalendar (android.icu.util.GregorianCalendar)18 JapaneseCalendar (android.icu.util.JapaneseCalendar)17