Java Code Examples for java.time.format.DateTimeFormatter#withResolverFields()
The following examples show how to use
java.time.format.DateTimeFormatter#withResolverFields() .
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: TCKDateTimeFormatter.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_resolverFields_selectOneDateResolveYD() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR); Set<TemporalField> expected = new HashSet<>(Arrays.asList(YEAR, DAY_OF_YEAR)); // Use set.equals(); testNG comparison of Collections is ordered assertTrue(f.getResolverFields().equals(expected), "ResolveFields: " + f.getResolverFields()); try { base.parse("2012-6-30-321", LocalDate::from); // wrong month/day-of-month fail(); } catch (DateTimeException ex) { // expected, fails as it produces two different dates } LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored month/day-of-month assertEquals(parsed, LocalDate.of(2012, 11, 16)); }
Example 2
Source File: TCKDateTimeFormatter.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_resolverFields_selectOneDateResolveYD() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR); Set<TemporalField> expected = new HashSet<>(Arrays.asList(YEAR, DAY_OF_YEAR)); // Use set.equals(); testNG comparison of Collections is ordered assertTrue(f.getResolverFields().equals(expected), "ResolveFields: " + f.getResolverFields()); try { base.parse("2012-6-30-321", LocalDate::from); // wrong month/day-of-month fail(); } catch (DateTimeException ex) { // expected, fails as it produces two different dates } LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored month/day-of-month assertEquals(parsed, LocalDate.of(2012, 11, 16)); }
Example 3
Source File: TCKDateTimeFormatter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_Set_null() throws Exception { DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); assertEquals(f.getResolverFields().size(), 1); f = f.withResolverFields((Set<TemporalField>) null); assertEquals(f.getResolverFields(), null); }
Example 4
Source File: TCKDateTimeFormatter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_Set_null() throws Exception { DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); assertEquals(f.getResolverFields().size(), 1); f = f.withResolverFields((Set<TemporalField>) null); assertEquals(f.getResolverFields(), null); }
Example 5
Source File: TCKDateTimeFormatter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_Array_null() throws Exception { DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); assertEquals(f.getResolverFields().size(), 1); f = f.withResolverFields((TemporalField[]) null); assertEquals(f.getResolverFields(), null); }
Example 6
Source File: TCKDateTimeFormatter.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void test_resolverFields_Set_null() throws Exception { DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); assertEquals(f.getResolverFields().size(), 1); f = f.withResolverFields((Set<TemporalField>) null); assertEquals(f.getResolverFields(), null); }
Example 7
Source File: TCKDateTimeFormatter.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_Array_null() throws Exception { DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); assertEquals(f.getResolverFields().size(), 1); f = f.withResolverFields((TemporalField[]) null); assertEquals(f.getResolverFields(), null); }
Example 8
Source File: TCKDateTimeFormatter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_selectOneDateResolveYMD() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH); try { base.parse("2012-6-30-321", LocalDate::from); // wrong day-of-year fail(); } catch (DateTimeException ex) { // expected, fails as it produces two different dates } LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored day-of-year assertEquals(parsed, LocalDate.of(2012, 6, 30)); }
Example 9
Source File: TCKDateTimeFormatter.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_Array_null() throws Exception { DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); assertEquals(f.getResolverFields().size(), 1); f = f.withResolverFields((TemporalField[]) null); assertEquals(f.getResolverFields(), null); }
Example 10
Source File: TCKDateTimeFormatter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_selectOneDateResolveYMD() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH); try { base.parse("2012-6-30-321", LocalDate::from); // wrong day-of-year fail(); } catch (DateTimeException ex) { // expected, fails as it produces two different dates } LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored day-of-year assertEquals(parsed, LocalDate.of(2012, 6, 30)); }
Example 11
Source File: TCKDateTimeFormatter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_ignoreCrossCheck() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(DAY_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_WEEK).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR); try { base.parse("2012-321-1", LocalDate::from); // wrong day-of-week fail(); } catch (DateTimeException ex) { // expected, should fail in cross-check of day-of-week } LocalDate parsed = f.parse("2012-321-1", LocalDate::from); // ignored wrong day-of-week assertEquals(parsed, LocalDate.of(2012, 11, 16)); }
Example 12
Source File: TCKDateTimeFormatter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_Set_null() throws Exception { DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); assertEquals(f.getResolverFields().size(), 1); f = f.withResolverFields((Set<TemporalField>) null); assertEquals(f.getResolverFields(), null); }
Example 13
Source File: TCKDateTimeFormatter.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_selectOneDateResolveYMD() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH); try { base.parse("2012-6-30-321", LocalDate::from); // wrong day-of-year fail(); } catch (DateTimeException ex) { // expected, fails as it produces two different dates } LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored day-of-year assertEquals(parsed, LocalDate.of(2012, 6, 30)); }
Example 14
Source File: TCKDateTimeFormatter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_ignoreCrossCheck() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(DAY_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_WEEK).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR); try { base.parse("2012-321-1", LocalDate::from); // wrong day-of-week fail(); } catch (DateTimeException ex) { // expected, should fail in cross-check of day-of-week } LocalDate parsed = f.parse("2012-321-1", LocalDate::from); // ignored wrong day-of-week assertEquals(parsed, LocalDate.of(2012, 11, 16)); }
Example 15
Source File: TCKDateTimeFormatter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_Array_null() throws Exception { DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); assertEquals(f.getResolverFields().size(), 1); f = f.withResolverFields((TemporalField[]) null); assertEquals(f.getResolverFields(), null); }
Example 16
Source File: TCKDateTimeFormatter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_ignoreCrossCheck() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(DAY_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_WEEK).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR); try { base.parse("2012-321-1", LocalDate::from); // wrong day-of-week fail(); } catch (DateTimeException ex) { // expected, should fail in cross-check of day-of-week } LocalDate parsed = f.parse("2012-321-1", LocalDate::from); // ignored wrong day-of-week assertEquals(parsed, LocalDate.of(2012, 11, 16)); }
Example 17
Source File: TCKDateTimeFormatter.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_selectOneDateResolveYMD() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH); try { base.parse("2012-6-30-321", LocalDate::from); // wrong day-of-year fail(); } catch (DateTimeException ex) { // expected, fails as it produces two different dates } LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored day-of-year assertEquals(parsed, LocalDate.of(2012, 6, 30)); }
Example 18
Source File: TCKDateTimeFormatter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_selectOneDateResolveYMD() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH); try { base.parse("2012-6-30-321", LocalDate::from); // wrong day-of-year fail(); } catch (DateTimeException ex) { // expected, fails as it produces two different dates } LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored day-of-year assertEquals(parsed, LocalDate.of(2012, 6, 30)); }
Example 19
Source File: TCKDateTimeFormatter.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_Set_null() throws Exception { DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); assertEquals(f.getResolverFields().size(), 1); f = f.withResolverFields((Set<TemporalField>) null); assertEquals(f.getResolverFields(), null); }
Example 20
Source File: TCKDateTimeFormatter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void test_resolverFields_ignoreCrossCheck() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(DAY_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_WEEK).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR); try { base.parse("2012-321-1", LocalDate::from); // wrong day-of-week fail(); } catch (DateTimeException ex) { // expected, should fail in cross-check of day-of-week } LocalDate parsed = f.parse("2012-321-1", LocalDate::from); // ignored wrong day-of-week assertEquals(parsed, LocalDate.of(2012, 11, 16)); }