Example usage for java.time OffsetDateTime toLocalTime

List of usage examples for java.time OffsetDateTime toLocalTime

Introduction

In this page you can find the example usage for java.time OffsetDateTime toLocalTime.

Prototype

public LocalTime toLocalTime() 

Source Link

Document

Gets the LocalTime part of this date-time.

Usage

From source file:Main.java

public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    LocalTime l = o.toLocalTime();
    System.out.println(l);//from w ww  .ja v  a 2 s .  co m
}

From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java

/**
 * Checks if scheduler's time data satisfies existing time parameters.
 *
 * @param dto           scheduler job data.
 * @param dateTime      existing time data.
 * @param desiredStatus target exploratory status which has influence for time/date checking ('running' status
 *                      requires for checking start time, 'stopped' - for end time, 'terminated' - for
 *                      'terminatedDateTime').
 * @return true/false./*from ww w  .j  a v a  2s  . c o m*/
 */
private boolean isSchedulerJobDtoSatisfyCondition(SchedulerJobDTO dto, OffsetDateTime dateTime,
        UserInstanceStatus desiredStatus) {
    ZoneOffset zOffset = dto.getTimeZoneOffset();
    OffsetDateTime roundedDateTime = OffsetDateTime.of(dateTime.toLocalDate(),
            LocalTime.of(dateTime.toLocalTime().getHour(), dateTime.toLocalTime().getMinute()),
            dateTime.getOffset());

    LocalDateTime convertedDateTime = ZonedDateTime
            .ofInstant(roundedDateTime.toInstant(), ZoneId.ofOffset(TIMEZONE_PREFIX, zOffset))
            .toLocalDateTime();

    return desiredStatus == TERMINATED
            ? Objects.nonNull(dto.getTerminateDateTime())
                    && convertedDateTime.toLocalDate().equals(dto.getTerminateDateTime().toLocalDate())
                    && convertedDateTime.toLocalTime().equals(getDesiredTime(dto, desiredStatus))
            : !convertedDateTime.toLocalDate().isBefore(dto.getBeginDate())
                    && isFinishDateMatchesCondition(dto, convertedDateTime)
                    && getDaysRepeat(dto, desiredStatus)
                            .contains(convertedDateTime.toLocalDate().getDayOfWeek())
                    && convertedDateTime.toLocalTime().equals(getDesiredTime(dto, desiredStatus));
}

From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java

@Override
public void executeStopResourceJob(boolean isAppliedForClusters) {
    OffsetDateTime currentDateTime = OffsetDateTime.now();
    List<SchedulerJobData> jobsToStop = getSchedulerJobsForAction(STOPPED, currentDateTime,
            isAppliedForClusters);//from  w  w w.  j av a  2 s  . c  om
    if (!jobsToStop.isEmpty()) {
        log.debug(isAppliedForClusters ? "Scheduler computational resource stop job is executing..."
                : "Scheduler exploratory stop job is executing...");
        log.info(CURRENT_DATETIME_INFO,
                LocalTime.of(currentDateTime.toLocalTime().getHour(),
                        currentDateTime.toLocalTime().getMinute()),
                currentDateTime.toLocalDate(), currentDateTime.getDayOfWeek());
        log.info(isAppliedForClusters ? "Quantity of clusters for stopping: {}"
                : "Quantity of exploratories for stopping: {}", jobsToStop.size());
        jobsToStop.forEach(job -> changeResourceStatusTo(STOPPED, job, isAppliedForClusters));
    }
}

From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java

@Override
public void executeStartResourceJob(boolean isAppliedForClusters) {
    OffsetDateTime currentDateTime = OffsetDateTime.now();
    List<SchedulerJobData> jobsToStart = getSchedulerJobsForAction(UserInstanceStatus.RUNNING, currentDateTime,
            isAppliedForClusters);/*from   ww w .j a v  a2 s  .  c  o m*/
    if (!jobsToStart.isEmpty()) {
        log.debug(isAppliedForClusters ? "Scheduler computational resource start job is executing..."
                : "Scheduler exploratory start job is executing...");
        log.info(CURRENT_DATETIME_INFO,
                LocalTime.of(currentDateTime.toLocalTime().getHour(),
                        currentDateTime.toLocalTime().getMinute()),
                currentDateTime.toLocalDate(), currentDateTime.getDayOfWeek());
        log.info(isAppliedForClusters ? "Quantity of clusters for starting: {}"
                : "Quantity of exploratories for starting: {}", jobsToStart.size());
        jobsToStart
                .forEach(job -> changeResourceStatusTo(UserInstanceStatus.RUNNING, job, isAppliedForClusters));
    }

}

From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java

@Override
public void executeTerminateResourceJob(boolean isAppliedForClusters) {
    OffsetDateTime currentDateTime = OffsetDateTime.now();
    List<SchedulerJobData> jobsToTerminate = getSchedulerJobsForAction(UserInstanceStatus.TERMINATED,
            currentDateTime, isAppliedForClusters);
    if (!jobsToTerminate.isEmpty()) {
        log.debug(isAppliedForClusters ? "Scheduler computational resource terminate job is executing..."
                : "Scheduler exploratory terminate job is executing...");
        log.info(CURRENT_DATETIME_INFO,//w ww.  j  a va 2  s  .  co m
                LocalTime.of(currentDateTime.toLocalTime().getHour(),
                        currentDateTime.toLocalTime().getMinute()),
                currentDateTime.toLocalDate(), currentDateTime.getDayOfWeek());
        log.info(isAppliedForClusters ? "Quantity of clusters for terminating: {}"
                : "Quantity of exploratories for terminating: {}", jobsToTerminate.size());
        jobsToTerminate.forEach(
                job -> changeResourceStatusTo(UserInstanceStatus.TERMINATED, job, isAppliedForClusters));
    }
}