150 offset = trans.getOffsetAfter();
151 } else {
152 if (preferredOffset != null && validOffsets.contains(preferredOffset)) {
153 offset = preferredOffset;
154 } else {
155 offset = validOffsets.get(0);
156 }
157 }
158 Objects.requireNonNull(offset, "offset"); // protect against bad ZoneRules
159 return new ChronoZonedDateTimeImpl<>(localDateTime, offset, zone);
160 }
161
162 /**
163 * Obtains an instance from an instant using the specified time-zone.
164 *
165 * @param chrono the chronology, not null
166 * @param instant the instant, not null
167 * @param zone the zone identifier, not null
168 * @return the zoned date-time, not null
169 */
170 static ChronoZonedDateTimeImpl<?> ofInstant(Chronology chrono, Instant instant, ZoneId zone) {
171 ZoneRules rules = zone.getRules();
172 ZoneOffset offset = rules.getOffset(instant);
173 Objects.requireNonNull(offset, "offset"); // protect against bad ZoneRules
174 LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
175 ChronoLocalDateTimeImpl<?> cldt = (ChronoLocalDateTimeImpl<?>) chrono.localDateTime(ldt);
176 return new ChronoZonedDateTimeImpl(cldt, offset, zone);
177 }
178
179 /**
180 * Obtains an instance from an {@code Instant}.
181 *
182 * @param instant the instant to create the date-time from, not null
183 * @param zone the time-zone to use, validated not null
184 * @return the zoned date-time, validated not null
185 */
186 private ChronoZonedDateTimeImpl<D> create(Instant instant, ZoneId zone) {
187 return (ChronoZonedDateTimeImpl<D>)ofInstant(toLocalDate().getChronology(), instant, zone);
188 }
189
|
150 offset = trans.getOffsetAfter();
151 } else {
152 if (preferredOffset != null && validOffsets.contains(preferredOffset)) {
153 offset = preferredOffset;
154 } else {
155 offset = validOffsets.get(0);
156 }
157 }
158 Objects.requireNonNull(offset, "offset"); // protect against bad ZoneRules
159 return new ChronoZonedDateTimeImpl<>(localDateTime, offset, zone);
160 }
161
162 /**
163 * Obtains an instance from an instant using the specified time-zone.
164 *
165 * @param chrono the chronology, not null
166 * @param instant the instant, not null
167 * @param zone the zone identifier, not null
168 * @return the zoned date-time, not null
169 */
170 @SuppressWarnings("rawtypes")
171 static ChronoZonedDateTimeImpl<?> ofInstant(Chronology chrono, Instant instant, ZoneId zone) {
172 ZoneRules rules = zone.getRules();
173 ZoneOffset offset = rules.getOffset(instant);
174 Objects.requireNonNull(offset, "offset"); // protect against bad ZoneRules
175 LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
176 ChronoLocalDateTimeImpl<?> cldt = (ChronoLocalDateTimeImpl<?>) chrono.localDateTime(ldt);
177 return new ChronoZonedDateTimeImpl(cldt, offset, zone);
178 }
179
180 /**
181 * Obtains an instance from an {@code Instant}.
182 *
183 * @param instant the instant to create the date-time from, not null
184 * @param zone the time-zone to use, validated not null
185 * @return the zoned date-time, validated not null
186 */
187 private ChronoZonedDateTimeImpl<D> create(Instant instant, ZoneId zone) {
188 return (ChronoZonedDateTimeImpl<D>)ofInstant(toLocalDate().getChronology(), instant, zone);
189 }
190
|