Example usage for org.joda.time LocalDateTime withMillisOfDay

List of usage examples for org.joda.time LocalDateTime withMillisOfDay

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime withMillisOfDay.

Prototype

public LocalDateTime withMillisOfDay(int millis) 

Source Link

Document

Returns a copy of this datetime with the millis of day field updated.

Usage

From source file:energy.usef.dso.workflow.step.DsoDetermineOrangeReductionPeriodsStub.java

License:Apache License

private List<ConnectionCapacityLimitationPeriodDto> buildPeriods(
        List<ConnectionMeterEventDto> connectionMeterEventDtos) {
    List<ConnectionCapacityLimitationPeriodDto> results = new ArrayList<>();
    ConnectionCapacityLimitationPeriodDto connectionMeterEventPeriodDto = null;
    for (ConnectionMeterEventDto connectionMeterEventDto : connectionMeterEventDtos) {
        // if start/ending event, set endTime of previous period.
        if (connectionMeterEventPeriodDto != null && (MeterEventTypeDto.CONNECTION_RESUMPTION
                .equals(connectionMeterEventDto.getEventType())
                || MeterEventTypeDto.CONNECTION_INTERRUPTION.equals(connectionMeterEventDto.getEventType()))) {
            connectionMeterEventPeriodDto.setEndDateTime(connectionMeterEventDto.getEventDateTime());
            connectionMeterEventPeriodDto = null;
        }/*  ww  w  .j  a v  a2 s .com*/
        // if capacity management event, then set start time and end time
        if (MeterEventTypeDto.CAPACITY_MANAGEMENT.equals(connectionMeterEventDto.getEventType())) {
            LocalDateTime eventTime = connectionMeterEventDto.getEventDateTime();
            BigInteger eventData = connectionMeterEventDto.getEventData();
            if (eventData != null) {
                connectionMeterEventPeriodDto = new ConnectionCapacityLimitationPeriodDto();
                connectionMeterEventPeriodDto.setEntityAddress(connectionMeterEventDto.getEntityAddress());
                connectionMeterEventPeriodDto.setStartDateTime(eventTime);
                LocalDateTime endOfDay = eventTime.withMillisOfDay(eventTime.millisOfDay().getMaximumValue());
                connectionMeterEventPeriodDto.setEndDateTime(endOfDay);
                connectionMeterEventPeriodDto.setCapacityReduction(eventData);
                results.add(connectionMeterEventPeriodDto);
            } else if (connectionMeterEventPeriodDto != null) {
                connectionMeterEventPeriodDto.setEndDateTime(eventTime);
                connectionMeterEventPeriodDto = null;
            }
        }
    }
    return results;
}