本文整理汇总了Java中java.time.ZonedDateTime.minus方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.minus方法的具体用法?Java ZonedDateTime.minus怎么用?Java ZonedDateTime.minus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.minus方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: cleanupAuditData
import java.time.ZonedDateTime; //导入方法依赖的package包/类
protected void cleanupAuditData(final String auditApplicationName, final JobExecutionContext context)
{
final AuditService auditService = JobUtilities.getJobDataValue(context, "auditService", AuditService.class);
final String cutOffPeriodStr = JobUtilities.getJobDataValue(context, "cutOffPeriod", String.class);
final String timezoneStr = JobUtilities.getJobDataValue(context, "timezone", String.class, false);
final Period cutOffPeriod = Period.parse(cutOffPeriodStr);
final ZoneId zone = ZoneId.of(timezoneStr != null ? timezoneStr : "Z");
final ZonedDateTime now = LocalDateTime.now(ZoneId.of("Z")).atZone(zone);
final ZonedDateTime cutOffDate = now.minus(cutOffPeriod);
final long epochSecond = cutOffDate.toEpochSecond();
LOGGER.debug("Clearing all audit entries of application {} until {}", auditApplicationName, cutOffDate);
auditService.clearAudit(auditApplicationName, null, Long.valueOf(epochSecond));
}
示例3: 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);
}
}
示例4: 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++;
}
}
示例5: 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());
}
示例6: 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());
}
示例7: schedulePendingMirrors
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private void schedulePendingMirrors() {
final ZonedDateTime now = ZonedDateTime.now();
if (lastRunTime == null) {
lastRunTime = now.minus(TICK);
}
final ZonedDateTime currentLastRunTime = lastRunTime;
lastRunTime = now;
projectManager.list().values().stream()
.map(Project::metaRepo)
.flatMap(r -> {
try {
return r.mirrors().stream();
} catch (Exception e) {
logger.warn("Failed to load the mirror list from: {}", r.parent().name(), e);
return Stream.empty();
}
})
.filter(m -> {
final ExecutionTime execTime = ExecutionTime.forCron(m.schedule());
return execTime.nextExecution(currentLastRunTime).compareTo(now) < 0;
})
.forEach(m -> {
final ListenableFuture<?> future = worker.submit(() -> run(m, true));
FuturesExtra.addFailureCallback(
future,
cause -> logger.warn("Unexpected Git-to-CD mirroring failure: {}", m, cause));
});
}
示例8: BaseTick
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Constructor.
* @param timePeriod the time period
* @param endTime the end time of the tick period
*/
public BaseTick(Duration timePeriod, ZonedDateTime endTime) {
checkTimeArguments(timePeriod, endTime);
this.timePeriod = timePeriod;
this.endTime = endTime;
this.beginTime = endTime.minus(timePeriod);
}
示例9: lastValidTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
protected long lastValidTime() {
ZonedDateTime now = truncate(ZonedDateTime.now(), retention.getUnit());
ZonedDateTime lastValidDate = now.minus(retention);
return lastValidDate.toInstant().toEpochMilli();
}
示例10: 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())));
}
示例11: backward
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public void backward(CalendarComponentEvents.BackwardEvent event) {
int firstDay = event.getComponent().getFirstVisibleDayOfWeek();
int lastDay = event.getComponent().getLastVisibleDayOfWeek();
ZonedDateTime start = event.getComponent().getStartDate();
ZonedDateTime end = event.getComponent().getEndDate();
long durationInDays;
// for week view durationInDays = 7, for day view durationInDays = 1
if (event.getComponent().isDayMode()) { // day view
durationInDays = 1;
} else if (event.getComponent().isWeeklyMode()) {
durationInDays = 7;
} else {
durationInDays = Duration.between(start, end).toDays() +1;
}
start = start.minus(durationInDays, ChronoUnit.DAYS);
end = end.minus(durationInDays, ChronoUnit.DAYS);
if (event.getComponent().isDayMode()) { // day view
int dayOfWeek = start.get(ChronoField.DAY_OF_WEEK);
ZonedDateTime newDate = start;
while (!(firstDay <= dayOfWeek && dayOfWeek <= lastDay)) {
newDate = newDate.minus(1, ChronoUnit.DAYS);
dayOfWeek = start.get(ChronoField.DAY_OF_WEEK);
}
setDates(event, newDate, newDate);
return;
}
if (durationInDays < 28) {
setDates(event, start, end);
} else {
// go 7 days before and get the last day from month
setDates(event, start.minus(7, ChronoUnit.DAYS).with(lastDayOfMonth()), end.with(lastDayOfMonth()));
}
}