Java Code Examples for java.time.zone.ZoneRules#isValidOffset()
The following examples show how to use
java.time.zone.ZoneRules#isValidOffset() .
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 openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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 2
Source File: ZonedDateTime.java From j2objc with Apache License 2.0 | 6 votes |
/** * 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 3
Source File: ZonedDateTime.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * 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 jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * 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 jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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 openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * 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 openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * 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: ZonedDateTime.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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 13
Source File: ZonedDateTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * 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 14
Source File: ZonedDateTime.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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 15
Source File: ZonedDateTime.java From desugar_jdk_libs with GNU General Public License v2.0 | 6 votes |
/** * 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 16
Source File: ZonedDateTime.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * 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 17
Source File: ZonedDateTime.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * 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 18
Source File: ZonedDateTime.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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 19
Source File: ZonedDateTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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); }