当前位置: 首页>>代码示例>>Java>>正文


Java TemporalQueries类代码示例

本文整理汇总了Java中java.time.temporal.TemporalQueries的典型用法代码示例。如果您正苦于以下问题:Java TemporalQueries类的具体用法?Java TemporalQueries怎么用?Java TemporalQueries使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TemporalQueries类属于java.time.temporal包,在下文中一共展示了TemporalQueries类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: format

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:DateTimeFormatterBuilder.java

示例2: test_ParseText

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@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);

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TestZoneTextPrinterParser.java

示例3: format

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:DateTimeFormatterBuilder.java

示例4: test_resolveClockHourOfAmPm

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@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
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:TCKDateTimeParseResolver.java

示例5: test_parseDigitsAdjacentLenient

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TestNumberParser.java

示例6: test_resolveThreeNoChange

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TCKDateTimeParseResolver.java

示例7: test_resolveOneToField

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@Test(dataProvider="resolveOneToField")
public void test_resolveOneToField(TemporalField field1, long value1,
                                   TemporalField expectedField1, Long expectedValue1,
                                   TemporalField expectedField2, Long expectedValue2) {
    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);
    if (expectedField1 != null) {
        assertEquals(accessor.isSupported(expectedField1), true);
        assertEquals(accessor.getLong(expectedField1), expectedValue1.longValue());
    }
    if (expectedField2 != null) {
        assertEquals(accessor.isSupported(expectedField2), true);
        assertEquals(accessor.getLong(expectedField2), expectedValue2.longValue());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKDateTimeParseResolver.java

示例8: test_resolveTwoToField

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@Test(dataProvider="resolveTwoToField")
public void test_resolveTwoToField(TemporalField field1, long value1,
                                   TemporalField field2, long value2,
                                   TemporalField expectedField1, Long expectedValue1,
                                   TemporalField expectedField2, Long expectedValue2) {
    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);
    if (expectedField1 != null) {
        assertEquals(accessor.isSupported(expectedField1), true);
        assertEquals(accessor.getLong(expectedField1), expectedValue1.longValue());
    }
    if (expectedField2 != null) {
        assertEquals(accessor.isSupported(expectedField2), true);
        assertEquals(accessor.getLong(expectedField2), expectedValue2.longValue());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:TCKDateTimeParseResolver.java

示例9: test_resolveFourToTime

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@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
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:TCKDateTimeParseResolver.java

示例10: test_resolveThreeToTime

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@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
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:TCKDateTimeParseResolver.java

示例11: test_resolveSecondOfDay

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@Test(dataProvider="resolveSecondOfDay")
public void test_resolveSecondOfDay(ResolverStyle style, long value, Integer expectedSecond, int expectedDays) {
    String str = Long.toString(value);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(SECOND_OF_DAY).toFormatter();

    if (expectedSecond != null) {
        TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
        assertEquals(accessor.query(TemporalQueries.localDate()), null);
        assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedSecond));
        assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
    } else {
        try {
            f.withResolverStyle(style).parse(str);
            fail();
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKDateTimeParseResolver.java

示例12: test

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
private void test(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected,
                  boolean isZoneOffset) {
    TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text, pos);
    assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + text);
    assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + text);
    if (expected != null) {
        assertEquals(parsed.query(TemporalQueries.zoneId()),
                     expected,
                     "Incorrect zoneId parsing: " + text);
        assertEquals(parsed.query(TemporalQueries.offset()),
                     isZoneOffset ? expected : null,
                     "Incorrect offset parsing: " + text);
        assertEquals(parsed.query(TemporalQueries.zone()),
                     expected,
                     "Incorrect zone parsing: " + text);
    } else {
        assertEquals(parsed, null);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TCKZoneIdPrinterParser.java

示例13: test_resolveClockHourOfDay

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@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
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKDateTimeParseResolver.java

示例14: test_resolveAmPm

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@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
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:TCKDateTimeParseResolver.java

示例15: test_parse_textField

import java.time.temporal.TemporalQueries; //导入依赖的package包/类
@Test(dataProvider="parseData")
public void test_parse_textField(int minWidth, int maxWidth, SignStyle signStyle, int subsequentWidth, String text, int pos, int expectedPos, long expectedValue) {
    ParsePosition ppos = new ParsePosition(pos);
    DateTimeFormatter dtf = getFormatter(DAY_OF_WEEK, minWidth, maxWidth, signStyle);
    if (subsequentWidth > 0) {
        // hacky, to reserve space
        dtf = builder.appendValue(DAY_OF_YEAR, subsequentWidth).toFormatter(locale).withDecimalStyle(decimalStyle);
    }
    TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), expectedPos);
    } else {
        assertTrue(subsequentWidth >= 0);
        assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
        assertEquals(parsed.getLong(DAY_OF_WEEK), expectedValue);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TestNumberParser.java


注:本文中的java.time.temporal.TemporalQueries类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。