Example usage for org.joda.time LocalDate toDateMidnight

List of usage examples for org.joda.time LocalDate toDateMidnight

Introduction

In this page you can find the example usage for org.joda.time LocalDate toDateMidnight.

Prototype

@Deprecated
public DateMidnight toDateMidnight() 

Source Link

Document

Converts this LocalDate to a DateMidnight in the default time zone.

Usage

From source file:energy.usef.mdc.workflow.step.MdcMeterDataQueryStub.java

License:Apache License

private List<ConnectionMeterEventDto> generateConnectionMeterEventDto(String entityAddress, LocalDate day) {
    List<ConnectionMeterEventDto> result = new ArrayList<>();

    ConnectionMeterEventDto connectionMeterEventDto1 = new ConnectionMeterEventDto();
    connectionMeterEventDto1.setEntityAddress(entityAddress);
    LocalDateTime eventDateTime1 = new LocalDateTime(day.toDateMidnight().toDate())
            .plusMinutes(RANDOM.nextInt(MINUTES_PER_HOUR));
    connectionMeterEventDto1.setEventDateTime(eventDateTime1);
    result.add(connectionMeterEventDto1);

    ConnectionMeterEventDto connectionMeterEventDto2 = new ConnectionMeterEventDto();
    connectionMeterEventDto2.setEntityAddress(entityAddress);
    LocalDateTime eventDateTime2 = new LocalDateTime(day.toDateMidnight().toDate())
            .plusMinutes(MINUTES_PER_HOUR + 1 + RANDOM.nextInt(MINUTES_PER_HOUR));
    connectionMeterEventDto2.setEventDateTime(eventDateTime2);

    int randomInt = RANDOM.nextInt(EVENT_TYPE_CASES_AMOUNT);
    if (randomInt == CAPACITY_MANAGEMENT_ONLY) {
        connectionMeterEventDto1.setEventType(MeterEventTypeDto.CAPACITY_MANAGEMENT);
        BigInteger eventData = BigInteger
                .valueOf(generateRandomNumber(MIN_UNCONTROLLED_LOAD, MAX_UNCONTROLLED_LOAD));
        connectionMeterEventDto1.setEventData(eventData);

        connectionMeterEventDto2.setEventType(MeterEventTypeDto.CAPACITY_MANAGEMENT);
        result.add(connectionMeterEventDto2);
    } else if (randomInt == CONNECTION_INTERRUPTION_AND_RESUMPTION) {
        connectionMeterEventDto1.setEventType(MeterEventTypeDto.CONNECTION_INTERRUPTION);

        connectionMeterEventDto2.setEventType(MeterEventTypeDto.CONNECTION_RESUMPTION);
        result.add(connectionMeterEventDto2);
    } else if (randomInt == CAPACITY_MANAGEMENT_WITH_RANDOM) {
        connectionMeterEventDto1.setEventType(MeterEventTypeDto.CAPACITY_MANAGEMENT);
        if (RANDOM.nextBoolean()) {
            BigInteger eventData = BigInteger.valueOf(generateRandomNumber(MIN_POWER, MAX_POWER));
            connectionMeterEventDto1.setEventData(eventData);
        }//from w ww .  j  a  v  a 2  s.  c  o  m
    } else if (randomInt == CONNECTION_INTERRUPTION_ONLY) {
        connectionMeterEventDto1.setEventType(MeterEventTypeDto.CONNECTION_INTERRUPTION);
    } else if (randomInt == CONNECTION_RESUMPTION_ONLY) {
        connectionMeterEventDto1.setEventType(MeterEventTypeDto.CONNECTION_RESUMPTION);
    }

    return result;
}

From source file:energy.usef.pbcfeeder.PbcFeeder.java

License:Apache License

/**
 * @param date// w  ww .j a v  a 2  s .c  o  m
 * @param startPtuIndex of the list starting from 1 till 96 (PTU_PER_DAY).
 * @param amount
 * @return
 */
