/** * Resolves the new local date-time using the offset to identify the instant. * * @param newDateTime the new local date-time, not null * @return the zoned date-time, not null */ private ZonedDateTime resolveInstant(LocalDateTime newDateTime) { return ofInstant(newDateTime, offset, zone); }
/** * Resolves the new local date-time using the offset to identify the instant. * * @param newDateTime the new local date-time, not null * @return the zoned date-time, not null */ private ZonedDateTime resolveInstant(LocalDateTime newDateTime) { return ofInstant(newDateTime, offset, zone); }
/** * Obtains an ISO zoned date-time from an instant. * <p> * This is equivalent to {@link ZonedDateTime#ofInstant(Instant, ZoneId)}. * * @param instant the instant to convert, not null * @param zone the zone to use, not null * @return the ISO zoned date-time, not null * @throws DateTimeException if unable to create the date-time */ @Override // override with covariant return type public ZonedDateTime zonedDateTime(Instant instant, ZoneId zone) { return ZonedDateTime.ofInstant(instant, zone); }
/** * Obtains an ISO zoned date-time from an instant. * <p> * This is equivalent to {@link ZonedDateTime#ofInstant(Instant, ZoneId)}. * * @param instant the instant to convert, not null * @param zone the zone to use, not null * @return the ISO zoned date-time, not null * @throws DateTimeException if unable to create the date-time */ @Override // override with covariant return type public ZonedDateTime zonedDateTime(Instant instant, ZoneId zone) { return ZonedDateTime.ofInstant(instant, zone); }
/** * Combines this instant with a time-zone to create a {@code ZonedDateTime}. * <p> * This returns an {@code ZonedDateTime} formed from this instant at the * specified time-zone. An exception will be thrown if the instant is too * large to fit into a zoned date-time. * <p> * This method is equivalent to * {@link ZonedDateTime#ofInstant(Instant, ZoneId) ZonedDateTime.ofInstant(this, zone)}. * * @param zone the zone to combine with, not null * @return the zoned date-time formed from this instant and the specified zone, not null * @throws DateTimeException if the result exceeds the supported range */ public ZonedDateTime atZone(ZoneId zone) { return ZonedDateTime.ofInstant(this, zone); }
/** * Combines this date-time with a time-zone to create a {@code ZonedDateTime} * ensuring that the result has the same instant. * <p> * This returns a {@code ZonedDateTime} formed from this date-time and the specified time-zone. * This conversion will ignore the visible local date-time and use the underlying instant instead. * This avoids any problems with local time-line gaps or overlaps. * The result might have different values for fields such as hour, minute an even day. * <p> * To attempt to retain the values of the fields, use {@link #atZoneSimilarLocal(ZoneId)}. * To use the offset as the zone ID, use {@link #toZonedDateTime()}. * * @param zone the time-zone to use, not null * @return the zoned date-time formed from this date-time, not null */ public ZonedDateTime atZoneSameInstant(ZoneId zone) { return ZonedDateTime.ofInstant(dateTime, offset, zone); }
/** * Combines this instant with a time-zone to create a {@code ZonedDateTime}. * <p> * This returns an {@code ZonedDateTime} formed from this instant at the * specified time-zone. An exception will be thrown if the instant is too * large to fit into a zoned date-time. * <p> * This method is equivalent to * {@link ZonedDateTime#ofInstant(Instant, ZoneId) ZonedDateTime.ofInstant(this, zone)}. * * @param zone the zone to combine with, not null * @return the zoned date-time formed from this instant and the specified zone, not null * @throws DateTimeException if the result exceeds the supported range */ public ZonedDateTime atZone(ZoneId zone) { return ZonedDateTime.ofInstant(this, zone); }
/** * Combines this date-time with a time-zone to create a {@code ZonedDateTime} * ensuring that the result has the same instant. * <p> * This returns a {@code ZonedDateTime} formed from this date-time and the specified time-zone. * This conversion will ignore the visible local date-time and use the underlying instant instead. * This avoids any problems with local time-line gaps or overlaps. * The result might have different values for fields such as hour, minute an even day. * <p> * To attempt to retain the values of the fields, use {@link #atZoneSimilarLocal(ZoneId)}. * To use the offset as the zone ID, use {@link #toZonedDateTime()}. * * @param zone the time-zone to use, not null * @return the zoned date-time formed from this date-time, not null */ public ZonedDateTime atZoneSameInstant(ZoneId zone) { return ZonedDateTime.ofInstant(dateTime, offset, zone); }
@Override public ZonedDateTime apply(FromIntegerArguments a) { return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); } },
@Override public ZonedDateTime apply(FromIntegerArguments a) { return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); } },
@Override public ZonedDateTime apply(FromDecimalArguments a) { return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); } },
@Override public ZonedDateTime apply(FromDecimalArguments a) { return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); } },
@Override public ZonedDateTime apply(FromIntegerArguments a) { return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); } },
@Override public ZonedDateTime apply(FromIntegerArguments a) { return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); } },
@Override public ZonedDateTime apply(FromDecimalArguments a) { return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); } },
@Override public ZonedDateTime apply(FromDecimalArguments a) { return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); } },
/** * Converts a {@code Calendar} to a {@code ZonedDateTime}. * <p> * Note that {@code GregorianCalendar} supports a Julian-Gregorian cutover * date and {@code ZonedDateTime} does not so some differences will occur. * * @param calendar the calendar, not null * @return the instant, not null */ public static ZonedDateTime toZonedDateTime(Calendar calendar) { Instant instant = Instant.ofEpochMilli(calendar.getTimeInMillis()); ZoneId zone = toZoneId(calendar.getTimeZone()); return ZonedDateTime.ofInstant(instant, zone); }
/** * Converts a {@code Calendar} to a {@code ZonedDateTime}. * <p> * Note that {@code GregorianCalendar} supports a Julian-Gregorian cutover * date and {@code ZonedDateTime} does not so some differences will occur. * * @param calendar the calendar, not null * @return the instant, not null */ public static ZonedDateTime toZonedDateTime(Calendar calendar) { Instant instant = Instant.ofEpochMilli(calendar.getTimeInMillis()); ZoneId zone = toZoneId(calendar.getTimeZone()); return ZonedDateTime.ofInstant(instant, zone); }
/** * Obtains the current date-time from the specified clock. * <p> * This will query the specified clock to obtain the current date-time. * The zone and offset will be set based on the time-zone in the clock. * <p> * Using this method allows the use of an alternate clock for testing. * The alternate clock may be introduced using {@link Clock dependency injection}. * * @param clock the clock to use, not null * @return the current date-time, not null */ public static ZonedDateTime now(Clock clock) { Jdk8Methods.requireNonNull(clock, "clock"); final Instant now = clock.instant(); // called once return ofInstant(now, clock.getZone()); }
/** * Obtains the current date-time from the specified clock. * <p> * This will query the specified clock to obtain the current date-time. * The zone and offset will be set based on the time-zone in the clock. * <p> * Using this method allows the use of an alternate clock for testing. * The alternate clock may be introduced using {@link Clock dependency injection}. * * @param clock the clock to use, not null * @return the current date-time, not null */ public static ZonedDateTime now(Clock clock) { Jdk8Methods.requireNonNull(clock, "clock"); final Instant now = clock.instant(); // called once return ofInstant(now, clock.getZone()); }