Example usage for org.joda.time DateTime withTimeAtStartOfDay

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

Introduction

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

Prototype

public DateTime withTimeAtStartOfDay() 

Source Link

Document

Returns a copy of this datetime with the time set to the start of the day.

Usage

From source file:aplicacion.control.RolDePagoClienteController.java

public void setControlEmpleadoInfo(Usuario empleado, Fecha inicio, Fecha fin) {

    ControlDiarioDAO controlDAO = new ControlDiarioDAO();
    ControlExtrasDAO extrasDAO = new ControlExtrasDAO();

    Fecha fechaInicial = new Fecha(inicio.getFecha()); // dias anteriores de horas extras 
    Fecha fechaFinal = new Fecha(fin.getFecha());

    int days = (int) fechaInicial.daysDifference(fechaFinal);

    controlesDiarios = new ArrayList<>();

    for (int i = 0; i <= days; i++) {
        ControlTable controlTable = new ControlTable();
        controlTable.setFecha(fechaInicial.plusDays(i));
        controlTable.setFechaString(controlTable.getFecha().toStringInverse());
        controlTable.setDia(controlTable.getFecha().getMonthName());
        controlesDiarios.add(controlTable);
    }/* ww  w .  j a v a  2 s.c o  m*/

    System.out.println("dias " + controlesDiarios.size());
    controlesEmpleado = new ArrayList<>();
    controlesEmpleado.addAll(controlDAO.findAllByEmpleadoIdInDeterminateTime(empleado.getId(),
            fechaInicial.getFecha(), fechaFinal.getFecha()));

    ////////////////////////////////////////////////////////////////////////////////////////
    Date fechaInicialExtra = fechaInicial.minusDays(7).getDate(); // dias anteriores de horas extras 
    Date fechaFinalExtra = fechaFinal.minusDays(7).getDate();
    System.out.println("fecha inicio a mostrar para horas extras " + fechaInicialExtra.toString());
    System.out.println("fecha final a mostrar para horas extras " + fechaFinalExtra.toString());
    DateTime dateA = new DateTime(fechaInicialExtra.getTime());
    DateTime dateB = new DateTime(fechaFinalExtra.getTime());

    int daysE = Days.daysBetween(dateA.withTimeAtStartOfDay(), dateB.withTimeAtStartOfDay()).getDays();

    controlesExtras = new ArrayList<>();

    for (int i = 0; i <= daysE; i++) {
        ControlTable controlTable = new ControlTable();
        controlTable.setFechaExtra(dateA.plusDays(i));
        controlTable.setFechaString(dateA.plusDays(i).toString("dd-MM-yyyy")); // QUITADO extrano problema en java.sql.date que lo deja con un mes mas del real, se deberia optimizar y acomodar el error, de momento se solvento diminuyendo un mes antes de pasar a string
        controlesExtras.add(controlTable);
    }

    controlesHoras = new ArrayList<>();
    controlesHoras.addAll(extrasDAO.findAllByEmpleadoIdInDeterminateTime(empleado.getId(), fechaInicialExtra,
            fechaFinalExtra));
    System.out.println("cantidad de controles de horas extras " + controlesHoras.size());
    setToTable(true);
}

From source file:ar.com.informaticaorion.sasha.beans.CollectionsBean.java

private int getDelay(Ticket ticket) {
    DateTime dtCollectionDate = new DateTime(this.getCollectionActivo().getCollectionDate());
    DateTime dtTicketDueDate = new DateTime(ticket.getDueDate());
    int delay = Days
            .daysBetween(dtTicketDueDate.withTimeAtStartOfDay(), dtCollectionDate.withTimeAtStartOfDay())
            .getDays();/*from   w w w . ja va 2  s.c o m*/
    return delay;
}

From source file:carrental.beans.billing.BillingBean.java

private int simulateDaysUsed(ReturnProtocol returnProtocol) {
    DateTime newReturnDate = new DateTime(simulateReturnDate(returnProtocol));
    DateTime reservationDate = new DateTime(returnProtocol.getReservationDate().getTime());
    return Days.daysBetween(reservationDate.withTimeAtStartOfDay(), newReturnDate.withTimeAtStartOfDay())
            .getDays();/*from ww w.  jav  a 2s .co  m*/
}

