本文整理汇总了Java中java.time.ZonedDateTime.plus方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.plus方法的具体用法?Java ZonedDateTime.plus怎么用?Java ZonedDateTime.plus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.plus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initNextTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private ZonedDateTime initNextTime(ZonedDateTime start, ZonedDateTime now, Period p, Duration d) {
// if the start time is in the future next will just be start
ZonedDateTime next = start;
// if the start time is in the past, increment until we find the next time to execute
// cannot call isComplete() here as it depends on nextTime
if (startTime.compareTo(now) <= 0 && !schedule.getRunOnce()) {
// TODO: Look to optimize. Consider a one-second timer, it would take too long
// For example if only a single unit, e.g. only minutes, then can optimize relative to start
// if there are more than one unit, then the loop may be best as it will be difficult
while (next.compareTo(now) <= 0) {
next = next.plus(p);
next = next.plus(d);
}
}
return next;
}
示例2: toIntervalStart
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public ZonedDateTime toIntervalStart(ZonedDateTime time) {
ZonedDateTime start;
switch (ChronoUnit.valueOf(unit.toString().toUpperCase())) {
case SECONDS:
start = time.truncatedTo(ChronoUnit.MINUTES);
break;
case MINUTES:
start = time.truncatedTo(ChronoUnit.HOURS);
break;
case HOURS:
start = time.truncatedTo(ChronoUnit.DAYS);
break;
case DAYS:
start = time.with(TemporalAdjusters.firstDayOfYear()).truncatedTo(ChronoUnit.DAYS);
break;
default:
start = time.with(TemporalAdjusters.firstDayOfYear()).truncatedTo(ChronoUnit.DAYS);
}
long haveMillis = Duration.between(start, time).toMillis();
long maxMillis = duration.toMillis();
long periods = haveMillis / maxMillis;
start = start.plus(duration.multipliedBy(periods));
return start;
}
示例3: calculateIntervalsForTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public List<Interval> calculateIntervalsForTime(TimeObject phenTime) {
List<Interval> retval = new ArrayList<>();
Instant phenTimeStart = getPhenTimeStart(phenTime);
Instant phenTimeEnd = getPhenTimeEnd(phenTime);
ZonedDateTime atZone = phenTimeStart.atZone(getZoneId());
ZonedDateTime intStart = level.toIntervalStart(atZone);
ZonedDateTime intEnd = intStart.plus(level.amount, level.unit);
retval.add(Interval.of(intStart.toInstant(), intEnd.toInstant()));
while (intEnd.toInstant().isBefore(phenTimeEnd)) {
intStart = intEnd;
intEnd = intStart.plus(level.amount, level.unit);
retval.add(Interval.of(intStart.toInstant(), intEnd.toInstant()));
}
return retval;
}
示例4: isExpired
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public boolean isExpired(final TicketState ticketState) {
final ZonedDateTime currentSystemTime = ZonedDateTime.now(ZoneOffset.UTC);
final ZonedDateTime creationTime = ticketState.getCreationTime();
// token has been used, check maxTimeToLive (hard window)
ZonedDateTime expirationTime = creationTime.plus(this.maxTimeToLiveInSeconds, ChronoUnit.SECONDS);
if (currentSystemTime.isAfter(expirationTime)) {
LOGGER.debug("Access token is expired because the time since creation is greater than maxTimeToLiveInSeconds");
return true;
}
// token is within hard window, check timeToKill (sliding window)
expirationTime = creationTime.plus(this.timeToKillInSeconds, ChronoUnit.SECONDS);
if (ticketState.getLastTimeUsed().isAfter(expirationTime)) {
LOGGER.debug("Access token is expired because the time since last use is greater than timeToKillInMilliseconds");
return true;
}
return false;
}
示例5: isExpired
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public boolean isExpired(final TicketState ticketState) {
final ZonedDateTime currentSystemTime = ZonedDateTime.now(ZoneOffset.UTC);
final ZonedDateTime creationTime = ticketState.getCreationTime();
final ZonedDateTime lastTimeUsed = ticketState.getLastTimeUsed();
// Ticket has been used, check maxTimeToLive (hard window)
ZonedDateTime expirationTime = creationTime.plus(this.maxTimeToLiveInSeconds, ChronoUnit.SECONDS);
if (currentSystemTime.isAfter(expirationTime)) {
LOGGER.debug("Ticket is expired because the time since creation is greater than maxTimeToLiveInSeconds");
return true;
}
expirationTime = lastTimeUsed.plus(this.timeToKillInSeconds, ChronoUnit.SECONDS);
if (currentSystemTime.isAfter(expirationTime)) {
LOGGER.debug("Ticket is expired because the time since last use is greater than timeToKillInSeconds");
return true;
}
return false;
}
示例6: isExpired
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public boolean isExpired(final TicketState ticketState) {
final ZonedDateTime currentTime = ZonedDateTime.now(ZoneOffset.UTC);
final ZonedDateTime lastTimeUsed = ticketState.getLastTimeUsed();
final ZonedDateTime killTime = lastTimeUsed.plus(this.timeToKillInSeconds, ChronoUnit.SECONDS);
if (ticketState.getCountOfUses() == 0 && currentTime.isBefore(killTime)) {
LOGGER.debug("Ticket is not expired due to a count of zero and the time being less "
+ "than the timeToKillInSeconds");
return false;
}
if (currentTime.isAfter(killTime)) {
LOGGER.debug("Ticket is expired due to the time being greater than the timeToKillInSeconds");
return true;
}
final ZonedDateTime dontUseUntil = lastTimeUsed.plus(this.timeInBetweenUsesInSeconds, ChronoUnit.SECONDS);
if (currentTime.isBefore(dontUseUntil)) {
LOGGER.warn("Ticket is expired due to the time being less than the waiting period.");
return true;
}
return false;
}
示例7: isExpired
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public boolean isExpired(final TicketState ticketState) {
if (ticketState == null) {
LOGGER.debug("Ticket state is null for [{}]", this.getClass().getSimpleName());
return true;
}
final long countUses = ticketState.getCountOfUses();
if (countUses >= this.numberOfUses) {
LOGGER.debug("Ticket usage count [{}] is greater than or equal to [{}]", countUses, this.numberOfUses);
return true;
}
final ZonedDateTime systemTime = ZonedDateTime.now(ZoneOffset.UTC);
final ZonedDateTime lastTimeUsed = ticketState.getLastTimeUsed();
final ZonedDateTime expirationTime = lastTimeUsed.plus(this.timeToKillInSeconds, ChronoUnit.SECONDS);
if (systemTime.isAfter(expirationTime)) {
LOGGER.debug("Ticket has expired because the difference between current time [{}] "
+ "and ticket time [{}] is greater than or equal to [{}]", systemTime, lastTimeUsed,
this.timeToKillInSeconds);
return true;
}
return false;
}
示例8: resolveTimestamp
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private Timestamp resolveTimestamp(String timestampState, String timestampUnitString, long amountToAddValue, String amountToAddUnit) {
ChronoUnit timestampUnit = ChronoUnit.valueOf(timestampUnitString.toUpperCase());
ZonedDateTime timestamp = truncate(executionInstant.atZone(systemDefault()), timestampUnit);
if (timestampState.equalsIgnoreCase("past")) {
timestamp = timestamp.minus(1, timestampUnit);
} else if (timestampState.equalsIgnoreCase("future")) {
timestamp = timestamp.plus(1, timestampUnit);
}
if (amountToAddValue != 0 && amountToAddUnit != null) {
timestamp = timestamp.plus(amountToAddValue, ChronoUnit.valueOf(amountToAddUnit.toUpperCase()));
}
return new Timestamp(timestamp.toInstant().toEpochMilli());
}
示例9: initNextTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private ZonedDateTime initNextTime(ZonedDateTime start, ZonedDateTime now, Period p, Duration d) {
// if the start time is in the future next will just be start
ZonedDateTime next = start;
// if the start time is in the past, increment until we find the next time to execute
// cannot call isComplete() here as it depends on nextTime
if (startTime.compareTo(now) <= 0 && !schedule.getRunOnce()) {
// TODO: Look to optimize. Consider a one-second timer, it would take too long
// For example if only a single unit, e.g. only minutes, then can optimize relative to start
// if there are more than one unit, then the loop may be best as it will be difficult
while (next.compareTo(now) <= 0) {
next = next.plus(p);
next = next.plus(d);
}
}
return next;
}
示例10: initNextTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private ZonedDateTime initNextTime(ZonedDateTime start, ZonedDateTime now, Period p, Duration d) {
// if the start time is in the future next will just be start
ZonedDateTime next = start;
// if the start time is in the past, increment until we find the next time to execute
// cannot call isComplete() here as it depends on nextTime
if(startTime.compareTo(now) <= 0 && !schedule.getRunOnce()) {
// TODO: Look to optimize. Consider a one-second timer, it would take too long
// For example if only a single unit, e.g. only minutes, then can optimize relative to start
// if there are more than one unit, then the loop may be best as it will be difficult
while(next.compareTo(now) <= 0) {
next = next.plus(p);
next = next.plus(d);
}
}
return next;
}
示例11: testRangeOfZonedDateTimes
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(dataProvider = "ZonedDateTimeRanges")
public void testRangeOfZonedDateTimes(ZonedDateTime start, ZonedDateTime end, Duration step, boolean parallel) {
final Range<ZonedDateTime> range = Range.of(start, end, step);
final Array<ZonedDateTime> array = range.toArray(parallel);
final boolean ascend = start.isBefore(end);
final int expectedLength = (int)Math.ceil(Math.abs((double)ChronoUnit.SECONDS.between(start, end)) / (double)step.getSeconds());
Assert.assertEquals(array.length(), expectedLength);
Assert.assertEquals(array.typeCode(), ArrayType.ZONED_DATETIME);
Assert.assertTrue(!array.style().isSparse());
Assert.assertEquals(range.start(), start, "The range start");
Assert.assertEquals(range.end(), end, "The range end");
ZonedDateTime expected = null;
for (int i=0; i<array.length(); ++i) {
final ZonedDateTime actual = array.getValue(i);
expected = expected == null ? start : ascend ? expected.plus(step) : expected.minus(step);
Assert.assertEquals(actual, expected, "Value matches at " + i);
Assert.assertTrue(ascend ? actual.compareTo(start) >=0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + i);
}
}
示例12: testRangeOfZonedDateTimes
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(dataProvider = "ZonedDateTimeRanges")
public void testRangeOfZonedDateTimes(ZonedDateTime start, ZonedDateTime end, Duration step, boolean parallel) {
final boolean ascend = start.isBefore(end);
final Range<ZonedDateTime> range = Range.of(start, end, step, v -> v.getHour() == 6);
final Array<ZonedDateTime> array = range.toArray(parallel);
final ZonedDateTime first = array.first(v -> true).map(ArrayValue::getValue).get();
final ZonedDateTime last = array.last(v -> true).map(ArrayValue::getValue).get();
Assert.assertEquals(array.typeCode(), ArrayType.ZONED_DATETIME);
Assert.assertTrue(!array.style().isSparse());
Assert.assertEquals(range.start(), start, "The range start");
Assert.assertEquals(range.end(), end, "The range end");
int index = 0;
ZonedDateTime value = first;
while (ascend ? value.isBefore(last) : value.isAfter(last)) {
final ZonedDateTime actual = array.getValue(index);
Assert.assertEquals(actual, value, "Value matches at " + index);
Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
value = ascend ? value.plus(step) : value.minus(step);
while (value.getHour() == 6) value = ascend ? value.plus(step) : value.minus(step);
index++;
}
}
示例13: resolveTimestamp
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private Timestamp resolveTimestamp(String timestampState, String timestampUnitString) {
ChronoUnit timestampUnit = ChronoUnit.valueOf(timestampUnitString.toUpperCase());
ZonedDateTime timestamp = truncate(executionInstant.atZone(systemDefault()), timestampUnit);
if (timestampState.equalsIgnoreCase("past")) {
timestamp = timestamp.minus(1, timestampUnit);
} else if (timestampState.equalsIgnoreCase("future")) {
timestamp = timestamp.plus(1, timestampUnit);
}
return new Timestamp(timestamp.toInstant().toEpochMilli());
}
示例14: resolveTimestamp
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private Timestamp resolveTimestamp(String state, long diff, String unitString) {
ChronoUnit timestampUnit = ChronoUnit.valueOf(unitString.toUpperCase());
ZonedDateTime timestamp = truncate(executionInstant.atZone(systemDefault()), timestampUnit);
if (state.equalsIgnoreCase("past")) {
timestamp = timestamp.minus(diff, timestampUnit);
} else if (state.equalsIgnoreCase("future")) {
timestamp = timestamp.plus(diff, timestampUnit);
}
return new Timestamp(timestamp.toInstant().toEpochMilli());
}
示例15: buildEmptyTicks
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Builds a list of empty ticks.
* @param beginTime the begin time of the whole period
* @param endTime the end time of the whole period
* @param duration the tick duration (in seconds)
* @return the list of empty ticks
*/
private static List<Tick> buildEmptyTicks(ZonedDateTime beginTime, ZonedDateTime endTime, int duration) {
List<Tick> emptyTicks = new ArrayList<>();
Duration tickDuration = Duration.ofSeconds(duration);
ZonedDateTime tickEndTime = beginTime;
do {
tickEndTime = tickEndTime.plus(tickDuration);
emptyTicks.add(new BaseTick(tickDuration, tickEndTime));
} while (tickEndTime.isBefore(endTime));
return emptyTicks;
}