Java Code Examples for java.time.OffsetDateTime#isBefore()

The following examples show how to use java.time.OffsetDateTime#isBefore() . 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: UpdateChecker.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
/**
 * The Date Alert has in the About will always be slightly before the Docker Hub date. So if the two are within 1 hour of each other, then we will consider them the same.
 */
private int compareDateStrings(String first, String second) {
    try {
        OffsetDateTime firstDate = parseDate(first, DOCKER_DATE_FORMAT);
        OffsetDateTime secondDate = parseDate(second, DOCKER_DATE_FORMAT);

        OffsetDateTime hourEarlier = firstDate.minusHours(1);
        OffsetDateTime hourLater = firstDate.plusHours(1);

        boolean secondIsWithinAnHourOfFirst = hourEarlier.isBefore(secondDate) && hourLater.isAfter(secondDate);

        if (secondIsWithinAnHourOfFirst) {
            return 0;
        }
        if (firstDate.isAfter(secondDate)) {
            return -1;
        } else if (firstDate.isBefore(secondDate)) {
            return 1;
        }
    } catch (ParseException e) {
        logger.debug("Could not parse the date strings with the format {}.", DOCKER_DATE_FORMAT);
        logger.debug(e.getMessage(), e);
    }
    return 0;
}
 
Example 2
Source File: SetupEditorController.java    From OEE-Designer with MIT License 5 votes vote down vote up
@Override
protected void saveRecord() throws Exception {
	// time period
	setTimePeriod(setupEvent);

	// material
	if (setupEvent.getMaterial() == null) {
		throw new Exception(DesignerLocalizer.instance().getErrorString("material.not.specified"));
	}

	// job
	setupEvent.setJob(tfJob.getText());

	// close off last setup
	List<KeyedObject> records = new ArrayList<>();
	records.add(setupEvent);

	// close off last setup
	OeeEvent lastRecord = PersistenceService.instance().fetchLastEvent(setupEvent.getEquipment(),
			OeeEventType.MATL_CHANGE);

	if (lastRecord != null && !(lastRecord.getKey().equals(setupEvent.getKey()))) {
		OffsetDateTime newStart = setupEvent.getStartTime();
		OffsetDateTime lastStart = lastRecord.getStartTime();

		if (newStart.isBefore(lastStart)) {
			throw new Exception(
					DesignerLocalizer.instance().getErrorString("start.before.end", newStart, lastStart));
		}

		lastRecord.setEndTime(newStart);
		Duration duration = Duration.between(lastRecord.getStartTime(), lastRecord.getEndTime());
		lastRecord.setDuration(duration);

		records.add(lastRecord);
	}

	// save records
	PersistenceService.instance().save(records);
}
 
Example 3
Source File: JobStatusCalculator.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates whether or not the last job execution is too old.
 *
 * @param jobInfo       job info of the last job execution
 * @param jobDefinition job definition, specifying the max age of jobs
 * @return boolean
 */
protected boolean jobTooOld(final JobInfo jobInfo, final JobDefinition jobDefinition) {
    final Optional<OffsetDateTime> stopped = jobInfo.getStopped();
    if (stopped.isPresent() && jobDefinition.maxAge().isPresent()) {
        final OffsetDateTime deadlineToRerun = stopped.get().plus(jobDefinition.maxAge().get());
        return deadlineToRerun.isBefore(now());
    }

    return false;
}
 
Example 4
Source File: Utils.java    From FROST-Server with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static TimeInterval intervalFromTimes(OffsetDateTime timeStart, OffsetDateTime timeEnd) {
    if (timeStart == null) {
        timeStart = OffsetDateTime.of(LocalDateTime.MAX, UTC);
    }
    if (timeEnd == null) {
        timeEnd = OffsetDateTime.of(LocalDateTime.MIN, UTC);
    }
    if (timeEnd.isBefore(timeStart)) {
        return null;
    } else {
        return TimeInterval.create(timeStart.toInstant().toEpochMilli(), timeEnd.toInstant().toEpochMilli());
    }
}
 
Example 5
Source File: TCKOffsetDateTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 6
Source File: TCKOffsetDateTime.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 7
Source File: TCKOffsetDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 8
Source File: TCKOffsetDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 9
Source File: TCKOffsetDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 10
Source File: PrometheusBasedResourceLimitChecks.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Calculates the effective resource limit for a tenant for the given period from the configured values.
 * <p>
 * In the <em>monthly</em> mode, if the effectiveSince date doesn't fall on the 
 * first day of the month then the effective resource limit for the tenant is 
 * calculated as below.
 * <pre>
 *             configured limit 
 *   ---------------------------------- x No. of days from effectiveSince till lastDay of the targetDateMonth.
 *    No. of days in the current month
 * </pre>
 * <p>
 * For rest of the months and the <em>days</em> mode, the configured limit is used directly.
 *
 * @param effectiveSince The point of time on which the given resource limit came into effect.
 * @param targetDateTime The target date and time.
 * @param mode The mode of the period. 
 * @param configuredLimit The configured limit. 
 * @return The effective resource limit that has been calculated.
 */
