本文整理汇总了Java中java.time.ZonedDateTime.compareTo方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.compareTo方法的具体用法?Java ZonedDateTime.compareTo怎么用?Java ZonedDateTime.compareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.compareTo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: 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;
}
示例4: getDelayBeforeNextPost
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static long getDelayBeforeNextPost() {
ZonedDateTime zonedNow = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault());
ZonedDateTime zonedNext = zonedNow.withHour(Config.POST_HOUR).withMinute(0).withSecond(0);
if(zonedNow.compareTo(zonedNext) > 0) {
zonedNext = zonedNext.plusDays(1);
}
return zonedNext.toInstant().toEpochMilli() - zonedNow.toInstant().toEpochMilli();
}
示例5: TimeComparison
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private TimeComparison(
@Nullable final ZonedDateTime left,
@Nullable final ZonedDateTime right){
comparison = left == null || right == null ?
null :
left.compareTo(right);
}
示例6: applyThreshold
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Check for the input points, compare each with threshold, if it continue
* to pass the threshold for the critical/warn/info duration time period, change
* its the value to be critical/warn/info, otherwise, it's ok
*/
List<Transmutation> applyThreshold(List<Transmutation> points) {
// nothing to do
if (points.isEmpty()) {
return null;
}
Transmutation lastPoint = Iterables.getLast(points);
ZonedDateTime lastPointTS = lastPoint.time();
// get the timestamp for the critical, warning, info durations
// if the millisecond unit is not supported, it will throw UnsupportedTemporalTypeException
ZonedDateTime infoDurationTS = lastPointTS.minus(infoDurationMillis(), ChronoUnit.MILLIS);
ZonedDateTime warnDurationTS = lastPointTS.minus(warnDurationMillis(), ChronoUnit.MILLIS);
ZonedDateTime criticalDurationTS = lastPointTS.minus(criticalDurationMillis(), ChronoUnit.MILLIS);
ListIterator<Transmutation> iter = points.listIterator(points.size());
boolean matchThreshold = true;
boolean atWarningLevel = false;
boolean atInfoLevel = false;
while (iter.hasPrevious() && matchThreshold) {
Transmutation result = iter.previous();
ZonedDateTime pointTS = result.time();
Number value = result.value();
matchThreshold = type().matches(value, threshold());
if (matchThreshold) {
if (pointTS.compareTo(criticalDurationTS) <= 0) {
return Collections.singletonList(appendMessage(changeValue(result, CRIT.value()), CRIT.code(), threshold(), criticalDurationMillis()));
} else if (pointTS.compareTo(warnDurationTS) <= 0) {
atWarningLevel = true;
} else if (pointTS.compareTo(infoDurationTS) <= 0) {
atInfoLevel = true;
}
} else {
if (pointTS.compareTo(warnDurationTS) <= 0) {
return Collections.singletonList(appendMessage(changeValue(result, WARN.value()), WARN.code(), threshold(), warnDurationMillis()));
} else if (pointTS.compareTo(infoDurationTS) <= 0) {
return Collections.singletonList(appendMessage(changeValue(result, INFO.value()), INFO.code(), threshold(), warnDurationMillis()));
} else {
return Collections.singletonList(changeValue(result, OK.value())); // OK status
}
}
}
// critical, warning or info duration value is longer than available input time series
return atWarningLevel
? Collections.singletonList(appendMessage(changeValue(lastPoint, WARN.value()), WARN.code(), threshold(), warnDurationMillis()))
: (atInfoLevel
? Collections.singletonList(appendMessage(changeValue(lastPoint, INFO.value()), INFO.code(), threshold(), warnDurationMillis()))
: Collections.singletonList(changeValue(lastPoint, OK.value())));
}
示例7: test_compareTo_null
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_compareTo_null() {
ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
a.compareTo(null);
}
示例8: inRange
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Is a date in the date range
*
* @param date
* The date to check
* @return true if the date range contains a date start and end of range
* inclusive; false otherwise
*/
public boolean inRange(ZonedDateTime date) {
if (date == null) {
return false;
}
return date.compareTo(start) >= 0 && date.compareTo(end) <= 0;
}
示例9: RangeOfZonedDateTimes
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Constructor
* @param start the start for range, inclusive
* @param end the end for range, exclusive
* @param step the step increment
* @param excludes optional predicate to exclude elements in this range
*/
RangeOfZonedDateTimes(ZonedDateTime start, ZonedDateTime end, Duration step, Predicate<ZonedDateTime> excludes) {
super(start, end);
this.step = step;
this.ascend = start.compareTo(end) <= 0;
this.excludes = excludes;
}
示例10: inBounds
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Checks that the value specified is in the bounds of this range
* @param value the value to check if in bounds
* @return true if in bounds
*/
private boolean inBounds(ZonedDateTime value) {
return ascend ? value.compareTo(start()) >=0 && value.isBefore(end()) : value.compareTo(start()) <=0 && value.isAfter(end());
}