public List<PbcStubDataDto> getStubRowInputList(LocalDate date, int startPtuIndex, int amount) {
    if (startPtuIndex > PTU_PER_DAY) {
        date = date.plusDays((int) Math.floor(startPtuIndex / PTU_PER_DAY));
        startPtuIndex = startPtuIndex % PTU_PER_DAY;
    }

    // Match PTU-index with requested startIndex and date from ExcelSheet.
    LocalDate epochDate = new LocalDate("1970-01-01");
    int daysDif = Days.daysBetween(epochDate, date).getDays();
    int ptuOffset = (daysDif % DAYS_IN_SPREADSHEET) * PTU_PER_DAY + startPtuIndex - 1;
    List<PbcStubDataDto> pbcStubDataDtoList = new ArrayList<>();

    // Loop over stubRowInputList, if necessary, to get requested amount of ptus.
    do {
        int toIndex = 0;
        if (ptuOffset + amount > stubRowInputList.size()) {
            toIndex = stubRowInputList.size();
        } else {
            toIndex = ptuOffset + amount;
        }
        amount -= (toIndex - ptuOffset);

        pbcStubDataDtoList.addAll(stubRowInputList.subList(ptuOffset, toIndex));
        ptuOffset = 0;
    } while (amount > 0);

    // Create and set PtuContainer for pbcStubDataDto.

    int lastPtuIndex = 0;
    for (PbcStubDataDto pbcStubDataDto : pbcStubDataDtoList) {
        int ptuIndex = pbcStubDataDto.getIndex() % PTU_PER_DAY;
        if (ptuIndex == 0) {
            ptuIndex = PTU_PER_DAY;
        }
        if (ptuIndex < lastPtuIndex) {
            date = date.plusDays(1);
        }
        PbcPtuContainerDto ptuContainerDto = new PbcPtuContainerDto(date.toDateMidnight().toDate(), ptuIndex);
        pbcStubDataDto.setPtuContainer(ptuContainerDto);
        lastPtuIndex = ptuIndex;
    }
    return pbcStubDataDtoList;
}

From source file:energy.usef.test.DatabaseObject.java

License:Apache License

public void setPeriod(LocalDate period) {
    if (period == null) {
        this.period = null;
    } else {//from  w w w.ja va 2  s . co m
        this.period = period.toDateMidnight().toDate();
    }

}

From source file:gg.db.datamodel.Periods.java

License:Open Source License

/**
 * Gets the adjusted start date: the date is adjusted to the first day of the period<BR/>
 * Depending on periodType, the date will be:
 * <UL>/*from  w w w .  jav a2s.  c om*/
 * <LI>First day of the week (monday)</LI>
 * <LI>First day of the month</LI>
 * <LI>First day of the year</LI>>
 * </UL>
 * Example:
 * <UL>
 * <LI>getAdjustedStartDate(new LocalDate(2006, 5, 20), PeriodType.DAY) should return: <B>05/20/2006</B></LI>
 * <LI>getAdjustedStartDate(new LocalDate(2006, 5, 20), PeriodType.WEEK) should return: <B>05/15/2006</B> (if Configuration.getWeekStartingOn() == MONDAY)</LI>
 * <LI>getAdjustedStartDate(new LocalDate(2006, 5, 20), PeriodType.MONTH) should return: <B>05/01/2006</B></LI>
 * <LI>getAdjustedStartDate(new LocalDate(2006, 5, 20), PeriodType.YEAR) should return: <B>01/01/2006</B></LI>
 * <LI>getAdjustedStartDate(new LocalDate(2006, 5, 20), PeriodType.FREE) should return: <B>05/20/2006</B></LI>
 * </UL>
 * @param date Date to adjust to the start of the period
 * @param periodType Type of the Period to adjust the period
 * @return Date adjusted to the start of the period
 */
public static LocalDate getAdjustedStartDate(LocalDate date, PeriodType periodType) {
    if (date == null || periodType == null) {
        throw new IllegalArgumentException("One of the following parameters is null: 'date', 'periodType'");
    }

    LocalDate adjustedStartDate = null;
    switch (periodType) {
    case DAY: // No adjustement to do
        adjustedStartDate = date;
        break;
    case FREE: // No adjustement to do
        adjustedStartDate = date;
        break;
    case WEEK: // Adjust the date to the first day of the week (Monday)
        adjustedStartDate = date.toDateMidnight()
                .withField(DateTimeFieldType.dayOfWeek(), DateTimeConstants.MONDAY).toLocalDate();
        break;
    case MONTH: // Adjust the date to the first day of the month (<MONTH>/01/<YEAR>)
        adjustedStartDate = date.withField(DateTimeFieldType.dayOfMonth(), 1);
        break;
    case YEAR: // Adjust the date to the first day of the year (01/01/<YEAR>)
        adjustedStartDate = date.withField(DateTimeFieldType.dayOfMonth(), 1)
                .withField(DateTimeFieldType.monthOfYear(), 1);
        break;
    default:
        throw new AssertionError("Unknown PeriodType"); // should never happen
    }

    assert (adjustedStartDate != null);
    return adjustedStartDate;
}

From source file:gg.db.datamodel.Periods.java

License:Open Source License