long calculateEffectiveLimit(
        final OffsetDateTime effectiveSince,
        final OffsetDateTime targetDateTime,
        final PeriodMode mode,
        final long configuredLimit) {
    if (PeriodMode.MONTHLY.equals(mode)
            && configuredLimit > 0
            && !targetDateTime.isBefore(effectiveSince)
            && YearMonth.from(targetDateTime).equals(YearMonth.from(effectiveSince))
            && effectiveSince.getDayOfMonth() != 1) {
        final OffsetDateTime lastDayOfMonth = effectiveSince.with(TemporalAdjusters.lastDayOfMonth());
        final long daysBetween = ChronoUnit.DAYS
                .between(effectiveSince, lastDayOfMonth) + 1;
        return Double.valueOf(Math.ceil(daysBetween * configuredLimit / lastDayOfMonth.getDayOfMonth()))
                .longValue();
    }
    return configuredLimit;
}
 
Example 11
Source File: TCKOffsetDateTime.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 12
Source File: TCKOffsetDateTime.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 13
Source File: TCKOffsetDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 14
Source File: TCKOffsetDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 15
Source File: TCKOffsetDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 16
Source File: TCKOffsetDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 17
Source File: TimestampedValueGroupGenerationServiceImpl.java    From sample-data-generator with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<TimestampedValueGroup> generateValueGroups(MeasureGenerationRequest request) {

    ExponentialDistribution interPointDurationDistribution =
            new ExponentialDistribution(request.getMeanInterPointDuration().getSeconds());

    long totalDurationInS = Duration.between(request.getStartDateTime(), request.getEndDateTime()).getSeconds();

    OffsetDateTime effectiveDateTime = request.getStartDateTime();
    List<TimestampedValueGroup> timestampedValueGroups = new ArrayList<>();

    do {
        effectiveDateTime = effectiveDateTime.plus((long) interPointDurationDistribution.sample(), SECONDS);

        if (!effectiveDateTime.isBefore(request.getEndDateTime())) {
            break;
        }

        if (request.isSuppressNightTimeMeasures() != null && request.isSuppressNightTimeMeasures() &&
                (effectiveDateTime.getHour() >= NIGHT_TIME_START_HOUR ||
                        effectiveDateTime.getHour() < NIGHT_TIME_END_HOUR)) {
            continue;
        }

        TimestampedValueGroup valueGroup = new TimestampedValueGroup();
        valueGroup.setTimestamp(effectiveDateTime);

        double trendProgressFraction = (double)
                Duration.between(request.getStartDateTime(), effectiveDateTime).getSeconds() / totalDurationInS;

        for (Map.Entry<String, BoundedRandomVariableTrend> trendEntry : request.getTrends().entrySet()) {

            String key = trendEntry.getKey();
            BoundedRandomVariableTrend trend = trendEntry.getValue();

            double value = trend.nextValue(trendProgressFraction);
            valueGroup.setValue(key, value);
        }

        timestampedValueGroups.add(valueGroup);
    }
    while (true);

    return timestampedValueGroups;
}
 
Example 18
Source File: TrendChartController.java    From OEE-Designer with MIT License 4 votes vote down vote up
@FXML
public void onRefresh() {
	try {
		onResetTrending();

		OffsetDateTime odtStart = null;
		OffsetDateTime odtEnd = null;

		// start date and time
		LocalDate startDate = dpStartDate.getValue();

		if (startDate != null) {
			Duration startSeconds = null;
			if (tfStartTime.getText() != null && tfStartTime.getText().trim().length() > 0) {
				startSeconds = AppUtils.durationFromString(tfStartTime.getText().trim());
			} else {
				startSeconds = Duration.ZERO;
			}

			LocalTime startTime = LocalTime.ofSecondOfDay(startSeconds.getSeconds());
			LocalDateTime ldtStart = LocalDateTime.of(startDate, startTime);
			odtStart = DomainUtils.fromLocalDateTime(ldtStart);
		}

		// end date and time
		LocalDate endDate = dpEndDate.getValue();

		if (endDate != null) {
			Duration endSeconds = null;
			if (tfEndTime.getText() != null && tfEndTime.getText().trim().length() > 0) {
				endSeconds = AppUtils.durationFromString(tfEndTime.getText().trim());
			} else {
				endSeconds = Duration.ZERO;
			}

			LocalTime endTime = LocalTime.ofSecondOfDay(endSeconds.getSeconds());
			LocalDateTime ldtEnd = LocalDateTime.of(endDate, endTime);
			odtEnd = DomainUtils.fromLocalDateTime(ldtEnd);
		}

		if (odtStart != null && odtEnd != null && odtEnd.isBefore(odtStart)) {
			throw new Exception(DesignerLocalizer.instance().getErrorString("start.before.end", odtStart, odtEnd));
		}

		List<OeeEvent> events = PersistenceService.instance().fetchEvents(eventResolver.getEquipment(),
				eventResolver.getType(), odtStart, odtEnd);

		for (OeeEvent event : events) {
			// plot values
			Object plottedValue = null;

			switch (eventResolver.getType()) {
			case AVAILABILITY:
				plottedValue = event.getReason().getName();
				break;

			case CUSTOM:
				break;

			case JOB_CHANGE:
				plottedValue = event.getJob();
				break;

			case MATL_CHANGE:
				plottedValue = event.getMaterial().getName();
				break;

			case PROD_GOOD:
			case PROD_REJECT:
			case PROD_STARTUP:
				plottedValue = event.getAmount();
				break;

			default:
				break;
			}

			// add event to table
			event.setSourceId(eventResolver.getSourceId());
			event.setOutputValue(plottedValue);
			addEvent(event);

			// plot it
			plotData(event.getInputValue(), plottedValue);
		}

	} catch (Exception e) {
		AppUtils.showErrorDialog(e);
	}
}
 
Example 19
Source File: TCKOffsetDateTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}
 
Example 20
Source File: TCKOffsetDateTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_null() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    a.isBefore(null);
}