Java Code Examples for java.time.format.DateTimeFormatterBuilder#appendLiteral()
The following examples show how to use
java.time.format.DateTimeFormatterBuilder#appendLiteral() .
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 |
@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 |
@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 |
@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 |
@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 |
@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 |
@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: SlackDateTimeFormatter.java From roboslack with Apache License 2.0 | 5 votes |
/** * The delegate {@link DateTimeFormatter} for formatting a {@link SlackDateTime} outside of the context of Slack. * * @return the {@link DateTimeFormatter} to use when formatting a {@link SlackDateTime} outside of Slack */ @Value.Derived protected DateTimeFormatter delegateFormatter() { DateTimeFormatterBuilder formatterBuilder = new DateTimeFormatterBuilder(); for (String patternToken : tokenizePattern(pattern())) { Optional<DateTimeFormatToken> formatToken = DateTimeFormatToken.ofSafe(patternToken); if (formatToken.isPresent()) { formatterBuilder.appendPattern(formatToken.get().pattern()); } else { formatterBuilder.appendLiteral(patternToken); } } return formatterBuilder.toFormatter(); }
Example 8
Source File: TCKResolverStyle.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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 hottub with GNU General Public License v2.0 | 5 votes |
@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-source with GNU General Public License v2.0 | 5 votes |
@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 openjdk-8 with GNU General Public License v2.0 | 5 votes |
@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 |
@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-jdk with GNU General Public License v2.0 | 5 votes |
@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 jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@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 15
Source File: TCKResolverStyle.java From j2objc with Apache License 2.0 | 5 votes |
@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)); } } }