Example usage for org.joda.time DateTime toLocalTime

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

Introduction

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

Prototype

public LocalTime toLocalTime() 

Source Link

Document

Converts this object to a LocalTime with the same time and chronology.

Usage

From source file:com.jay.pea.mhealthapp2.presenter.NewMedication.java

License:Open Source License

/**
 * method to create a medication from the user input data
 *
 * @return/*from w  ww .j  av a  2s . c  om*/
 */
private Medication createMed() {
    newMed = new Medication();
    newMed.setMedName(medicationET.getText().toString());
    newMed.setMedNotes(medNotesET.getText().toString());
    newMed.setDose(doseET.getText().toString());
    newMed.setFreq(freqSpinner.getSelectedItemPosition() + 1);
    Log.d(TAG, newMed.getFreq() + "");
    long startDateLong = startDate.getTimeInMillis() / 1000;
    int startDateInt = (int) startDateLong;
    newMed.setMedStart(startDateInt);
    Log.d(TAG, startDateInt + "");
    long endDateLong = endDate.getTimeInMillis() / 1000;
    int endDateInt = (int) endDateLong;
    newMed.setMedEnd(endDateInt);
    Log.d(TAG, endDateInt + "");

    if (medImageString.equals(PHOTOSTRING)) {
    }
    newMed.setImageRes(medImageString);

    int[] alertTimeArrayInt = new int[6];

    for (int i = 0; i < alertArray.length; i++) {
        DateTime dateString;
        DateTime alertTime = new DateTime();

        Log.d(TAG, alertArray[i].getText().toString() + " " + !alertArray[i].getText().toString().isEmpty());

        if (!alertArray[i].getText().toString().isEmpty()) {
            dateString = dtfTime.parseDateTime(alertArray[i].getText().toString());
        } else {
            dateString = dtfTime.parseDateTime(alert1.getText().toString());
        }
        long l = alertTime.withTime(dateString.toLocalTime()).getMillis() / 1000;
        alertTimeArrayInt[i] = (int) l;
    }

    newMed.setAlert1(alertTimeArrayInt[0]);
    newMed.setAlert2(alertTimeArrayInt[1]);
    newMed.setAlert3(alertTimeArrayInt[2]);
    newMed.setAlert4(alertTimeArrayInt[3]);
    newMed.setAlert5(alertTimeArrayInt[4]);
    newMed.setAlert6(alertTimeArrayInt[5]);

    int alertsOnInt = 0;
    if (alertsOn)
        alertsOnInt = 1;
    newMed.setAlertsOn(alertsOnInt);

    //set up the dose Map from the manager class
    newMed.setDoseMap1(new MedicationManager().buildDoseMap1(newMed, context));
    newMed.setDoseMap2(new MedicationManager().buildDoseMap2(newMed, context));

    return newMed;
}

From source file:com.qcadoo.mes.basic.shift.Shift.java

License:Open Source License

/**
 * Check if this shift will be working at given date and time. This method is aware of timetable exceptions
 * /*  w  w w  .  j a  v  a2 s .  c  o  m*/
 * @param date
 * @return true if this shift will be working at given date and time.
 * 
 * @deprecated use worksAt(DateTime) if you want to check if shift works at given date and time, or works(LocalDate) if all
 *             you want is just check if shift works at given day.
 */
@Deprecated
public boolean worksAt(final Date date) {
    DateTime dateTime = new DateTime(date);
    return (worksAt(dateTime.getDayOfWeek(), dateTime.toLocalTime())
            && !timetableExceptions.hasFreeTimeAt(date)) || timetableExceptions.hasWorkTimeAt(date);
}

From source file:com.qcadoo.mes.basic.shift.Shift.java

License:Open Source License

/**
 * Returns date range containing given date. This method IS AWARE of timetable exceptions.
 * //from w  ww  .  jav  a  2s  . c  om
 * <b>Be aware</b> - this method doesn't compose returned date range with the timetable exclusions/inclusions. This means that
 * if you have a shift which works at Monday from 8:00-16:00 and there is defined work time exclusion from 12:00-20:00 and you
 * ask for 10:00 then you will get date range from 8:00-16:00 (as in plan). But if you ask for 14:00 you will get
 * Optional.absent().
 * 
 * @param date
 *            date with time for which work dates range you want to find.
 * @return
 */
