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:org.apache.tajo.util.TimeStampUtil.java

License:Apache License

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

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

License:Apache License

public static long getSecond(DateTime dateTime) {
    return convertToMicroSeconds(dateTime.withTime(dateTime.get(DateTimeFieldType.clockhourOfDay()),
            dateTime.get(DateTimeFieldType.minuteOfHour()), dateTime.get(DateTimeFieldType.secondOfMinute()),
            0));/*w w  w  .j a  v a  2s.c  o m*/
}

From source file:org.egov.pgr.service.reports.AgeingReportService.java

License:Open Source License

private Date getEndOfDayByDate(final DateTime fromDate) {
    return fromDate.withTime(23, 59, 59, 999).toDate();
}

From source file:org.egov.pgr.service.reports.AgeingReportService.java

License:Open Source License

private Date resetTimeByPassingDate(final DateTime fromDate) {
    return fromDate.withTime(0, 0, 0, 0).toDate();
}

From source file:org.fenixedu.ulisboa.specifications.ui.student.enrolment.ShiftEnrolmentByAcademicOfficeController.java

License:Open Source License

@RequestMapping(value = "currentSchedule.json/{registrationOid}/{executionSemesterOid}", produces = "application/json; charset=utf-8")
public @ResponseBody String schedule(@PathVariable("registrationOid") Registration registration,
        @PathVariable("executionSemesterOid") ExecutionSemester executionSemester) {

    checkUser();/*www .jav a2 s.co  m*/

    final JsonArray result = new JsonArray();

    for (final Shift shift : registration.getShiftsFor(executionSemester)) {
        for (Lesson lesson : shift.getAssociatedLessonsSet()) {
            final DateTime now = new DateTime();
            final DateTime weekDay = now
                    .withDayOfWeek(lesson.getDiaSemana().getDiaSemanaInDayOfWeekJodaFormat());
            final DateTime startTime = weekDay.withTime(lesson.getBeginHourMinuteSecond().getHour(),
                    lesson.getBeginHourMinuteSecond().getMinuteOfHour(), 0, 0);
            final DateTime endTime = weekDay.withTime(lesson.getEndHourMinuteSecond().getHour(),
                    lesson.getEndHourMinuteSecond().getMinuteOfHour(), 0, 0);

            final JsonObject event = new JsonObject();
            event.addProperty("id", lesson.getExternalId());
            event.addProperty("start", startTime.toString());
            event.addProperty("end", endTime.toString());
            event.addProperty("title", shift.getExecutionCourse().getName() + " ("
                    + shift.getShiftTypesCodePrettyPrint() + " - " + shift.getNome() + ")");
            event.addProperty("shiftId", shift.getExternalId());
            result.add(event);
        }
    }

    return result.toString();
}

From source file:org.fenixedu.ulisboa.specifications.ui.student.enrolment.ShiftEnrolmentController.java

License:Open Source License

@RequestMapping(value = "currentSchedule.json/{registrationOid}/{executionSemesterOid}", produces = "application/json; charset=utf-8")
public @ResponseBody String schedule(@PathVariable("registrationOid") Registration registration,
        @PathVariable("executionSemesterOid") ExecutionSemester executionSemester) {

    checkUser(registration);/*from   w  ww.  jav  a 2s. c  o m*/

    final JsonArray result = new JsonArray();

    for (final Shift shift : registration.getShiftsFor(executionSemester)) {
        for (Lesson lesson : shift.getAssociatedLessonsSet()) {
            final DateTime now = new DateTime();
            final DateTime weekDay = now
                    .withDayOfWeek(lesson.getDiaSemana().getDiaSemanaInDayOfWeekJodaFormat());
            final DateTime startTime = weekDay.withTime(lesson.getBeginHourMinuteSecond().getHour(),
                    lesson.getBeginHourMinuteSecond().getMinuteOfHour(), 0, 0);
            final DateTime endTime = weekDay.withTime(lesson.getEndHourMinuteSecond().getHour(),
                    lesson.getEndHourMinuteSecond().getMinuteOfHour(), 0, 0);

            final JsonObject event = new JsonObject();
            event.addProperty("id", lesson.getExternalId());
            event.addProperty("start", startTime.toString());
            event.addProperty("end", endTime.toString());
            event.addProperty("title", shift.getExecutionCourse().getName() + " ("
                    + shift.getShiftTypesCodePrettyPrint() + " - " + shift.getNome() + ")");
            result.add(event);
        }
    }

    return result.toString();
}

