Java Code Examples for org.threeten.bp.Instant#getEpochSecond()
The following examples show how to use
org.threeten.bp.Instant#getEpochSecond() .
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: StandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public ZoneOffset getOffset(Instant instant) { long epochSec = instant.getEpochSecond(); // check if using last rules if (lastRules.length > 0 && epochSec > savingsInstantTransitions[savingsInstantTransitions.length - 1]) { int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]); ZoneOffsetTransition[] transArray = findTransitionArray(year); ZoneOffsetTransition trans = null; for (int i = 0; i < transArray.length; i++) { trans = transArray[i]; if (epochSec < trans.toEpochSecond()) { return trans.getOffsetBefore(); } } return trans.getOffsetAfter(); } // using historic rules int index = Arrays.binarySearch(savingsInstantTransitions, epochSec); if (index < 0) { // switch negative insert position to start of matched range index = -index - 2; } return wallOffsets[index + 1]; }
Example 2
Source File: StandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public ZoneOffset getStandardOffset(Instant instant) { long epochSec = instant.getEpochSecond(); int index = Arrays.binarySearch(standardTransitions, epochSec); if (index < 0) { // switch negative insert position to start of matched range index = -index - 2; } return standardOffsets[index + 1]; }
Example 3
Source File: StandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public ZoneOffsetTransition nextTransition(Instant instant) { if (savingsInstantTransitions.length == 0) { return null; } long epochSec = instant.getEpochSecond(); // check if using last rules if (epochSec >= savingsInstantTransitions[savingsInstantTransitions.length - 1]) { if (lastRules.length == 0) { return null; } // search year the instant is in int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]); ZoneOffsetTransition[] transArray = findTransitionArray(year); for (ZoneOffsetTransition trans : transArray) { if (epochSec < trans.toEpochSecond()) { return trans; } } // use first from following year if (year < Year.MAX_VALUE) { transArray = findTransitionArray(year + 1); return transArray[0]; } return null; } // using historic rules int index = Arrays.binarySearch(savingsInstantTransitions, epochSec); if (index < 0) { index = -index - 1; // switched value is the next transition } else { index += 1; // exact match, so need to add one to get the next } return new ZoneOffsetTransition(savingsInstantTransitions[index], wallOffsets[index], wallOffsets[index + 1]); }
Example 4
Source File: StandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public ZoneOffsetTransition previousTransition(Instant instant) { if (savingsInstantTransitions.length == 0) { return null; } long epochSec = instant.getEpochSecond(); if (instant.getNano() > 0 && epochSec < Long.MAX_VALUE) { epochSec += 1; // allow rest of method to only use seconds } // check if using last rules long lastHistoric = savingsInstantTransitions[savingsInstantTransitions.length - 1]; if (lastRules.length > 0 && epochSec > lastHistoric) { // search year the instant is in ZoneOffset lastHistoricOffset = wallOffsets[wallOffsets.length - 1]; int year = findYear(epochSec, lastHistoricOffset); ZoneOffsetTransition[] transArray = findTransitionArray(year); for (int i = transArray.length - 1; i >= 0; i--) { if (epochSec > transArray[i].toEpochSecond()) { return transArray[i]; } } // use last from preceeding year int lastHistoricYear = findYear(lastHistoric, lastHistoricOffset); if (--year > lastHistoricYear) { transArray = findTransitionArray(year); return transArray[transArray.length - 1]; } // drop through } // using historic rules int index = Arrays.binarySearch(savingsInstantTransitions, epochSec); if (index < 0) { index = -index - 1; } if (index <= 0) { return null; } return new ZoneOffsetTransition(savingsInstantTransitions[index - 1], wallOffsets[index - 1], wallOffsets[index]); }