public Optional<DateRange> findWorkTimeAt(final Date date) {
    if (timetableExceptions.hasFreeTimeAt(date)) {
        return Optional.absent();
    }
    DateTime dateTime = new DateTime(date);
    Optional<TimeRange> maybeTimeRangeFromPlan = findWorkTimeAt(dateTime.getDayOfWeek(),
            dateTime.toLocalTime());
    for (TimeRange timeRangeFromPlan : maybeTimeRangeFromPlan.asSet()) {
        return Optional.of(buildDateRangeFrom(timeRangeFromPlan, date));
    }
    return timetableExceptions.findDateRangeFor(TimetableExceptionType.WORK_TIME, date);
}

From source file:com.qcadoo.mes.basic.shift.Shift.java

License:Open Source License

private DateRange buildDateRangeFrom(final TimeRange timeRange, final Date date) {
    DateTime dateTime = new DateTime(date);
    DateTime midnight = dateTime.withTimeAtStartOfDay();
    DateTime from;/*from   w  ww. jav a 2 s.co  m*/
    DateTime to;
    if (timeRange.startsDayBefore()) {
        if (dateTime.toLocalTime().isBefore(timeRange.getFrom())) {
            from = timeRange.getFrom().toDateTime(midnight.minusDays(1));
            to = timeRange.getTo().toDateTime(midnight);
        } else {
            from = timeRange.getFrom().toDateTime(midnight);
            to = timeRange.getTo().toDateTime(midnight.plusDays(1));
        }
    } else {
        from = timeRange.getFrom().toDateTime(midnight);
        to = timeRange.getTo().toDateTime(midnight);
    }
    return new DateRange(from.toDate(), to.toDate());
}

From source file:com.qcadoo.mes.productionPerShift.dates.OrderRealizationDaysResolver.java

License:Open Source License

private Optional<OrderRealizationDay> tryResolveFirstDay(final OrderRealizationDay firstWorkingDay,
        final DateTime orderStartDateTime) {
    LocalDate orderStartDate = orderStartDateTime.toLocalDate();
    LocalTime orderStartTime = orderStartDateTime.toLocalTime();

    Optional<Shift> shiftStartingOrder = firstWorkingDay.findShiftWorkingAt(orderStartTime);
    Optional<TimeRange> workTimeRange = FluentOptional.wrap(shiftStartingOrder).flatMap(shift -> {
        int prevDayOfWeek = firstWorkingDay.getDate().minusDays(1).getDayOfWeek();
        return shift.findWorkTimeAt(prevDayOfWeek, orderStartTime);
    }).toOpt();/*ww w  .  j  av a 2s. c o  m*/

    if (shiftWorkTimeMatchPredicate(shiftStartingOrder, workTimeRange, startsDayBefore(orderStartTime))) {
        return Optional.of(new OrderRealizationDay(orderStartDate,
                firstWorkingDay.getRealizationDayNumber() - 1, Lists.newArrayList(shiftStartingOrder.asSet())));
    }
    if (shiftWorkTimeMatchPredicate(shiftStartingOrder, workTimeRange, endsNextDay(orderStartTime))) {
        return Optional.of(new OrderRealizationDay(firstWorkingDay.getDate(),
                firstWorkingDay.getRealizationDayNumber(), Lists.newArrayList(shiftStartingOrder.asSet())));
    }
    return Optional.absent();
}

From source file:com.sonicle.webtop.calendar.CalendarManager.java

License:Open Source License

