Java Code Examples for java.time.ZoneOffset#getTotalSeconds()

The following examples show how to use java.time.ZoneOffset#getTotalSeconds() . 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: DateTimeZone.java    From jphp with Apache License 2.0 5 votes vote down vote up
@Signature
public Memory getOffset(Environment env, TraceInfo traceInfo, Memory datetime) {
    DateTimeInterface dateTime = datetime.toObject(DateTimeInterface.class);
    long timestamp = dateTime.getTimestamp(env, traceInfo).toLong();
    ZoneOffset offset = nativeZone.getRules().getOffset(Instant.ofEpochSecond(timestamp));
    int totalSeconds = offset.getTotalSeconds();

    return LongMemory.valueOf(totalSeconds);
}
 
Example 2
Source File: ZonedDateTimes.java    From jpx with Apache License 2.0 5 votes vote down vote up
private static
void writeZoneOffset(final ZoneOffset os, final DataOutput out)
	throws IOException
{
	final int offsetSecs = os.getTotalSeconds();
	int offsetByte = offsetSecs%900 == 0 ? offsetSecs/900 : 127;
	out.writeByte(offsetByte);
	if (offsetByte == 127) {
		IO.writeInt(offsetSecs, out);
	}
}
 
Example 3
Source File: Ser.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Writes the state to the stream.
 *
 * @param offset  the offset, not null
 * @param out  the output stream, not null
 * @throws IOException if an error occurs
 */
static void writeOffset(ZoneOffset offset, DataOutput out) throws IOException {
    final int offsetSecs = offset.getTotalSeconds();
    int offsetByte = offsetSecs % 900 == 0 ? offsetSecs / 900 : 127;  // compress to -72 to +72
    out.writeByte(offsetByte);
    if (offsetByte == 127) {
        out.writeInt(offsetSecs);
    }
}
 
Example 4
Source File: ZoneRules.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
Example 5
Source File: ZoneRules.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
Example 6
Source File: ZoneRules.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
Example 7
Source File: ZoneRules.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private int findYear(long epochSecond, ZoneOffset offset) {
    // inline for performance
    long localSecond = epochSecond + offset.getTotalSeconds();
    long localEpochDay = Math.floorDiv(localSecond, 86400);
    return LocalDate.ofEpochDay(localEpochDay).getYear();
}
 
Example 8
Source File: ZoneRules.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private int findYear(long epochSecond, ZoneOffset offset) {
    // inline for performance
    long localSecond = epochSecond + offset.getTotalSeconds();
    long localEpochDay = Math.floorDiv(localSecond, 86400);
    return LocalDate.ofEpochDay(localEpochDay).getYear();
}
 
Example 9
Source File: ZoneRules.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private int findYear(long epochSecond, ZoneOffset offset) {
    // inline for performance
    long localSecond = epochSecond + offset.getTotalSeconds();
    long localEpochDay = Math.floorDiv(localSecond, 86400);
    return LocalDate.ofEpochDay(localEpochDay).getYear();
}
 
Example 10
Source File: ZoneRules.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private int findYear(long epochSecond, ZoneOffset offset) {
    // inline for performance
    long localSecond = epochSecond + offset.getTotalSeconds();
    long localEpochDay = Math.floorDiv(localSecond, 86400);
    return LocalDate.ofEpochDay(localEpochDay).getYear();
}
 
Example 11
Source File: ZoneRules.java    From desugar_jdk_libs with GNU General Public License v2.0 4 votes vote down vote up
private int findYear(long epochSecond, ZoneOffset offset) {
    // inline for performance
    long localSecond = epochSecond + offset.getTotalSeconds();
    long localEpochDay = Math8.floorDiv(localSecond, 86400);
    return LocalDate.ofEpochDay(localEpochDay).getYear();
}
 
Example 12
Source File: ZoneOffsetHandle.java    From alibaba-rsocket-broker with Apache License 2.0 4 votes vote down vote up
public ZoneOffsetHandle(ZoneOffset o) {
    this.seconds = o.getTotalSeconds();
}
 
Example 13
Source File: PDTFactory.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public static int getTimezoneOffsetInMinutes (@Nonnull final ZoneOffset aZO)
{
  return aZO.getTotalSeconds () / CGlobal.SECONDS_PER_MINUTE;
}
 