From source file:com.amlcurran.messages.core.analysis.SmsMessageAnalyser.java

License:Apache License

boolean isYesterday(Time time) {
    DateTime then = new DateTime(time.toMillis());
    return then.withTimeAtStartOfDay().plusDays(1).equals(startOfToday);
}

From source file:com.amlcurran.messages.core.analysis.SmsMessageAnalyser.java

License:Apache License

boolean isToday(Time time) {
    DateTime then = new DateTime(time.toMillis());
    return then.withTimeAtStartOfDay().equals(startOfToday);
}

From source file:com.facebook.presto.atop.AtopPageSourceProvider.java

License:Apache License

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle,
        ConnectorSession session, ConnectorSplit split, List<ColumnHandle> columns) {
    AtopSplit atopSplit = checkType(split, AtopSplit.class, "split");

    ImmutableList.Builder<Type> types = ImmutableList.builder();
    ImmutableList.Builder<AtopColumn> atopColumns = ImmutableList.builder();

    for (ColumnHandle column : columns) {
        AtopColumnHandle atopColumnHandle = checkType(column, AtopColumnHandle.class, "column");
        AtopColumn atopColumn = atopSplit.getTable().getColumn(atopColumnHandle.getName());
        atopColumns.add(atopColumn);//  w ww.  j a va 2  s. c  o  m
        types.add(typeManager.getType(atopColumn.getType()));
    }

    // Timezone is not preserved during JSON serialization
    DateTime date = atopSplit.getDate().withZone(timeZone);
    checkState(date.equals(date.withTimeAtStartOfDay()), "Expected date to be at beginning of day");
    return new AtopPageSource(readerPermits, atopFactory, session, utf8Slice(atopSplit.getHost().getHostText()),
            atopSplit.getTable(), date, atopColumns.build(), types.build());
}

From source file:com.krycha.vaadin.example.entity.Incident.java

License:Apache License

/**
 * @param date/*from   w  ww  . j  a v  a 2s .  c  o m*/
 *            the date to set
 */
public void setDate(DateTime date) {
    this.date = date.withTimeAtStartOfDay().withDayOfMonth(1);
}

From source file:com.marand.thinkmed.medications.administration.impl.AdministrationTaskCreatorImpl.java

License:Open Source License

private List<NewTaskRequestDto> createTasksForVariableDaysTherapy(final String patientId,
        final VariableSimpleTherapyDto therapy, final Interval taskCreationInterval,
        final AdministrationTaskCreateActionEnum action) {
    final Map<DateTime, TherapyDoseDto> timesWithDosesMap = new HashMap<>();

    for (final TimedSimpleDoseElementDto timedDoseElement : therapy.getTimedDoseElements()) {
        getTimedDoseForVariableDaysTherapy(therapy, taskCreationInterval, action, timedDoseElement,
                timedDoseElement.getDate()).forEach(e -> timesWithDosesMap.put(e.getFirst(), e.getSecond()));
    }// w w w  . ja  va2 s .c o m

    final DateTime lastAdministrationDateTime = timesWithDosesMap.entrySet().stream().map(Map.Entry::getKey)
            .max(Comparator.naturalOrder()).orElse(null);

    final boolean therapyContinuesAfterLastDefinedDose = lastAdministrationDateTime != null
            && lastAdministrationDateTime.isBefore(taskCreationInterval.getEnd());
    if (therapyContinuesAfterLastDefinedDose) {
        //repeat last day
        final DateTime lastDayStart = lastAdministrationDateTime.withTimeAtStartOfDay();
        final List<TimedSimpleDoseElementDto> lastDayDoses = therapy.getTimedDoseElements().stream()
                .filter(t -> t.getDate().withTimeAtStartOfDay().equals(lastDayStart))
                .collect(Collectors.toList());

        DateTime nextDay = lastDayStart.plusDays(1);
        while (taskCreationInterval.contains(nextDay)) {
            for (final TimedSimpleDoseElementDto timedDoseElement : lastDayDoses) {
                getTimedDoseForVariableDaysTherapy(therapy, taskCreationInterval, action, timedDoseElement,
                        nextDay).forEach(e -> timesWithDosesMap.put(e.getFirst(), e.getSecond()));
            }
            nextDay = nextDay.plusDays(1);
        }
    }

    return timesWithDosesMap.keySet().stream().sorted(Comparator.naturalOrder())
            .filter(administrationTime -> !administrationTime.isAfter(taskCreationInterval.getEnd()))
            .map(administrationTime -> createMedicationTaskRequest(patientId, therapy,
                    AdministrationTypeEnum.START, administrationTime,
                    timesWithDosesMap.get(administrationTime)))
            .collect(Collectors.toList());
}

