java.time.temporal.TemporalQueries Java Examples
The following examples show how to use
java.time.temporal.TemporalQueries.
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: TemporalFormatting.java From constellation with Apache License 2.0 | 6 votes |
/** * Parse the date time value as a ZonedDateTime. Any exception is logged and * absorbed as a convenience method so that processing can continue without * interruptions. * * @param value The date time value * @param formatter The date time formatter * @param logger The logger * @return The zoned date time formatter if it can be parsed correctly, the * original value if it could not be parsed or null otherwise. */ public static String parseAsZonedDateTime(final String value, final DateTimeFormatter formatter, final Logger logger) { if (StringUtils.isBlank(value)) { return null; } try { TemporalAccessor myDateTime = formatter.parse(value); ZoneId parsedTimeZone = myDateTime.query(TemporalQueries.zoneId()); ZoneOffset parsedOffset = myDateTime.query(TemporalQueries.offset()); if ((parsedTimeZone != null) || (parsedOffset != null)) { ZonedDateTime myZonedDateTime = ZonedDateTime.parse(value, formatter); return TemporalFormatting.ZONED_DATE_TIME_FORMATTER.format(myZonedDateTime); } else { return TemporalFormatting.formatAsZonedDateTime(formatter.parse(value)); } } catch (DateTimeParseException ex) { logger.log(Level.SEVERE, ERROR_PARSING_DATE_MESSAGE, new Object[]{value, ex.getMessage()}); return value; } }
Example #2
Source File: TestNumberParser.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="parseDigitsAdjacentLenient") public void test_parseDigitsAdjacentLenient(String input, int parseLen, Integer parseMonth, Integer parsedDay) throws Exception { setStrict(false); ParsePosition pos = new ParsePosition(0); DateTimeFormatter f = builder .appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL) .appendValue(DAY_OF_MONTH, 2).toFormatter(locale).withDecimalStyle(decimalStyle); TemporalAccessor parsed = f.parseUnresolved(input, pos); if (pos.getErrorIndex() != -1) { assertEquals(pos.getErrorIndex(), parseLen); } else { assertEquals(pos.getIndex(), parseLen); assertEquals(parsed.getLong(MONTH_OF_YEAR), (long) parseMonth); assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parsedDay); assertEquals(parsed.query(TemporalQueries.chronology()), null); assertEquals(parsed.query(TemporalQueries.zoneId()), null); } }
Example #3
Source File: TCKZoneIdPrinterParser.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="parseSuccess") public void test_parseSuccess_caseInsensitive(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected) { builder.parseCaseInsensitive().appendZoneId(); String lcText = text.toLowerCase(Locale.ENGLISH); TemporalAccessor parsed = builder.toFormatter().parseUnresolved(lcText, pos); assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + lcText); assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + lcText); if (expected != null) { ZoneId zid = parsed.query(TemporalQueries.zoneId()); assertEquals(parsed.query(TemporalQueries.zoneId()), expected, "Incorrect zoneId parsing: " + lcText); assertEquals(parsed.query(TemporalQueries.offset()), null, "Incorrect offset parsing: " + lcText); assertEquals(parsed.query(TemporalQueries.zone()), expected, "Incorrect zone parsing: " + lcText); } else { assertEquals(parsed, null); } }
Example #4
Source File: DateTimeFormatterBuilder.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
@Override public boolean format(DateTimePrintContext context, StringBuilder buf) { Long value = context.getValue(field); if (value == null) { return false; } String text; Chronology chrono = context.getTemporal().query(TemporalQueries.chronology()); if (chrono == null || chrono == IsoChronology.INSTANCE) { text = provider.getText(field, value, textStyle, context.getLocale()); } else { text = provider.getText(chrono, field, value, textStyle, context.getLocale()); } if (text == null) { return numberPrinterParser().format(context, buf); } buf.append(text); return true; }
Example #5
Source File: TestZoneTextPrinterParser.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private void parse(DateTimeFormatter fmt, String zid, String expected, String text, Locale locale, TextStyle style, boolean ci) { if (ci) { text = text.toUpperCase(); } String ret = fmt.parse(text, TemporalQueries.zone()).getId(); // TBD: need an excluding list // assertEquals(...); if (ret.equals(expected) || ret.equals(zid) || ret.equals(ZoneName.toZid(zid)) || ret.equals(expected.replace("UTC", "UCT"))) { return; } System.out.printf("[%-5s %s %s %16s] %24s -> %s(%s)%n", locale.toString(), ci ? "ci" : " ", style == TextStyle.FULL ? " full" :"short", zid, text, ret, expected); }
Example #6
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 #7
Source File: TCKZoneIdPrinterParser.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="parseSuccess") public void test_parseSuccess_caseInsensitive(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected) { builder.parseCaseInsensitive().appendZoneId(); String lcText = text.toLowerCase(Locale.ENGLISH); TemporalAccessor parsed = builder.toFormatter().parseUnresolved(lcText, pos); assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + lcText); assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + lcText); if (expected != null) { ZoneId zid = parsed.query(TemporalQueries.zoneId()); assertEquals(parsed.query(TemporalQueries.zoneId()), expected, "Incorrect zoneId parsing: " + lcText); assertEquals(parsed.query(TemporalQueries.offset()), null, "Incorrect offset parsing: " + lcText); assertEquals(parsed.query(TemporalQueries.zone()), expected, "Incorrect zone parsing: " + lcText); } else { assertEquals(parsed, null); } }
Example #8
Source File: TCKDateTimeParseResolver.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="resolveAmPm") public void test_resolveAmPm(ResolverStyle style, long value, Integer expectedValue) { String str = Long.toString(value); DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(AMPM_OF_DAY).toFormatter(); if (expectedValue != null) { TemporalAccessor accessor = f.withResolverStyle(style).parse(str); assertEquals(accessor.query(TemporalQueries.localDate()), null); assertEquals(accessor.query(TemporalQueries.localTime()), null); assertEquals(accessor.isSupported(AMPM_OF_DAY), true); assertEquals(accessor.getLong(AMPM_OF_DAY), expectedValue.longValue()); } else { try { f.withResolverStyle(style).parse(str); fail(); } catch (DateTimeParseException ex) { // expected } } }
Example #9
Source File: TCKDateTimeParseResolver.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="resolveFourToDate") public void test_resolveFourToDate(TemporalField field1, long value1, TemporalField field2, long value2, TemporalField field3, long value3, TemporalField field4, long value4, LocalDate expectedDate) { String str = value1 + " " + value2 + " " + value3 + " " + value4; DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(field1).appendLiteral(' ') .appendValue(field2).appendLiteral(' ') .appendValue(field3).appendLiteral(' ') .appendValue(field4).toFormatter(); TemporalAccessor accessor = f.parse(str); assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate); assertEquals(accessor.query(TemporalQueries.localTime()), null); }
Example #10
Source File: TCKDateTimeParseResolver.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="resolveThreeNoChange") public void test_resolveThreeNoChange(TemporalField field1, long value1, TemporalField field2, long value2, TemporalField field3, long value3) { String str = value1 + " " + value2 + " " + value3; DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(field1).appendLiteral(' ') .appendValue(field2).appendLiteral(' ') .appendValue(field3).toFormatter(); TemporalAccessor accessor = f.parse(str); assertEquals(accessor.query(TemporalQueries.localDate()), null); assertEquals(accessor.query(TemporalQueries.localTime()), null); assertEquals(accessor.isSupported(field1), true); assertEquals(accessor.isSupported(field2), true); assertEquals(accessor.isSupported(field3), true); assertEquals(accessor.getLong(field1), value1); assertEquals(accessor.getLong(field2), value2); assertEquals(accessor.getLong(field3), value3); }
Example #11
Source File: TestReducedParser.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test public void test_reducedWithLateChronoChange() { ThaiBuddhistDate date = ThaiBuddhistDate.of(2543, 1, 1); DateTimeFormatter df = new DateTimeFormatterBuilder() .appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1)) .appendLiteral(" ") .appendChronologyId() .toFormatter(); int expected = date.get(YEAR); String input = df.format(date); ParsePosition pos = new ParsePosition(0); TemporalAccessor parsed = df.parseUnresolved(input, pos); assertEquals(pos.getIndex(), input.length(), "Input not parsed completely"); assertEquals(pos.getErrorIndex(), -1, "Error index should be -1 (no-error)"); int actual = parsed.get(YEAR); assertEquals(actual, expected, String.format("Wrong date parsed, chrono: %s, input: %s", parsed.query(TemporalQueries.chronology()), input)); }
Example #12
Source File: DateTimeFormatterBuilder.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public boolean format(DateTimePrintContext context, StringBuilder buf) { ZoneId zone = context.getValue(TemporalQueries.zoneId()); if (zone == null) { return false; } String zname = zone.getId(); if (!(zone instanceof ZoneOffset)) { TemporalAccessor dt = context.getTemporal(); String name = getDisplayName(zname, dt.isSupported(ChronoField.INSTANT_SECONDS) ? (zone.getRules().isDaylightSavings(Instant.from(dt)) ? DST : STD) : GENERIC, context.getLocale()); if (name != null) { zname = name; } } buf.append(zname); return true; }
Example #13
Source File: TCKDateTimeParseResolver.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="resolveClockHourOfDay") public void test_resolveClockHourOfDay(ResolverStyle style, long value, Integer expectedHour, int expectedDays) { String str = Long.toString(value); DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(CLOCK_HOUR_OF_DAY).toFormatter(); if (expectedHour != null) { TemporalAccessor accessor = f.withResolverStyle(style).parse(str); assertEquals(accessor.query(TemporalQueries.localDate()), null); assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(expectedHour, 0)); assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays)); } else { try { f.withResolverStyle(style).parse(str); fail(); } catch (DateTimeParseException ex) { // expected } } }
Example #14
Source File: JsonRowDeserializationSchema.java From flink with Apache License 2.0 | 6 votes |
private DeserializationRuntimeConverter createTimestampConverter() { return (mapper, jsonNode) -> { // according to RFC 3339 every date-time must have a timezone; // until we have full timezone support, we only support UTC; // users can parse their time as string as a workaround TemporalAccessor parsedTimestamp = RFC3339_TIMESTAMP_FORMAT.parse(jsonNode.asText()); ZoneOffset zoneOffset = parsedTimestamp.query(TemporalQueries.offset()); if (zoneOffset != null && zoneOffset.getTotalSeconds() != 0) { throw new IllegalStateException( "Invalid timestamp format. Only a timestamp in UTC timezone is supported yet. " + "Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); } LocalTime localTime = parsedTimestamp.query(TemporalQueries.localTime()); LocalDate localDate = parsedTimestamp.query(TemporalQueries.localDate()); return Timestamp.valueOf(LocalDateTime.of(localDate, localTime)); }; }
Example #15
Source File: TestZoneTextPrinterParser.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="preferredZones") public void test_ParseText(String expected, String text, Set<ZoneId> preferred, Locale locale, TextStyle style) { DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendZoneText(style, preferred) .toFormatter(locale) .withDecimalStyle(DecimalStyle.of(locale)); String ret = fmt.parse(text, TemporalQueries.zone()).getId(); System.out.printf("[%-5s %s] %24s -> %s(%s)%n", locale.toString(), style == TextStyle.FULL ? " full" :"short", text, ret, expected); assertEquals(ret, expected); }
Example #16
Source File: TCKDateTimeParseResolver.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="resolveFourToDate") public void test_resolveFourToDate(TemporalField field1, long value1, TemporalField field2, long value2, TemporalField field3, long value3, TemporalField field4, long value4, LocalDate expectedDate) { String str = value1 + " " + value2 + " " + value3 + " " + value4; DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(field1).appendLiteral(' ') .appendValue(field2).appendLiteral(' ') .appendValue(field3).appendLiteral(' ') .appendValue(field4).toFormatter(); TemporalAccessor accessor = f.parse(str); assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate); assertEquals(accessor.query(TemporalQueries.localTime()), null); }
Example #17
Source File: TestZoneTextPrinterParser.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="preferredZones") public void test_ParseText(String expected, String text, Set<ZoneId> preferred, Locale locale, TextStyle style) { DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendZoneText(style, preferred) .toFormatter(locale) .withDecimalStyle(DecimalStyle.of(locale)); String ret = fmt.parse(text, TemporalQueries.zone()).getId(); System.out.printf("[%-5s %s] %24s -> %s(%s)%n", locale.toString(), style == TextStyle.FULL ? " full" :"short", text, ret, expected); assertEquals(ret, expected); }
Example #18
Source File: DateTimeFormatterBuilder.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override public boolean format(DateTimePrintContext context, StringBuilder buf) { ZoneId zone = context.getValue(TemporalQueries.zoneId()); if (zone == null) { return false; } String zname = zone.getId(); if (!(zone instanceof ZoneOffset)) { TemporalAccessor dt = context.getTemporal(); String name = getDisplayName(zname, dt.isSupported(ChronoField.INSTANT_SECONDS) ? (zone.getRules().isDaylightSavings(Instant.from(dt)) ? DST : STD) : GENERIC, context.getLocale()); if (name != null) { zname = name; } } buf.append(zname); return true; }
Example #19
Source File: DateTimeFormatterBuilder.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override public boolean format(DateTimePrintContext context, StringBuilder buf) { Long value = context.getValue(field); if (value == null) { return false; } String text; Chronology chrono = context.getTemporal().query(TemporalQueries.chronology()); if (chrono == null || chrono == IsoChronology.INSTANCE) { text = provider.getText(field, value, textStyle, context.getLocale()); } else { text = provider.getText(chrono, field, value, textStyle, context.getLocale()); } if (text == null) { return numberPrinterParser().format(context, buf); } buf.append(text); return true; }
Example #20
Source File: TCKDateTimeParseResolver.java From dragonwell8_jdk 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 #21
Source File: TCKDateTimeParseResolver.java From dragonwell8_jdk 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 #22
Source File: TCKDateTimeParseResolver.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="resolveMinuteOfDay") public void test_resolveMinuteOfDay(ResolverStyle style, long value, Integer expectedMinute, int expectedDays) { String str = Long.toString(value); DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(MINUTE_OF_DAY).toFormatter(); if (expectedMinute != null) { TemporalAccessor accessor = f.withResolverStyle(style).parse(str); assertEquals(accessor.query(TemporalQueries.localDate()), null); assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedMinute * 60)); assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays)); } else { try { f.withResolverStyle(style).parse(str); fail(); } catch (DateTimeParseException ex) { // expected } } }
Example #23
Source File: TCKZoneIdPrinterParser.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="parseSuccess") public void test_parseSuccess_prefix(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected) { builder.appendZoneId(); pos.setIndex(3); String prefixText = "XXX" + text; TemporalAccessor parsed = builder.toFormatter().parseUnresolved(prefixText, pos); assertEquals(pos.getErrorIndex(), expectedErrorIndex >= 0 ? expectedErrorIndex + 3 : expectedErrorIndex, "Incorrect error index parsing: " + prefixText); assertEquals(pos.getIndex(), expectedIndex + 3, "Incorrect index parsing: " + prefixText); if (expected != null) { assertEquals(parsed.query(TemporalQueries.zoneId()), expected, "Incorrect zoneId parsing: " + prefixText); assertEquals(parsed.query(TemporalQueries.offset()), null, "Incorrect offset parsing: " + prefixText); assertEquals(parsed.query(TemporalQueries.zone()), expected, "Incorrect zone parsing: " + prefixText); } else { assertEquals(parsed, null); } }
Example #24
Source File: TCKDateTimeParseResolver.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="resolveClockHourOfAmPm") public void test_resolveClockHourOfAmPm(ResolverStyle style, long value, Integer expectedValue) { String str = Long.toString(value); DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(CLOCK_HOUR_OF_AMPM).toFormatter(); if (expectedValue != null) { TemporalAccessor accessor = f.withResolverStyle(style).parse(str); assertEquals(accessor.query(TemporalQueries.localDate()), null); assertEquals(accessor.query(TemporalQueries.localTime()), null); assertEquals(accessor.isSupported(CLOCK_HOUR_OF_AMPM), false); assertEquals(accessor.isSupported(HOUR_OF_AMPM), true); assertEquals(accessor.getLong(HOUR_OF_AMPM), expectedValue.longValue()); } else { try { f.withResolverStyle(style).parse(str); fail(); } catch (DateTimeParseException ex) { // expected } } }
Example #25
Source File: TCKDateTimeParseResolver.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="resolveTwoNoChange") public void test_resolveTwoNoChange(TemporalField field1, long value1, TemporalField field2, long value2) { String str = value1 + " " + value2; DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(field1).appendLiteral(' ') .appendValue(field2).toFormatter(); TemporalAccessor accessor = f.parse(str); assertEquals(accessor.query(TemporalQueries.localDate()), null); assertEquals(accessor.query(TemporalQueries.localTime()), null); assertEquals(accessor.isSupported(field1), true); assertEquals(accessor.isSupported(field2), true); assertEquals(accessor.getLong(field1), value1); assertEquals(accessor.getLong(field2), value2); }
Example #26
Source File: TestNumberParser.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="parseSignsLenient") public void test_parseSignsLenient(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception { setStrict(false); ParsePosition pos = new ParsePosition(0); TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos); if (pos.getErrorIndex() != -1) { assertEquals(pos.getErrorIndex(), parseLen); } else { assertEquals(pos.getIndex(), parseLen); assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal); assertEquals(parsed.query(TemporalQueries.chronology()), null); assertEquals(parsed.query(TemporalQueries.zoneId()), null); } }
Example #27
Source File: TCKDateTimeParseResolver.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="resolveOneNoChange") public void test_resolveOneNoChange(TemporalField field1, long value1) { String str = Long.toString(value1); DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).toFormatter(); TemporalAccessor accessor = f.parse(str); assertEquals(accessor.query(TemporalQueries.localDate()), null); assertEquals(accessor.query(TemporalQueries.localTime()), null); assertEquals(accessor.isSupported(field1), true); assertEquals(accessor.getLong(field1), value1); }
Example #28
Source File: TCKDateTimeParseResolver.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_fieldResolvesToChronoLocalDateTime_overrideChrono_matches() { MinguoDate mdt = MinguoDate.of(100, 6, 30); DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(mdt.atTime(LocalTime.NOON))).toFormatter(); f = f.withChronology(MinguoChronology.INSTANCE); TemporalAccessor accessor = f.parse("1234567890"); assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.from(mdt)); assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.NOON); assertEquals(accessor.query(TemporalQueries.chronology()), MinguoChronology.INSTANCE); }
Example #29
Source File: TCKDateTimeParseResolver.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="resolveTwoToTime") public void test_resolveTwoToTime(TemporalField field1, long value1, TemporalField field2, long value2, LocalTime expectedTime) { String str = value1 + " " + value2; DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(field1).appendLiteral(' ') .appendValue(field2).toFormatter(); TemporalAccessor accessor = f.parse(str); assertEquals(accessor.query(TemporalQueries.localDate()), null); assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime); }
Example #30
Source File: TCKDateTimeFormatters.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private void assertParseMatch(TemporalAccessor parsed, Expected expected) { for (TemporalField field : expected.fieldValues.keySet()) { assertEquals(parsed.isSupported(field), true); parsed.getLong(field); } assertEquals(parsed.query(TemporalQueries.chronology()), expected.chrono); assertEquals(parsed.query(TemporalQueries.zoneId()), expected.zone); }