public LinkedHashSet<String> calculateAvailabilitySpans(int minRange, UserProfileId pid, DateTime fromDate,
        DateTime toDate, DateTimeZone userTz, boolean busy) throws WTException {
    CalendarDAO calDao = CalendarDAO.getInstance();
    EventDAO evtDao = EventDAO.getInstance();
    LinkedHashSet<String> hours = new LinkedHashSet<>();
    Connection con = null;//from   w  w w  . j a  v a 2s . c  o m

    //TODO: review this method

    try {
        con = WT.getConnection(SERVICE_ID);

        // Lists desired calendars by profile
        final List<VVEventInstance> veis = new ArrayList<>();
        for (OCalendar ocal : calDao.selectByProfile(con, pid.getDomainId(), pid.getUserId())) {
            for (VVEvent ve : evtDao.viewByCalendarRangeCondition(con, ocal.getCalendarId(), fromDate, toDate,
                    null)) {
                veis.add(new VVEventInstance(ve));
            }
            for (VVEvent ve : evtDao.viewRecurringByCalendarRangeCondition(con, ocal.getCalendarId(), fromDate,
                    toDate, null)) {
                veis.add(new VVEventInstance(ve));
            }
        }

        DateTime startDt, endDt;
        for (VVEventInstance vei : veis) {
            if (vei.getBusy() != busy)
                continue; // Ignore events that are not marked as busy!

            if (vei.getRecurrenceId() == null) {
                startDt = vei.getStartDate().withZone(userTz);
                endDt = vei.getEndDate().withZone(userTz);
                hours.addAll(generateTimeSpans(minRange, startDt.toLocalDate(), endDt.toLocalDate(),
                        startDt.toLocalTime(), endDt.toLocalTime(), userTz));
            } else {
                final List<VVEventInstance> instances = calculateRecurringInstances(con,
                        new VVEventInstanceMapper(vei), fromDate, toDate, userTz);
                for (VVEventInstance instance : instances) {
                    startDt = instance.getStartDate().withZone(userTz);
                    endDt = instance.getEndDate().withZone(userTz);
                    hours.addAll(generateTimeSpans(minRange, startDt.toLocalDate(), endDt.toLocalDate(),
                            startDt.toLocalTime(), endDt.toLocalTime(), userTz));
                }
            }
        }

    } catch (SQLException | DAOException ex) {
        throw wrapException(ex);
    } finally {
        DbUtils.closeQuietly(con);
    }
    return hours;
}

From source file:com.sonicle.webtop.calendar.Service.java

License:Open Source License