/**
 * Gets the adjusted end date: the date is adjusted to the last day of the period<BR/>
 * Depending on periodType, the date will be:
 * <UL>//from ww w . jav a  2  s  . co m
 * <LI>Last day of the week (sunday)</LI>
 * <LI>Last day of the month</LI>
 * <LI>Last day of the year</LI>>
 * </UL>
 * Example:
 * <UL>
 * <LI>getAdjustedEndDate(new LocalDate(2006, 5, 20), PeriodType.DAY) should return: <B>05/20/2006</B></LI>
 * <LI>getAdjustedEndDate(new LocalDate(2006, 5, 20), PeriodType.WEEK) should return: <B>05/21/2006</B> (if Configuration.getWeekStartingOn() == MONDAY)</LI>
 * <LI>getAdjustedEndDate(new LocalDate(2006, 5, 20), PeriodType.MONTH) should return: <B>05/31/2006</B></LI>
 * <LI>getAdjustedEndDate(new LocalDate(2006, 5, 20), PeriodType.YEAR) should return: <B>12/31/2006</B></LI>
 * <LI>getAdjustedEndDate(new LocalDate(2006, 5, 20), PeriodType.FREE) should return: <B>05/20/2006</B></LI>
 * </UL>
 * @param date Date to adjust to the end of the period
 * @param periodType Type of the Period to adjust the date
 * @return Date adjusted to the end of the period
 */
public static LocalDate getAdjustedEndDate(LocalDate date, PeriodType periodType) {
    if (date == null || periodType == null) {
        throw new IllegalArgumentException("One of the following parameters is null: 'date', 'periodType'");
    }

    LocalDate adjustedEndDate = null;
    switch (periodType) {
    case DAY: // No adjustement to do
        adjustedEndDate = date;
        break;
    case FREE: // No adjustement to do
        adjustedEndDate = date;
        break;
    case WEEK: // Adjust the date to the last day of the week (sunday)
        adjustedEndDate = date.toDateMidnight()
                .withField(DateTimeFieldType.dayOfWeek(), DateTimeConstants.MONDAY + 6).toLocalDate();
        break;
    case MONTH: // Adjust the date to the last day of the month
        adjustedEndDate = date.withField(DateTimeFieldType.dayOfMonth(), 1).plusMonths(1).minusDays(1);
        break;
    case YEAR: // Adjust the date to the last day of the year (12/31/<YEAR>)
        adjustedEndDate = date.withField(DateTimeFieldType.dayOfMonth(), 1).plusMonths(1).minusDays(1)
                .withField(DateTimeFieldType.monthOfYear(), 12);
        break;
    default:
        throw new AssertionError("Unknown PeriodType"); // should never happen
    }

    assert (adjustedEndDate != null);
    return adjustedEndDate;
}

From source file:net.objectlab.kit.console.ConsoleMenu.java

License:Apache License

public static LocalDate getYMD(final String title, final LocalDate defaultValue) {
    final Date dateStr = ConsoleMenu.getDate(title,
            defaultValue != null ? defaultValue.toDateMidnight().toDate() : null);
    if (dateStr != null) {
        return new LocalDate(dateStr);
    }/*from w w w.j a v a 2s .  c  o m*/
    return null;
}

From source file:net.sargue.base.util.JodaUtils.java

License:Open Source License

/**
 * Convierte la fecha en el formato de Joda-Time al equivalente en el formato de JDBC
 * java.sql.Date/*from ww w  . j a  va2  s.c om*/
 * 
 * @param fecha la fecha en formato Joda-Time
 * @return la misma fecha en formato JDBC
 */
public static Date toJDBC(LocalDate fecha) {
    return fecha == null ? null : new Date(fecha.toDateMidnight().getMillis());
}

From source file:net.sourceforge.fenixedu.util.date.IntervalTools.java

License:Open Source License

public static Interval getInterval(LocalDate startDate, LocalDate endDate) {
    long start = startDate == null ? Long.MIN_VALUE : startDate.toDateMidnight().getMillis();
    long end = endDate == null ? Long.MAX_VALUE
            : endDate.toDateMidnight().toDateTime().withTime(23, 59, 59, 999).getMillis();

    return new Interval(start, end);
}

From source file:net.sourceforge.fenixedu.util.date.IntervalTools.java

License:Open Source License

public static Interval intervalWithStart(Interval originalInterval, LocalDate day) {
    long millis = day.toDateMidnight().getMillis();
    return new Interval(millis, originalInterval.getEndMillis());
}

From source file:net.sourceforge.fenixedu.util.date.IntervalTools.java

License:Open Source License

public static Interval intervalWithEnd(Interval originalInterval, LocalDate day) {
    long millis = day.toDateMidnight().toDateTime().withTime(23, 59, 59, 999).getMillis();
    return new Interval(originalInterval.getStartMillis(), millis);
}