Example usage for org.joda.time DateTime withTime

List of usage examples for org.joda.time DateTime withTime

Introduction

In this page you can find the example usage for org.joda.time DateTime withTime.

Prototype

public DateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) 

Source Link

Document

Returns a copy of this datetime with the specified time, retaining the date fields.

Usage

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets time./*w  ww  .  j a v  a 2s . co m*/
 *
 * @param moment       the moment
 * @param hourOfDay    the hour of day
 * @param minuteOfHour the minute of hour
 * @return the time
 */
public static DateTime setTime(DateTime moment, int hourOfDay, int minuteOfHour) {
    return moment.withTimeAtStartOfDay().withTime(hourOfDay, minuteOfHour, 0, 0);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets time.//from   w  w  w.ja va 2s. co  m
 *
 * @param moment         the moment
 * @param hourOfDay      the hour of day
 * @param minuteOfHour   the minute of hour
 * @param secondOfMinute the second of minute
 * @return the time
 */
public static DateTime setTime(DateTime moment, int hourOfDay, int minuteOfHour, int secondOfMinute) {
    return moment.withTimeAtStartOfDay().withTime(hourOfDay, minuteOfHour, secondOfMinute, 0);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets time.//from   w w  w  .  j a  v  a2 s.c o m
 *
 * @param moment         the moment
 * @param hourOfDay      the hour of day
 * @param minuteOfHour   the minute of hour
 * @param secondOfMinute the second of minute
 * @param millisOfSecond the millis of second
 * @return the time
 */
public static DateTime setTime(DateTime moment, int hourOfDay, int minuteOfHour, int secondOfMinute,
        int millisOfSecond) {
    return moment.withTimeAtStartOfDay().withTime(hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}

From source file:module.mission.domain.NationalMission.java

License:Open Source License

@Override
public double getFirstDayPersonelDayExpensePercentage(final PersonelExpenseItem personelExpenseItem) {
    double result = 0.0;
    final DateTime departure = personelExpenseItem.getStart();
    final DateTime arrival = personelExpenseItem.getEnd();

    if (!arrival.isAfter(departure)) {
        return Double.MAX_VALUE;
    }//  w w w.  j a va 2 s .c o  m

    final Interval interval = new Interval(departure, arrival);
    // Check if include lunch period
    if (overlapsMeal(interval, departure, 13)) {
        result += 0.25;
    }
    // Check if include dinner period
    if (overlapsMeal(interval, departure, 20)) {
        result += 0.25;
    }
    final DateTime accomodationThreashold = departure.withTime(22, 0, 0, 0);
    // Check if include accomodations
    if (personelExpenseItem instanceof FullPersonelExpenseItem && arrival.isAfter(accomodationThreashold)) {
        result += 0.5;
    }
    return result;
}

From source file:module.mission.domain.NationalMission.java

License:Open Source License

private boolean overlapsMeal(final Interval interval, final DateTime dateTime, final int hour) {
    final Interval mealTime = new Interval(dateTime.withTime(hour, 0, 0, 0), Hours.ONE);
    return interval.overlaps(mealTime);
}

From source file:module.mission.domain.NationalMission.java

License:Open Source License

@Override
protected boolean discountLunchDay(final DateTime dateTime) {
    if (super.discountLunchDay(dateTime)) {
        if (isFirstDay(dateTime)) {
            final Interval interval = new Interval(getDaparture(), dateTime.withTime(23, 59, 59, 0));
            return overlapsMeal(interval, dateTime, 13);
        } else if (isLastDay(dateTime)) {
            final Interval interval = new Interval(dateTime.withTime(0, 0, 0, 0), getArrival());
            return overlapsMeal(interval, dateTime, 13);
        }//from   ww  w  .ja va 2  s.com
        return true;
    }
    return false;
}

From source file:org.apache.tajo.util.datetime.DateTimeUtil.java

License:Apache License

public static long getHour(DateTime dateTime) {
    return convertToMicroSeconds(
            dateTime.withTime(dateTime.get(org.joda.time.DateTimeFieldType.hourOfDay()), 0, 0, 0));
}

From source file:org.apache.tajo.util.datetime.DateTimeUtil.java

License:Apache License

public static long getMinute(DateTime dateTime) {
    return convertToMicroSeconds(dateTime.withTime(dateTime.get(org.joda.time.DateTimeFieldType.hourOfDay()),
            dateTime.get(org.joda.time.DateTimeFieldType.minuteOfHour()), 0, 0));
}

From source file:org.apache.tajo.util.datetime.DateTimeUtil.java

License:Apache License

public static long getSecond(DateTime dateTime) {
    return convertToMicroSeconds(dateTime.withTime(dateTime.get(org.joda.time.DateTimeFieldType.hourOfDay()),
            dateTime.get(org.joda.time.DateTimeFieldType.minuteOfHour()),
            dateTime.get(org.joda.time.DateTimeFieldType.secondOfMinute()), 0));
}

From source file:org.apache.tajo.util.TimeStampUtil.java

License:Apache License

public static long getHour(DateTime dateTime) {
    return convertToMicroSeconds(dateTime.withTime(dateTime.get(DateTimeFieldType.clockhourOfDay()), 0, 0, 0));
}