/** * Converts this date-time to the number of seconds from the epoch of 1970-01-01T00:00:00Z. * <p> * This allows this date-time to be converted to a value of the * {@link ChronoField#INSTANT_SECONDS epoch-seconds} field. This is primarily * intended for low-level conversions rather than general application usage. * * @return the number of seconds from the epoch of 1970-01-01T00:00:00Z */ public long toEpochSecond() { return dateTime.toEpochSecond(offset); }
/** * Converts this date-time to the number of seconds from the epoch of 1970-01-01T00:00:00Z. * <p> * This allows this date-time to be converted to a value of the * {@link ChronoField#INSTANT_SECONDS epoch-seconds} field. This is primarily * intended for low-level conversions rather than general application usage. * * @return the number of seconds from the epoch of 1970-01-01T00:00:00Z */ public long toEpochSecond() { return dateTime.toEpochSecond(offset); }
/** * Gets the transition instant as an epoch second. * * @return the transition epoch second */ public long toEpochSecond() { return transition.toEpochSecond(offsetBefore); }
/** * Gets the transition instant as an epoch second. * * @return the transition epoch second */ public long toEpochSecond() { return transition.toEpochSecond(offsetBefore); }
/** * Creates the offset date-time for the local date-time at the end of the window. * * @param savingsSecs the amount of savings in use in seconds * @return the created date-time epoch second in the wall offset, not null */ long createDateTimeEpochSecond(int savingsSecs) { ZoneOffset wallOffset = createWallOffset(savingsSecs); LocalDateTime ldt = timeDefinition.createDateTime(windowEnd, standardOffset, wallOffset); return ldt.toEpochSecond(wallOffset); } }
/** * Creates the offset date-time for the local date-time at the end of the window. * * @param savingsSecs the amount of savings in use in seconds * @return the created date-time epoch second in the wall offset, not null */ long createDateTimeEpochSecond(int savingsSecs) { ZoneOffset wallOffset = createWallOffset(savingsSecs); LocalDateTime ldt = timeDefinition.createDateTime(windowEnd, standardOffset, wallOffset); return ldt.toEpochSecond(wallOffset); } }
/** * Returns a copy of this date-time with a different time-zone, * retaining the instant. * <p> * This method changes the time-zone and retains the instant. * This normally results in a change to the local date-time. * <p> * This method is based on retaining the same instant, thus gaps and overlaps * in the local time-line have no effect on the result. * <p> * To change the offset while keeping the local time, * use {@link #withZoneSameLocal(ZoneId)}. * * @param zone the time-zone to change to, not null * @return a {@code ZonedDateTime} based on this date-time with the requested zone, not null * @throws DateTimeException if the result exceeds the supported date range */ @Override public ZonedDateTime withZoneSameInstant(ZoneId zone) { Jdk8Methods.requireNonNull(zone, "zone"); return this.zone.equals(zone) ? this : create(dateTime.toEpochSecond(offset), dateTime.getNano(), zone); }
/** * Returns a copy of this date-time with a different time-zone, * retaining the instant. * <p> * This method changes the time-zone and retains the instant. * This normally results in a change to the local date-time. * <p> * This method is based on retaining the same instant, thus gaps and overlaps * in the local time-line have no effect on the result. * <p> * To change the offset while keeping the local time, * use {@link #withZoneSameLocal(ZoneId)}. * * @param zone the time-zone to change to, not null * @return a {@code ZonedDateTime} based on this date-time with the requested zone, not null * @throws DateTimeException if the result exceeds the supported date range */ @Override public ZonedDateTime withZoneSameInstant(ZoneId zone) { Jdk8Methods.requireNonNull(zone, "zone"); return this.zone.equals(zone) ? this : create(dateTime.toEpochSecond(offset), dateTime.getNano(), zone); }
/** * Obtains an instance of {@code ZonedDateTime} from the instant formed by combining * the local date-time and offset. * <p> * This creates a zoned date-time by {@link LocalDateTime#toInstant(ZoneOffset) combining} * the {@code LocalDateTime} and {@code ZoneOffset}. * This combination uniquely specifies an instant without ambiguity. * <p> * Converting an instant to a zoned date-time is simple as there is only one valid * offset for each instant. If the valid offset is different to the offset specified, * the the date-time and offset of the zoned date-time will differ from those specified. * <p> * If the {@code ZoneId} to be used is a {@code ZoneOffset}, this method is equivalent * to {@link #of(LocalDateTime, ZoneId)}. * * @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 ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) { Jdk8Methods.requireNonNull(localDateTime, "localDateTime"); Jdk8Methods.requireNonNull(offset, "offset"); Jdk8Methods.requireNonNull(zone, "zone"); return create(localDateTime.toEpochSecond(offset), localDateTime.getNano(), zone); }
/** * Obtains an instance of {@code ZonedDateTime} from the instant formed by combining * the local date-time and offset. * <p> * This creates a zoned date-time by {@link LocalDateTime#toInstant(ZoneOffset) combining} * the {@code LocalDateTime} and {@code ZoneOffset}. * This combination uniquely specifies an instant without ambiguity. * <p> * Converting an instant to a zoned date-time is simple as there is only one valid * offset for each instant. If the valid offset is different to the offset specified, * the the date-time and offset of the zoned date-time will differ from those specified. * <p> * If the {@code ZoneId} to be used is a {@code ZoneOffset}, this method is equivalent * to {@link #of(LocalDateTime, ZoneId)}. * * @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 ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) { Jdk8Methods.requireNonNull(localDateTime, "localDateTime"); Jdk8Methods.requireNonNull(offset, "offset"); Jdk8Methods.requireNonNull(zone, "zone"); return create(localDateTime.toEpochSecond(offset), localDateTime.getNano(), zone); }
for (TZRule rule : window.ruleList) { ZoneOffsetTransition trans = rule.toTransition(loopStandardOffset, loopSavings); if (trans.toEpochSecond() > loopWindowStart.toEpochSecond(loopWindowOffset)) { standardTransitionList.add(deduplicate( new ZoneOffsetTransition( LocalDateTime.ofEpochSecond(loopWindowStart.toEpochSecond(loopWindowOffset), 0, loopStandardOffset), loopStandardOffset, window.standardOffset))); loopStandardOffset = deduplicate(window.standardOffset); if (trans.toEpochSecond() < loopWindowStart.toEpochSecond(loopWindowOffset) == false && trans.toEpochSecond() < window.createDateTimeEpochSecond(loopSavings) && trans.getOffsetBefore().equals(trans.getOffsetAfter()) == false) {
for (TZRule rule : window.ruleList) { ZoneOffsetTransition trans = rule.toTransition(loopStandardOffset, loopSavings); if (trans.toEpochSecond() > loopWindowStart.toEpochSecond(loopWindowOffset)) { standardTransitionList.add(deduplicate( new ZoneOffsetTransition( LocalDateTime.ofEpochSecond(loopWindowStart.toEpochSecond(loopWindowOffset), 0, loopStandardOffset), loopStandardOffset, window.standardOffset))); loopStandardOffset = deduplicate(window.standardOffset); if (trans.toEpochSecond() < loopWindowStart.toEpochSecond(loopWindowOffset) == false && trans.toEpochSecond() < window.createDateTimeEpochSecond(loopSavings) && trans.getOffsetBefore().equals(trans.getOffsetAfter()) == false) {
try { LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, min, sec, 0).plusDays(days); instantSecs = ldt.toEpochSecond(ZoneOffset.UTC); instantSecs += Jdk8Methods.safeMultiply(yearParsed / 10000L, SECONDS_PER_10000_YEARS); } catch (RuntimeException ex) {
try { LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, min, sec, 0).plusDays(days); instantSecs = ldt.toEpochSecond(ZoneOffset.UTC); instantSecs += Jdk8Methods.safeMultiply(yearParsed / 10000L, SECONDS_PER_10000_YEARS); } catch (RuntimeException ex) {