Java Code Examples for java.time.ZonedDateTime#toInstant()

The following examples show how to use java.time.ZonedDateTime#toInstant() . 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: ExpChartController.java    From logbook-kai with MIT License 6 votes vote down vote up
/**
 * グラフデータを読み込み
 * 
 * @param type 種類
 * @param scale 期間
 * @param min 期間の最小(自身を含む)
 * @param max 期間の最大(自身を含まない)
 * @return グラフデータ
 */
private Map<ZonedDateTime, Double> load(TypeOption type, ScaleOption scale, ZonedDateTime min, ZonedDateTime max) {
    Map<ZonedDateTime, Double> map = new LinkedHashMap<>();
    // 空のデータを作る
    ZonedDateTime current = min;
    while (current.compareTo(max) < 0) {
        map.put(current, 0D);
        current = current.plus(scale.getTick());
    }
    // ログから読み込み
    Instant minInstant = min.toInstant();
    Instant maxInstant = max.toInstant();

    List<SimpleBattleLog> logs = BattleLogs.readSimpleLog(log -> {
        Instant a = log.getDate().toInstant();
        return a.compareTo(minInstant) >= 0 && a.compareTo(maxInstant) < 0;
    });
    map.putAll(logs.stream()
            .collect(Collectors.groupingBy(log -> scale.convert(log.getDate(), type),
                    Collectors.summingDouble(type::convert))));
    return map;
}
 
Example 2
Source File: TCKZoneRules.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void test_London_preTimeZones() {
    ZoneRules test = europeLondon();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, -1, -15);
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
 
Example 3
Source File: TCKZoneRules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void test_NewYork_preTimeZones() {
    ZoneRules test = americaNewYork();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.of("-04:56:02");
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
 
Example 4
Source File: TCKZonedDateTime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="toInstant")
public void test_toInstant_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_M0100);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec + 3600);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 5
Source File: TCKZoneRules.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void test_NewYork_preTimeZones() {
    ZoneRules test = americaNewYork();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.of("-04:56:02");
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
 
Example 6
Source File: TCKZoneRules.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_London_getStandardOffset() {
    ZoneRules test = europeLondon();
    ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
    while (zdt.getYear() < 2010) {
        Instant instant = zdt.toInstant();
        if (zdt.getYear() < 1848) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15));
        } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        } else {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        }
        zdt = zdt.plusMonths(6);
    }
}
 
Example 7
Source File: TCKZonedDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="toInstant")
public void test_toInstant_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_M0100);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec + 3600);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 8
Source File: TCKZoneRules.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void test_London_getStandardOffset() {
    ZoneRules test = europeLondon();
    ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
    while (zdt.getYear() < 2010) {
        Instant instant = zdt.toInstant();
        if (zdt.getYear() < 1848) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15));
        } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        } else {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        }
        zdt = zdt.plusMonths(6);
    }
}
 
Example 9
Source File: TCKZonedDateTime.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="toInstant")
public void test_toInstant_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_M0100);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec + 3600);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 10
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="toInstant")
public void test_toInstant_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_0100);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec - 3600);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 11
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="toInstant")
public void test_toInstant_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_M0100);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec + 3600);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 12
Source File: TCKZoneRules.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_London_preTimeZones() {
    ZoneRules test = europeLondon();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, -1, -15);
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
 
Example 13
Source File: TCKZonedDateTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test()
@UseDataProvider("data_toInstant")
public void test_toInstant_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_M0100);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec + 3600);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 14
Source File: TCKZoneRules.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void test_Paris_preTimeZones() {
    ZoneRules test = europeParis();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, 9, 21);
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
 
Example 15
Source File: TCKZoneRules.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_Paris_preTimeZones() {
    ZoneRules test = europeParis();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, 9, 21);
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
 
Example 16
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="toInstant")
public void test_toInstant_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_M0100);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec + 3600);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 17
Source File: TCKZoneRules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void test_NewYork_getStandardOffset() {
    ZoneRules test = americaNewYork();
    ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC);
    while (dateTime.getYear() < 2010) {
        Instant instant = dateTime.toInstant();
        if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02"));
        } else {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5));
        }
        dateTime = dateTime.plusMonths(6);
    }
}
 
Example 18
Source File: FederationProcessorImpl.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
private LifeTime processLifeTime(Element lifetimeElem) throws ProcessingException {
    Element createdElem = DOMUtils.getFirstChildWithName(lifetimeElem, WSConstants.WSU_NS,
                                                         WSConstants.CREATED_LN);

    ZonedDateTime createdDateTime = ZonedDateTime.parse(DOMUtils.getContent(createdElem));

    Element expiresElem = DOMUtils.getFirstChildWithName(lifetimeElem, WSConstants.WSU_NS,
                                                         WSConstants.EXPIRES_LN);
    ZonedDateTime expiresDateTime = ZonedDateTime.parse(DOMUtils.getContent(expiresElem));

    return new LifeTime(createdDateTime.toInstant(), expiresDateTime.toInstant());
}
 
Example 19
Source File: TCKZonedDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="toInstant")
public void test_toInstant_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 20
Source File: DateTimeExpression.java    From jstarcraft-core with Apache License 2.0 2 votes vote down vote up
/**
 * 根据指定日期时间获取下一次日期时间
 * 
 * @param dateTime
 * @return
 */
public Instant getNextDateTime(Instant dateTime) {
    ZonedDateTime instant = getNextDateTime(ZonedDateTime.ofInstant(dateTime, ZoneOffset.UTC));
    return instant == null ? null : instant.toInstant();
}