Java Code Examples for java.time.format.DateTimeFormatterBuilder#appendValue()

The following examples show how to use java.time.format.DateTimeFormatterBuilder#appendValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKResolverStyle.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 2
Source File: TCKResolverStyle.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 3
Source File: TCKResolverStyle.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 4
Source File: TCKResolverStyle.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 5
Source File: TCKResolverStyle.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 6
Source File: TCKResolverStyle.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 7
Source File: TCKResolverStyle.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 8
Source File: TCKResolverStyle.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 9
Source File: TCKResolverStyle.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 10
Source File: TCKResolverStyle.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 11
Source File: TCKResolverStyle.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 12
Source File: TCKResolverStyle.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 13
Source File: TCKResolverStyle.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 14
Source File: TCKResolverStyle.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("data_resolverStyle")
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendValue(ChronoField.YEAR_OF_ERA);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.MONTH_OF_YEAR);
    builder.appendLiteral("/");
    builder.appendValue(ChronoField.DAY_OF_MONTH);

    Map<Long, String> eraMap = new HashMap<Long, String>();
    eraMap.put(1L, "CE");
    eraMap.put(0L, "BCE");
    DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();

    DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
    formatter = formatter.withResolverStyle(style);
    if (expectedEx == null) {
        TemporalAccessor accessor = formatter.parse(str);
        assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
    } else {
        try {
            formatter.parse(str);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 15
Source File: FormatUtil.java    From jackcess with Apache License 2.0 4 votes vote down vote up
@Override
public void build(DateTimeFormatterBuilder dtfb, Args args,
                  boolean hasAmPm, Value.Type dtType) {
  dtfb.appendValue(getField(DefaultDateFunctions.weekFields(
                                args._firstDay, args._firstWeekType)));
}