public void processGetPlanning(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
    CoreUserSettings cus = getEnv().getCoreUserSettings();
    CoreManager core = WT.getCoreManager();
    ArrayList<MapItem> items = new ArrayList<>();
    Connection con = null;/*from  w w  w  .  ja  va 2  s . c  o m*/

    try {
        String eventStartDate = ServletUtils.getStringParameter(request, "startDate", true);
        String eventEndDate = ServletUtils.getStringParameter(request, "endDate", true);
        String timezone = ServletUtils.getStringParameter(request, "timezone", true);
        JsEvent.Attendee.List attendees = ServletUtils.getObjectParameter(request, "attendees",
                new JsEvent.Attendee.List(), JsEvent.Attendee.List.class);
        //JsAttendeeList attendees = ServletUtils.getObjectParameter(request, "attendees", new JsAttendeeList(), JsAttendeeList.class);

        // Parses string parameters
        DateTimeZone eventTz = DateTimeZone.forID(timezone);
        DateTime eventStartDt = DateTimeUtils.parseYmdHmsWithZone(eventStartDate, eventTz);
        DateTime eventEndDt = DateTimeUtils.parseYmdHmsWithZone(eventEndDate, eventTz);

        UserProfile up = getEnv().getProfile();
        DateTimeZone profileTz = up.getTimeZone();

        LocalTime localStartTime = eventStartDt.toLocalTime();
        LocalTime localEndTime = eventEndDt.toLocalTime();
        LocalTime fromTime = DateTimeUtils.min(localStartTime, us.getWorkdayStart());
        LocalTime toTime = DateTimeUtils.max(localEndTime, us.getWorkdayEnd());

        // Defines useful date/time formatters
        DateTimeFormatter ymdhmFmt = DateTimeUtils.createYmdHmFormatter();
        DateTimeFormatter tFmt = DateTimeUtils.createFormatter(cus.getShortTimeFormat());
        DateTimeFormatter dFmt = DateTimeUtils.createFormatter(cus.getShortDateFormat());

        ArrayList<String> spans = manager.generateTimeSpans(60, eventStartDt.toLocalDate(),
                eventEndDt.toLocalDate(), us.getWorkdayStart(), us.getWorkdayEnd(), profileTz);

        // Generates fields and columnsInfo dynamically
        ArrayList<FieldMeta> fields = new ArrayList<>();
        ArrayList<GridColumnMeta> colsInfo = new ArrayList<>();

        GridColumnMeta col = null;
        fields.add(new FieldMeta("recipient"));
        colsInfo.add(new GridColumnMeta("recipient"));
        for (String spanKey : spans) {
            LocalDateTime ldt = ymdhmFmt.parseLocalDateTime(spanKey);
            fields.add(new FieldMeta(spanKey));
            col = new GridColumnMeta(spanKey, tFmt.print(ldt));
            col.put("date", dFmt.print(ldt));
            col.put("overlaps", (ldt.compareTo(eventStartDt.toLocalDateTime()) >= 0)
                    && (ldt.compareTo(eventEndDt.toLocalDateTime()) < 0));
            colsInfo.add(col);
        }

        // Collects attendees availability...
        OUser user = null;
        UserProfileId profileId = null;
        LinkedHashSet<String> busyHours = null;
        MapItem item = null;
        for (JsEvent.Attendee attendee : attendees) {
            item = new MapItem();
            item.put("recipient", attendee.recipient);

            user = guessUserByAttendee(core, attendee.recipient);
            if (user != null) {
                profileId = new UserProfileId(user.getDomainId(), user.getUserId());
                busyHours = manager.calculateAvailabilitySpans(60, profileId, eventStartDt.withTime(fromTime),
                        eventEndDt.withTime(toTime), eventTz, true);
                for (String hourKey : spans) {
                    item.put(hourKey, busyHours.contains(hourKey) ? "busy" : "free");
                }
            } else {
                for (String spanKey : spans) {
                    item.put(spanKey, "unknown");
                }
            }
            items.add(item);
        }

        GridMetadata meta = new GridMetadata(true);
        meta.setFields(fields);
        meta.setColumnsInfo(colsInfo);
        new JsonResult(items, meta, items.size()).printTo(out);

    } catch (Exception ex) {
        logger.error("Error in GetPlanning", ex);
        new JsonResult(false, "Error").printTo(out);

    } finally {
        DbUtils.closeQuietly(con);
    }
}

From source file:divconq.scheduler.common.ScheduleList.java

License:Open Source License

public ScheduleEntry next(DateTime at) {
    LocalTime lt = at.toLocalTime();

    for (ScheduleEntry se : this.entries)
        if (se.getTime().isAfter(lt))
            return se;

    return null;// w ww. j  av a2s. co m
}

From source file:divconq.scheduler.limit.DayWindow.java

License:Open Source License

public LocalTime nextTimeOn(DateTime si) {
    // check that not completely excluded
    if (this.excludeAll())
        return null;

    int addMinutes = 1;
    LocalTime sil = si.toLocalTime();

    // start at the next minute
    int sidx = sil.getHourOfDay() * 60 + sil.getMinuteOfHour() + 1;

    // if any minute is open, return it
    for (int i = sidx; i < 1440; i++) {
        if (this.check(i) == CheckLimitResult.Pass)
            return sil.plusMinutes(addMinutes);

        addMinutes++;/*from   ww  w  . ja  va  2 s . c  o  m*/
    }

    // nothing open today
    return null;
}

From source file:divconq.scheduler.limit.DayWindow.java

License:Open Source License

public CheckLimitResult check(DateTime si) {
    if (this.excludeAll())
        return CheckLimitResult.Fail;

    LocalTime sil = si.toLocalTime();
    return this.check(sil.getHourOfDay() * 60 + sil.getMinuteOfHour());
}