From source file:com.marand.thinkmed.medications.administration.impl.AdministrationTaskCreatorImpl.java

License:Open Source License

private Opt<Pair<DateTime, TherapyDoseDto>> getTimedDoseForVariableDaysTherapy(
        final VariableSimpleTherapyDto therapy, final Interval taskCreationInterval,
        final AdministrationTaskCreateActionEnum action, final TimedSimpleDoseElementDto timedDoseElement,
        final DateTime date) {
    final HourMinuteDto doseTime = timedDoseElement.getDoseTime();
    final DateTime administrationDateTime = date.withTimeAtStartOfDay().plusHours(doseTime.getHour())
            .plusMinutes(doseTime.getMinute());
    final TherapyDoseDto dose = getTherapyDoseForSimpleTherapy(timedDoseElement.getDoseElement(), therapy);

    final DateTime taskCreationIntervalEnd = taskCreationInterval.getEnd();
    final boolean inTaskCreationInterval;
    //noinspection IfMayBeConditional
    if (action.isTaskCreationIntervalStartIncluded()) {
        inTaskCreationInterval = taskCreationInterval.contains(administrationDateTime)
                || taskCreationIntervalEnd.equals(administrationDateTime);
    } else {/*  w  w  w.  j a  va 2  s .co  m*/
        inTaskCreationInterval = taskCreationInterval.getStart().isBefore(administrationDateTime)
                && (taskCreationIntervalEnd.isAfter(administrationDateTime)
                        || taskCreationIntervalEnd.equals(administrationDateTime));
    }

    if (dose != null && dose.getNumerator() != null && inTaskCreationInterval) {
        return Opt.of(Pair.of(administrationDateTime, dose));
    }
    return Opt.none();
}

From source file:com.marand.thinkmed.medications.administration.impl.AdministrationTaskCreatorImpl.java

License:Open Source License

private List<Interval> removeInactiveTherapyDaysFromTasksInterval(final TherapyDto therapy,
        final DateTime start, final DateTime end) {
    final DateTime therapyStart = therapy.getStart();
    final Integer daysFrequency = therapy.getDosingDaysFrequency();

    final List<Interval> intervals = new ArrayList<>();

    DateTime intervalStart = new DateTime(start);
    DateTime intervalEnd = intervalStart.withTimeAtStartOfDay().plusDays(1);

    final DateTime firstDayStart = intervalStart.withTimeAtStartOfDay();

    boolean validDayOfWeek = isInValidDaysOfWeek(intervalStart, therapy.getDaysOfWeek());
    boolean validFrequency = isInValidDaysFrequency(intervalStart, therapyStart, daysFrequency);
    boolean previousDayWasValid = validDayOfWeek && validFrequency;
    if (!previousDayWasValid) {
        intervalStart = firstDayStart.plusDays(1);
    }//w w  w .  j a va 2  s  .  com
    boolean validInFutureDays = false;
    while (intervalEnd.isBefore(end) || intervalEnd.equals(end)) {
        validDayOfWeek = isInValidDaysOfWeek(intervalEnd, therapy.getDaysOfWeek());
        validFrequency = isInValidDaysFrequency(intervalEnd, therapyStart, daysFrequency);
        if (validDayOfWeek && validFrequency) {
            previousDayWasValid = true;
        } else {
            if (previousDayWasValid) {
                intervals.add(new Interval(intervalStart, intervalEnd));
            }
            previousDayWasValid = false;
            intervalStart = intervalEnd.plusDays(1);
        }
        intervalEnd = intervalEnd.plusDays(1);
        validInFutureDays = true;
    }
    if (previousDayWasValid && validInFutureDays || intervalEnd.minusDays(1).isBefore(end)) {
        if (!intervalStart.isAfter(end)) {
            intervals.add(new Interval(intervalStart, end));
        }
    }
    return intervals;
}