Example 14
Source File: ZoneRules.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
Example 15
Source File: ZoneRules.java    From j2objc with Apache License 2.0 4 votes vote down vote up
private int findYear(long epochSecond, ZoneOffset offset) {
    // inline for performance
    long localSecond = epochSecond + offset.getTotalSeconds();
    long localEpochDay = Math.floorDiv(localSecond, 86400);
    return LocalDate.ofEpochDay(localEpochDay).getYear();
}
 
Example 16
Source File: ZoneRules.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
Example 17
Source File: ChronoLocalDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Converts this date-time to the number of seconds from the epoch
 * of 1970-01-01T00:00:00Z.
 * <p>
 * This combines this local date-time and the specified offset to calculate the
 * epoch-second value, which is the number of elapsed seconds from 1970-01-01T00:00:00Z.
 * Instants on the time-line after the epoch are positive, earlier are negative.
 * <p>
 * This default implementation calculates from the epoch-day of the date and the
 * second-of-day of the time.
 *
 * @param offset  the offset to use for the conversion, not null
 * @return the number of seconds from the epoch of 1970-01-01T00:00:00Z
 */
default long toEpochSecond(ZoneOffset offset) {
    Objects.requireNonNull(offset, "offset");
    long epochDay = toLocalDate().toEpochDay();
    long secs = epochDay * 86400 + toLocalTime().toSecondOfDay();
    secs -= offset.getTotalSeconds();
    return secs;
}
 
Example 18
Source File: ChronoLocalDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Converts this date-time to the number of seconds from the epoch
 * of 1970-01-01T00:00:00Z.
 * <p>
 * This combines this local date-time and the specified offset to calculate the
 * epoch-second value, which is the number of elapsed seconds from 1970-01-01T00:00:00Z.
 * Instants on the time-line after the epoch are positive, earlier are negative.
 * <p>
 * This default implementation calculates from the epoch-day of the date and the
 * second-of-day of the time.
 *
 * @param offset  the offset to use for the conversion, not null
 * @return the number of seconds from the epoch of 1970-01-01T00:00:00Z
 */
default long toEpochSecond(ZoneOffset offset) {
    Objects.requireNonNull(offset, "offset");
    long epochDay = toLocalDate().toEpochDay();
    long secs = epochDay * 86400 + toLocalTime().toSecondOfDay();
    secs -= offset.getTotalSeconds();
    return secs;
}
 
Example 19
Source File: ChronoLocalDateTime.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Converts this date-time to the number of seconds from the epoch
 * of 1970-01-01T00:00:00Z.
 * <p>
 * This combines this local date-time and the specified offset to calculate the
 * epoch-second value, which is the number of elapsed seconds from 1970-01-01T00:00:00Z.
 * Instants on the time-line after the epoch are positive, earlier are negative.
 * <p>
 * This default implementation calculates from the epoch-day of the date and the
 * second-of-day of the time.
 *
 * @param offset  the offset to use for the conversion, not null
 * @return the number of seconds from the epoch of 1970-01-01T00:00:00Z
 */
default long toEpochSecond(ZoneOffset offset) {
    Objects.requireNonNull(offset, "offset");
    long epochDay = toLocalDate().toEpochDay();
    long secs = epochDay * 86400 + toLocalTime().toSecondOfDay();
    secs -= offset.getTotalSeconds();
    return secs;
}
 
Example 20
Source File: ChronoLocalDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Converts this date-time to the number of seconds from the epoch
 * of 1970-01-01T00:00:00Z.
 * <p>
 * This combines this local date-time and the specified offset to calculate the
 * epoch-second value, which is the number of elapsed seconds from 1970-01-01T00:00:00Z.
 * Instants on the time-line after the epoch are positive, earlier are negative.
 * <p>
 * This default implementation calculates from the epoch-day of the date and the
 * second-of-day of the time.
 *
 * @param offset  the offset to use for the conversion, not null
 * @return the number of seconds from the epoch of 1970-01-01T00:00:00Z
 */
default long toEpochSecond(ZoneOffset offset) {
    Objects.requireNonNull(offset, "offset");
    long epochDay = toLocalDate().toEpochDay();
    long secs = epochDay * 86400 + toLocalTime().toSecondOfDay();
    secs -= offset.getTotalSeconds();
    return secs;
}