From source file:org.kalypso.ui.rrm.internal.calccase.CatchmentModelHelper.java

License:Open Source License

private static DateRange modifyWithTimestamp(final LocalTime timestamp, final DateTime simulationStart,
        final DateTime simulationEnd) {
    /* Nothing to do. */
    if (timestamp == null)
        return new DateRange(simulationStart.toDate(), simulationEnd.toDate());

    /* Convert to a date with the kalypso timezone. */
    /* The date fields are ignored. */
    final DateTime timestampUTC = timestamp
            .toDateTimeToday(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))); //$NON-NLS-1$
    final DateTime timestampDate = new DateTime(timestampUTC.toDate(),
            DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone()));

    /* Further adjust range by predefined time. */
    final DateTime startWithTime = simulationStart.withTime(timestampDate.getHourOfDay(),
            timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(),
            timestampDate.getMillisOfSecond());
    final DateTime endWithTime = simulationEnd.withTime(timestampDate.getHourOfDay(),
            timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(),
            timestampDate.getMillisOfSecond());

    return new DateRange(startWithTime.toDate(), endWithTime.toDate());
}

From source file:org.kalypso.ui.rrm.internal.calccase.CatchmentModelHelper.java

License:Open Source License

/**
 * This function calculates the range for the timeseries to be generated. The range equals the range defined in the
 * simulation adjusted as follows://from  w ww  .  j a v  a  2s.  c om
 * <ul>
 * <li>1 timestep earlier</li>
 * <li>3 timesteps later</li>
 * </ul>
 *
 * @param control
 *          The na control.
 * @param timestep
 *          The timestep.
 * @param timestamp
 *          The timestamp in UTC.
 * @return The date range.
 */
public static DateRange getRange(final NAControl control, final Period timestep, final LocalTime timestamp) {
    final Date simulationStart = control.getSimulationStart();
    final Date simulationEnd = control.getSimulationEnd();

    final DateTime start = new DateTime(simulationStart);
    final DateTime end = new DateTime(simulationEnd);

    final DateTime adjustedStart = start.minus(timestep);
    final DateTime adjustedEnd = end.plus(timestep).plus(timestep).plus(timestep);

    if (timestep.getDays() == 0 || timestamp == null)
        return new DateRange(adjustedStart.toDate(), adjustedEnd.toDate());

    /* Convert to a date with the kalypso timezone. */
    /* The date fields are ignored. */
    final DateTime timestampUTC = timestamp
            .toDateTimeToday(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))); //$NON-NLS-1$
    final DateTime timestampDate = new DateTime(timestampUTC.toDate(),
            DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone()));

    /* Further adjust range by predefined time. */
    final DateTime startWithTime = adjustedStart.withTime(timestampDate.getHourOfDay(),
            timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(),
            timestampDate.getMillisOfSecond());
    final DateTime endWithTime = adjustedEnd.withTime(timestampDate.getHourOfDay(),
            timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(),
            timestampDate.getMillisOfSecond());

    /* New start must always be before unadjusted start, fix, if this is not the case. */
    DateTime startWithTimeFixed;
    if (startWithTime.isAfter(adjustedStart))
        startWithTimeFixed = startWithTime.minus(timestep);
    else
        startWithTimeFixed = startWithTime;

    /* New end must always be after unadjusted end, fix, if this is not the case. */
    DateTime endWithTimeFixed;
    if (endWithTime.isBefore(adjustedEnd))
        endWithTimeFixed = endWithTime.plus(timestep);
    else
        endWithTimeFixed = endWithTime;

    return new DateRange(startWithTimeFixed.toDate(), endWithTimeFixed.toDate());

}

From source file:org.mythtv.android.utils.DateUtils.java

License:Open Source License

public static DateTime getEndOfDay(DateTime day) {
    return day.withTime(23, 59, 59, 999);
}

From source file:org.mythtv.android.utils.DateUtils.java

License:Open Source License

public static DateTime getNextDayAfterMythfilldatabase() {

    DateTime day = convertUtc(new DateTime(DateTimeZone.UTC));
    day = day.plus(Period.days(1));

    return day.withTime(4, 0, 0, 0);
}