Java Code Examples for java.time.zone.ZoneOffsetTransition#isGap()

The following examples show how to use java.time.zone.ZoneOffsetTransition#isGap() . 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: ZonedDateTime.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
Example 2
Source File: ZonedDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 * @throws DateTimeException if the combination of arguments is invalid
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
Example 3
Source File: ZonedDateTime.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
Example 4
Source File: ZonedDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
Example 5
Source File: ZonedDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
Example 6
Source File: ZonedDateTime.java    From desugar_jdk_libs with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
Example 7
Source File: ZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
Example 8
Source File: ZonedDateTime.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
Example 9
Source File: ZonedDateTime.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
Example 10
Source File: ZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
Example 11
Source File: ZonedDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
Example 12
Source File: LocalDate.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a zoned date-time from this date at the earliest valid time according
 * to the rules in the time-zone.
 * <p>
 * Time-zone rules, such as daylight savings, mean that not every local date-time
 * is valid for the specified zone, thus the local date-time may not be midnight.
 * <p>
 * In most cases, there is only one valid offset for a local date-time.
 * In the case of an overlap, there are two valid offsets, and the earlier one is used,
 * corresponding to the first occurrence of midnight on the date.
 * In the case of a gap, the zoned date-time will represent the instant just after the gap.
 * <p>
 * If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
 * <p>
 * To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)}
 * followed by {@link LocalDateTime#atZone(ZoneId)}.
 *
 * @param zone  the zone ID to use, not null
 * @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
 */
public ZonedDateTime atStartOfDay(ZoneId zone) {
    Objects.requireNonNull(zone, "zone");
    // need to handle case where there is a gap from 11:30 to 00:30
    // standard ZDT factory would result in 01:00 rather than 00:30
    LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
    if (zone instanceof ZoneOffset == false) {
        ZoneRules rules = zone.getRules();
        ZoneOffsetTransition trans = rules.getTransition(ldt);
        if (trans != null && trans.isGap()) {
            ldt = trans.getDateTimeAfter();
        }
    }
    return ZonedDateTime.of(ldt, zone);
}
 
Example 13
Source File: LocalDate.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a zoned date-time from this date at the earliest valid time according
 * to the rules in the time-zone.
 * <p>
 * Time-zone rules, such as daylight savings, mean that not every local date-time
 * is valid for the specified zone, thus the local date-time may not be midnight.
 * <p>
 * In most cases, there is only one valid offset for a local date-time.
 * In the case of an overlap, there are two valid offsets, and the earlier one is used,
 * corresponding to the first occurrence of midnight on the date.
 * In the case of a gap, the zoned date-time will represent the instant just after the gap.
 * <p>
 * If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
 * <p>
 * To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)}
 * followed by {@link LocalDateTime#atZone(ZoneId)}.
 *
 * @param zone  the zone ID to use, not null
 * @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
 */
public ZonedDateTime atStartOfDay(ZoneId zone) {
    Objects.requireNonNull(zone, "zone");
    // need to handle case where there is a gap from 11:30 to 00:30
    // standard ZDT factory would result in 01:00 rather than 00:30
    LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
    if (zone instanceof ZoneOffset == false) {
        ZoneRules rules = zone.getRules();
        ZoneOffsetTransition trans = rules.getTransition(ldt);
        if (trans != null && trans.isGap()) {
            ldt = trans.getDateTimeAfter();
        }
    }
    return ZonedDateTime.of(ldt, zone);
}
 
Example 14
Source File: LocalDate.java    From desugar_jdk_libs with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a zoned date-time from this date at the earliest valid time according
 * to the rules in the time-zone.
 * <p>
 * Time-zone rules, such as daylight savings, mean that not every local date-time
 * is valid for the specified zone, thus the local date-time may not be midnight.
 * <p>
 * In most cases, there is only one valid offset for a local date-time.
 * In the case of an overlap, there are two valid offsets, and the earlier one is used,
 * corresponding to the first occurrence of midnight on the date.
 * In the case of a gap, the zoned date-time will represent the instant just after the gap.
 * <p>
 * If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
 * <p>
 * To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)}
 * followed by {@link LocalDateTime#atZone(ZoneId)}.
 *
 * @param zone  the zone ID to use, not null
 * @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
 */
public ZonedDateTime atStartOfDay(ZoneId zone) {
    Objects.requireNonNull(zone, "zone");
    // need to handle case where there is a gap from 11:30 to 00:30
    // standard ZDT factory would result in 01:00 rather than 00:30
    LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
    if (zone instanceof ZoneOffset == false) {
        ZoneRules rules = zone.getRules();
        ZoneOffsetTransition trans = rules.getTransition(ldt);
        if (trans != null && trans.isGap()) {
            ldt = trans.getDateTimeAfter();
        }
    }
    return ZonedDateTime.of(ldt, zone);
}
 
Example 15
Source File: LocalDate.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a zoned date-time from this date at the earliest valid time according
 * to the rules in the time-zone.
 * <p>
 * Time-zone rules, such as daylight savings, mean that not every local date-time
 * is valid for the specified zone, thus the local date-time may not be midnight.
 * <p>
 * In most cases, there is only one valid offset for a local date-time.
 * In the case of an overlap, there are two valid offsets, and the earlier one is used,
 * corresponding to the first occurrence of midnight on the date.
 * In the case of a gap, the zoned date-time will represent the instant just after the gap.
 * <p>
 * If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
 * <p>
 * To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)}
 * followed by {@link LocalDateTime#atZone(ZoneId)}.
 *
 * @param zone  the zone ID to use, not null
 * @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
 */
public ZonedDateTime atStartOfDay(ZoneId zone) {
    Objects.requireNonNull(zone, "zone");
    // need to handle case where there is a gap from 11:30 to 00:30
    // standard ZDT factory would result in 01:00 rather than 00:30
    LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
    if (zone instanceof ZoneOffset == false) {
        ZoneRules rules = zone.getRules();
        ZoneOffsetTransition trans = rules.getTransition(ldt);
        if (trans != null && trans.isGap()) {
            ldt = trans.getDateTimeAfter();
        }
    }
    return ZonedDateTime.of(ldt, zone);
}
 
Example 16
Source File: LocalDate.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a zoned date-time from this date at the earliest valid time according
 * to the rules in the time-zone.
 * <p>
 * Time-zone rules, such as daylight savings, mean that not every local date-time
 * is valid for the specified zone, thus the local date-time may not be midnight.
 * <p>
 * In most cases, there is only one valid offset for a local date-time.
 * In the case of an overlap, there are two valid offsets, and the earlier one is used,
 * corresponding to the first occurrence of midnight on the date.
 * In the case of a gap, the zoned date-time will represent the instant just after the gap.
 * <p>
 * If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
 * <p>
 * To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)}
 * followed by {@link LocalDateTime#atZone(ZoneId)}.
 *
 * @param zone  the zone ID to use, not null
 * @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
 */
public ZonedDateTime atStartOfDay(ZoneId zone) {
    Objects.requireNonNull(zone, "zone");
    // need to handle case where there is a gap from 11:30 to 00:30
    // standard ZDT factory would result in 01:00 rather than 00:30
    LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
    if (zone instanceof ZoneOffset == false) {
        ZoneRules rules = zone.getRules();
        ZoneOffsetTransition trans = rules.getTransition(ldt);
        if (trans != null && trans.isGap()) {
            ldt = trans.getDateTimeAfter();
        }
    }
    return ZonedDateTime.of(ldt, zone);
}
 
Example 17
Source File: LocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a zoned date-time from this date at the earliest valid time according
 * to the rules in the time-zone.
 * <p>
 * Time-zone rules, such as daylight savings, mean that not every local date-time
 * is valid for the specified zone, thus the local date-time may not be midnight.
 * <p>
 * In most cases, there is only one valid offset for a local date-time.
 * In the case of an overlap, there are two valid offsets, and the earlier one is used,
 * corresponding to the first occurrence of midnight on the date.
 * In the case of a gap, the zoned date-time will represent the instant just after the gap.
 * <p>
 * If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
 * <p>
 * To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)}
 * followed by {@link LocalDateTime#atZone(ZoneId)}.
 *
 * @param zone  the zone ID to use, not null
 * @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
 */
public ZonedDateTime atStartOfDay(ZoneId zone) {
    Objects.requireNonNull(zone, "zone");
    // need to handle case where there is a gap from 11:30 to 00:30
    // standard ZDT factory would result in 01:00 rather than 00:30
    LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
    if (zone instanceof ZoneOffset == false) {
        ZoneRules rules = zone.getRules();
        ZoneOffsetTransition trans = rules.getTransition(ldt);
        if (trans != null && trans.isGap()) {
            ldt = trans.getDateTimeAfter();
        }
    }
    return ZonedDateTime.of(ldt, zone);
}
 
Example 18
Source File: LocalDate.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a zoned date-time from this date at the earliest valid time according
 * to the rules in the time-zone.
 * <p>
 * Time-zone rules, such as daylight savings, mean that not every local date-time
 * is valid for the specified zone, thus the local date-time may not be midnight.
 * <p>
 * In most cases, there is only one valid offset for a local date-time.
 * In the case of an overlap, there are two valid offsets, and the earlier one is used,
 * corresponding to the first occurrence of midnight on the date.
 * In the case of a gap, the zoned date-time will represent the instant just after the gap.
 * <p>
 * If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
 * <p>
 * To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)}
 * followed by {@link LocalDateTime#atZone(ZoneId)}.
 *
 * @param zone  the zone ID to use, not null
 * @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
 */
public ZonedDateTime atStartOfDay(ZoneId zone) {
    Objects.requireNonNull(zone, "zone");
    // need to handle case where there is a gap from 11:30 to 00:30
    // standard ZDT factory would result in 01:00 rather than 00:30
    LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
    if (zone instanceof ZoneOffset == false) {
        ZoneRules rules = zone.getRules();
        ZoneOffsetTransition trans = rules.getTransition(ldt);
        if (trans != null && trans.isGap()) {
            ldt = trans.getDateTimeAfter();
        }
    }
    return ZonedDateTime.of(ldt, zone);
}
 
Example 19
Source File: LocalDate.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a zoned date-time from this date at the earliest valid time according
 * to the rules in the time-zone.
 * <p>
 * Time-zone rules, such as daylight savings, mean that not every local date-time
 * is valid for the specified zone, thus the local date-time may not be midnight.
 * <p>
 * In most cases, there is only one valid offset for a local date-time.
 * In the case of an overlap, there are two valid offsets, and the earlier one is used,
 * corresponding to the first occurrence of midnight on the date.
 * In the case of a gap, the zoned date-time will represent the instant just after the gap.
 * <p>
 * If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
 * <p>
 * To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)}
 * followed by {@link LocalDateTime#atZone(ZoneId)}.
 *
 * @param zone  the zone ID to use, not null
 * @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
 */
public ZonedDateTime atStartOfDay(ZoneId zone) {
    Objects.requireNonNull(zone, "zone");
    // need to handle case where there is a gap from 11:30 to 00:30
    // standard ZDT factory would result in 01:00 rather than 00:30
    LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
    if (zone instanceof ZoneOffset == false) {
        ZoneRules rules = zone.getRules();
        ZoneOffsetTransition trans = rules.getTransition(ldt);
        if (trans != null && trans.isGap()) {
            ldt = trans.getDateTimeAfter();
        }
    }
    return ZonedDateTime.of(ldt, zone);
}
 
Example 20
Source File: LocalDate.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a zoned date-time from this date at the earliest valid time according
 * to the rules in the time-zone.
 * <p>
 * Time-zone rules, such as daylight savings, mean that not every local date-time
 * is valid for the specified zone, thus the local date-time may not be midnight.
 * <p>
 * In most cases, there is only one valid offset for a local date-time.
 * In the case of an overlap, there are two valid offsets, and the earlier one is used,
 * corresponding to the first occurrence of midnight on the date.
 * In the case of a gap, the zoned date-time will represent the instant just after the gap.
 * <p>
 * If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
 * <p>
 * To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)}
 * followed by {@link LocalDateTime#atZone(ZoneId)}.
 *
 * @param zone  the zone ID to use, not null
 * @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
 */
public ZonedDateTime atStartOfDay(ZoneId zone) {
    Objects.requireNonNull(zone, "zone");
    // need to handle case where there is a gap from 11:30 to 00:30
    // standard ZDT factory would result in 01:00 rather than 00:30
    LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
    if (zone instanceof ZoneOffset == false) {
        ZoneRules rules = zone.getRules();
        ZoneOffsetTransition trans = rules.getTransition(ldt);
        if (trans != null && trans.isGap()) {
            ldt = trans.getDateTimeAfter();
        }
    }
    return ZonedDateTime.of(ldt, zone);
}