Java Code Examples for java.time.format.ResolverStyle#values()
The following examples show how to use
java.time.format.ResolverStyle#values() .
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: TCKDateTimeParseResolver.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="resolveFourToTime") public void test_resolveFourToDateTime(ResolverStyle style, long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) { DateTimeFormatter f = new DateTimeFormatterBuilder() .parseDefaulting(YEAR, 2012).parseDefaulting(MONTH_OF_YEAR, 6).parseDefaulting(DAY_OF_MONTH, 30) .parseDefaulting(HOUR_OF_DAY, hour) .parseDefaulting(MINUTE_OF_HOUR, min) .parseDefaulting(SECOND_OF_MINUTE, sec) .parseDefaulting(NANO_OF_SECOND, nano).toFormatter(); ResolverStyle[] styles = (style != null ? new ResolverStyle[] {style} : ResolverStyle.values()); if (expectedTime != null && excessPeriod != null) { LocalDate expectedDate = LocalDate.of(2012, 6, 30).plus(excessPeriod); for (ResolverStyle s : styles) { TemporalAccessor accessor = f.withResolverStyle(s).parse(""); assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate, "ResolverStyle: " + s); assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s); assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO, "ResolverStyle: " + s); } } }
Example 2
Source File: TCKDateTimeParseResolver.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="resolveFourToTime") public void test_resolveThreeToTime(ResolverStyle style, long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) { DateTimeFormatter f = new DateTimeFormatterBuilder() .parseDefaulting(HOUR_OF_DAY, hour) .parseDefaulting(MINUTE_OF_HOUR, min) .parseDefaulting(SECOND_OF_MINUTE, sec).toFormatter(); ResolverStyle[] styles = (style != null ? new ResolverStyle[] {style} : ResolverStyle.values()); for (ResolverStyle s : styles) { if (expectedTime != null) { TemporalAccessor accessor = f.withResolverStyle(s).parse(""); assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s); assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime.minusNanos(nano), "ResolverStyle: " + s); assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s); } else { try { f.withResolverStyle(style).parse(""); fail(); } catch (DateTimeParseException ex) { // expected } } } }
Example 3
Source File: TCKDateTimeParseResolver.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="resolveFourToTime") public void test_resolveFourToTime(ResolverStyle style, long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) { DateTimeFormatter f = new DateTimeFormatterBuilder() .parseDefaulting(HOUR_OF_DAY, hour) .parseDefaulting(MINUTE_OF_HOUR, min) .parseDefaulting(SECOND_OF_MINUTE, sec) .parseDefaulting(NANO_OF_SECOND, nano).toFormatter(); ResolverStyle[] styles = (style != null ? new ResolverStyle[] {style} : ResolverStyle.values()); for (ResolverStyle s : styles) { if (expectedTime != null) { TemporalAccessor accessor = f.withResolverStyle(s).parse(""); assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s); assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s); assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s); } else { try { f.withResolverStyle(style).parse(""); fail(); } catch (DateTimeParseException ex) { // expected } } } }
Example 4
Source File: TCKDateTimeParseResolver.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="resolveFourToTime") public void test_resolveFourToTime(ResolverStyle style, long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) { DateTimeFormatter f = new DateTimeFormatterBuilder() .parseDefaulting(HOUR_OF_DAY, hour) .parseDefaulting(MINUTE_OF_HOUR, min) .parseDefaulting(SECOND_OF_MINUTE, sec) .parseDefaulting(NANO_OF_SECOND, nano).toFormatter(); ResolverStyle[] styles = (style != null ? new ResolverStyle[] {style} : ResolverStyle.values()); for (ResolverStyle s : styles) { if (expectedTime != null) { TemporalAccessor accessor = f.withResolverStyle(s).parse(""); assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s); assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s); assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s); } else { try { f.withResolverStyle(style).parse(""); fail(); } catch (DateTimeParseException ex) { // expected } } } }
Example 5
Source File: TCKJapaneseChronology.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void test_resolve_yearOfEra_eraOnly_invalidTooLarge() { for (ResolverStyle style : ResolverStyle.values()) { Map<TemporalField, Long> fieldValues = new HashMap<>(); fieldValues.put(ChronoField.ERA, JapaneseEra.values()[JapaneseEra.values().length - 1].getValue() + 1L); try { JapaneseChronology.INSTANCE.resolveDate(fieldValues, style); fail("Should have failed: " + style); } catch (DateTimeException ex) { // expected } } }
Example 6
Source File: TCKJapaneseChronology.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "resolve_styles") Object[][] data_resolve_styles() { Object[][] result = new Object[ResolverStyle.values().length][]; int i = 0; for (ResolverStyle style : ResolverStyle.values()) { result[i++] = new Object[] {style}; } return result; }
Example 7
Source File: TCKJapaneseChronology.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "resolve_styleByEra") Object[][] data_resolve_styleByEra() { Object[][] result = new Object[ResolverStyle.values().length * JapaneseEra.values().length][]; int i = 0; for (ResolverStyle style : ResolverStyle.values()) { for (JapaneseEra era : JapaneseEra.values()) { result[i++] = new Object[] {style, era}; } } return result; }
Example 8
Source File: TCKHijrahChronology.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "resolve_styles") Object[][] data_resolve_styles() { Object[][] result = new Object[ResolverStyle.values().length][]; int i = 0; for (ResolverStyle style : ResolverStyle.values()) { result[i++] = new Object[] {style}; } return result; }
Example 9
Source File: TCKJapaneseChronology.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void test_resolve_yearOfEra_eraOnly_invalidTooSmall() { for (ResolverStyle style : ResolverStyle.values()) { Map<TemporalField, Long> fieldValues = new HashMap<>(); fieldValues.put(ChronoField.ERA, JapaneseEra.MEIJI.getValue() - 1L); try { JapaneseChronology.INSTANCE.resolveDate(fieldValues, style); fail("Should have failed: " + style); } catch (DateTimeException ex) { // expected } } }
Example 10
Source File: TCKHijrahChronology.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "resolve_styleByEra") Object[][] data_resolve_styleByEra() { Object[][] result = new Object[ResolverStyle.values().length * HijrahEra.values().length][]; int i = 0; for (ResolverStyle style : ResolverStyle.values()) { for (HijrahEra era : HijrahEra.values()) { result[i++] = new Object[] {style, era}; } } return result; }
Example 11
Source File: TCKJapaneseChronology.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "resolve_styles") Object[][] data_resolve_styles() { Object[][] result = new Object[ResolverStyle.values().length][]; int i = 0; for (ResolverStyle style : ResolverStyle.values()) { result[i++] = new Object[] {style}; } return result; }
Example 12
Source File: TCKHijrahChronology.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "resolve_styles") Object[][] data_resolve_styles() { Object[][] result = new Object[ResolverStyle.values().length][]; int i = 0; for (ResolverStyle style : ResolverStyle.values()) { result[i++] = new Object[] {style}; } return result; }
Example 13
Source File: TCKJapaneseChronology.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public void test_resolve_yearOfEra_eraOnly_invalidTooLarge() { for (ResolverStyle style : ResolverStyle.values()) { Map<TemporalField, Long> fieldValues = new HashMap<>(); fieldValues.put(ChronoField.ERA, JapaneseEra.values()[JapaneseEra.values().length - 1].getValue() + 1L); try { JapaneseChronology.INSTANCE.resolveDate(fieldValues, style); fail("Should have failed: " + style); } catch (DateTimeException ex) { // expected } } }
Example 14
Source File: TCKJapaneseChronology.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public void test_resolve_yearOfEra_eraOnly_invalidTooSmall() { for (ResolverStyle style : ResolverStyle.values()) { Map<TemporalField, Long> fieldValues = new HashMap<>(); fieldValues.put(ChronoField.ERA, JapaneseEra.MEIJI.getValue() - 1L); try { JapaneseChronology.INSTANCE.resolveDate(fieldValues, style); fail("Should have failed: " + style); } catch (DateTimeException ex) { // expected } } }
Example 15
Source File: TCKJapaneseChronology.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "resolve_styles") Object[][] data_resolve_styles() { Object[][] result = new Object[ResolverStyle.values().length][]; int i = 0; for (ResolverStyle style : ResolverStyle.values()) { result[i++] = new Object[] {style}; } return result; }
Example 16
Source File: TCKInstantPrinterParser.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_leapSecond() { Instant expected = OffsetDateTime.of(1970, 2, 3, 23, 59, 59, 123456789, ZoneOffset.UTC).toInstant(); DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter(); for (ResolverStyle style : ResolverStyle.values()) { TemporalAccessor parsed = f.withResolverStyle(style).parse("1970-02-03T23:59:60.123456789Z"); assertEquals(parsed.query(Instant::from), expected); assertEquals(parsed.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO); assertEquals(parsed.query(DateTimeFormatter.parsedLeapSecond()), Boolean.TRUE); } }
Example 17
Source File: TCKInstantPrinterParser.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_leapSecond() { Instant expected = OffsetDateTime.of(1970, 2, 3, 23, 59, 59, 123456789, ZoneOffset.UTC).toInstant(); DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter(); for (ResolverStyle style : ResolverStyle.values()) { TemporalAccessor parsed = f.withResolverStyle(style).parse("1970-02-03T23:59:60.123456789Z"); assertEquals(parsed.query(Instant::from), expected); assertEquals(parsed.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO); assertEquals(parsed.query(DateTimeFormatter.parsedLeapSecond()), Boolean.TRUE); } }
Example 18
Source File: TCKInstantPrinterParser.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_endOfDay() { Instant expected = OffsetDateTime.of(1970, 2, 4, 0, 0, 0, 0, ZoneOffset.UTC).toInstant(); DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter(); for (ResolverStyle style : ResolverStyle.values()) { TemporalAccessor parsed = f.withResolverStyle(style).parse("1970-02-03T24:00:00Z"); assertEquals(parsed.query(Instant::from), expected); assertEquals(parsed.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO); assertEquals(parsed.query(DateTimeFormatter.parsedLeapSecond()), Boolean.FALSE); } }
Example 19
Source File: TCKJapaneseChronology.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void test_resolve_yearOfEra_eraOnly_invalidTooLarge() { for (ResolverStyle style : ResolverStyle.values()) { Map<TemporalField, Long> fieldValues = new HashMap<>(); fieldValues.put(ChronoField.ERA, JapaneseEra.values()[JapaneseEra.values().length - 1].getValue() + 1L); try { JapaneseChronology.INSTANCE.resolveDate(fieldValues, style); fail("Should have failed: " + style); } catch (DateTimeException ex) { // expected } } }
Example 20
Source File: TCKResolverStyle.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Test public void test_valueOf() { for (ResolverStyle style : ResolverStyle.values()) { assertEquals(ResolverStyle.valueOf(style.name()), style); } }