Java Code Examples for org.threeten.bp.ZoneOffset#getTotalSeconds()
The following examples show how to use
org.threeten.bp.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: Ser.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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 2
Source File: StandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
private Object getOffsetInfo(LocalDateTime dt) { // 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 3
Source File: StandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
private int findYear(long epochSecond, ZoneOffset offset) { // inline for performance long localSecond = epochSecond + offset.getTotalSeconds(); long localEpochDay = Jdk8Methods.floorDiv(localSecond, 86400); return LocalDate.ofEpochDay(localEpochDay).getYear(); }
Example 4
Source File: ChronoLocalDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * 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. * * @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 */ public long toEpochSecond(ZoneOffset offset) { Jdk8Methods.requireNonNull(offset, "offset"); long epochDay = toLocalDate().toEpochDay(); long secs = epochDay * 86400 + toLocalTime().toSecondOfDay(); secs -= offset.getTotalSeconds(); return secs; }