Example usage for org.joda.time LocalTime plusMinutes

List of usage examples for org.joda.time LocalTime plusMinutes

Introduction

In this page you can find the example usage for org.joda.time LocalTime plusMinutes.

Prototype

public LocalTime plusMinutes(int minutes) 

Source Link

Document

Returns a copy of this time plus the specified number of minutes.

Usage

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.  j  a  va 2s .  c  om
    }

    // nothing open today
    return null;
}

From source file:dk.teachus.backend.domain.impl.PeriodImpl.java

License:Apache License

public boolean mayBook(LocalTime time) {
    boolean mayBook = false;

    if (isTimeValid(time)) {
        time = time.plusMinutes(lessonDuration);
        if (time.equals(endTime) || time.isBefore(endTime)) {
            mayBook = true;//from  w  w  w  . j  a va 2 s.  com
        }
    }

    return mayBook;
}

From source file:dk.teachus.frontend.components.calendar.CalendarPanel.java

License:Apache License

public CalendarPanel(String id, IModel<DateMidnight> weekDateModel) {
    super(id, weekDateModel);

    /*/*from w ww  .  j  a  v a 2 s.  co m*/
     * Navigation
     */
    Link<DateMidnight> previousWeekLink = new Link<DateMidnight>("previousWeek", weekDateModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setModelObject(getModelObject().minusWeeks(1));
        }
    };
    previousWeekLink.add(new Label("label", TeachUsSession.get().getString("CalendarPanelV2.previousWeek"))); //$NON-NLS-1$ //$NON-NLS-2$
    add(previousWeekLink);
    Link<DateMidnight> thisWeekLink = new Link<DateMidnight>("thisWeek", weekDateModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setModelObject(new DateMidnight());
        }
    };
    thisWeekLink.add(new Label("label", TeachUsSession.get().getString("CalendarPanelV2.thisWeek"))); //$NON-NLS-1$ //$NON-NLS-2$
    add(thisWeekLink);
    Link<DateMidnight> nextWeekLink = new Link<DateMidnight>("nextWeek", weekDateModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setModelObject(getModelObject().plusWeeks(1));
        }
    };
    nextWeekLink.add(new Label("label", TeachUsSession.get().getString("CalendarPanelV2.nextWeek"))); //$NON-NLS-1$ //$NON-NLS-2$
    add(nextWeekLink);

    /*
     * Calendar
     */
    IModel<List<DateMidnight>> daysModel = new LoadableDetachableModel<List<DateMidnight>>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected List<DateMidnight> load() {
            DateMidnight thisMonday = CalendarPanel.this.getModelObject()
                    .withDayOfWeek(DateTimeConstants.MONDAY);
            List<DateMidnight> days = new ArrayList<DateMidnight>();
            for (int i = 0; i < 7; i++) {
                days.add(thisMonday);
                thisMonday = thisMonday.plusDays(1);
            }
            return days;
        }
    };

    final IModel<List<LocalTime>> timesModel = new LoadableDetachableModel<List<LocalTime>>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected List<LocalTime> load() {
            int minutesDivider = 30;
            LocalTime localTime = getCalendarStartTime();
            final List<LocalTime> times = new ArrayList<LocalTime>();
            for (int i = 0; i < calculateNumberOfCalendarHours() * (60 / minutesDivider); i++) {
                times.add(localTime);
                localTime = localTime.plusMinutes(minutesDivider);
            }

            return times;
        }
    };

    // Headers
    add(new ListView<DateMidnight>("headers", daysModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<DateMidnight> item) {
            item.add(new Label("label", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return HEADER_FORMAT.withLocale(TeachUsSession.get().getLocale())
                            .print(item.getModelObject());
                }
            }).setRenderBodyOnly(true));
        }
    });

    // Body
    // Times
    add(new ListView<LocalTime>("times", timesModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<LocalTime> item) {
            Label label = new Label("label", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    if (item.getModelObject().getMinuteOfHour() == 0) {
                        return TIME_FORMAT.withLocale(TeachUsSession.get().getLocale())
                                .print(item.getModelObject());
                    } else {
                        return null;
                    }
                }
            });
            item.add(label);

            IModel<String> appendModel = new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    if (item.getModelObject().getMinuteOfHour() == 0) {
                        return "timehour"; //$NON-NLS-1$
                    } else {
                        return null;
                    }
                }
            };
            item.add(AttributeModifier.append("class", appendModel)); //$NON-NLS-1$
        }
    });

    // Days
    add(new ListView<DateMidnight>("days", daysModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<DateMidnight> dayItem) {
            // Times
            dayItem.add(new ListView<LocalTime>("times", timesModel) { //$NON-NLS-1$
                private static final long serialVersionUID = 1L;

                @Override
                protected void populateItem(final ListItem<LocalTime> item) {
                    IModel<String> appendModel = new AbstractReadOnlyModel<String>() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public String getObject() {
                            if (item.getModelObject().getMinuteOfHour() == 0) {
                                return "daytimehour"; //$NON-NLS-1$
                            } else {
                                return null;
                            }
                        }
                    };
                    item.add(AttributeModifier.append("class", appendModel)); //$NON-NLS-1$
                }
            });

            /*
             * Entries
             */
            dayItem.add(new ListView<TimeSlot<T>>("timeSlots", getTimeSlotModel(dayItem.getModelObject())) { //$NON-NLS-1$
                private static final long serialVersionUID = 1L;

                @Override
                protected void populateItem(final ListItem<TimeSlot<T>> timeSlotItem) {
                    timeSlotItem.setOutputMarkupId(true);

                    final LocalTime startTime = timeSlotItem.getModelObject().getStartTime();
                    final LocalTime endTime = timeSlotItem.getModelObject().getEndTime();
                    int dividerPixelHeight = 25;
                    double minutesPerDivider = calculateNumberOfCalendarHours() * 60
                            / timesModel.getObject().size();

                    // Calculate top/y (start time)
                    double minutesStart = startTime.getHourOfDay() * 60 + startTime.getMinuteOfHour();
                    minutesStart -= getCalendarStartTime().getHourOfDay() * 60
                            + getCalendarStartTime().getMinuteOfHour();
                    double pixelStart = minutesStart / minutesPerDivider;
                    long top = Math.round(pixelStart * dividerPixelHeight) - 1;

                    // Calculate height (end time)
                    final double minutesEnd = (endTime.getHourOfDay() * 60 + endTime.getMinuteOfHour())
                            - minutesStart - getCalendarStartTime().getHourOfDay() * 60
                            + getCalendarStartTime().getMinuteOfHour();
                    double pixelEnd = minutesEnd / minutesPerDivider;
                    long height = Math.round(pixelEnd * dividerPixelHeight) - 1;

                    timeSlotItem.add(AttributeModifier.replace("style", //$NON-NLS-1$
                            "left: 0; top: " + top + "px; height: " + height + "px;")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

                    // Time slot content
                    IModel<List<String>> timeSlotContentModel = new LoadableDetachableModel<List<String>>() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        protected List<String> load() {
                            return getTimeSlotContent(dayItem.getModelObject(), timeSlotItem.getModelObject(),
                                    timeSlotItem);
                        }
                    };

                    timeSlotItem.add(new ListView<String>("timeSlotContent", timeSlotContentModel) {
                        private static final long serialVersionUID = 1L;

                        @Override
                        protected void populateItem(ListItem<String> item) {
                            item.add(new Label("content", item.getModel()));
                            item.add(AttributeModifier.replace("title", item.getModel()));
                        }
                    });

                    // Details
                    final Component dayTimeLessonDetails = createTimeSlotDetailsComponent(
                            "dayTimeLessonDetails", timeSlotItem.getModelObject());
                    dayTimeLessonDetails.setOutputMarkupId(true);
                    timeSlotItem.add(dayTimeLessonDetails);
                    timeSlotItem.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public String getObject() {
                            if (dayTimeLessonDetails.isVisible()) {
                                return "popover-external";
                            }
                            return null;
                        }
                    }));
                    timeSlotItem.add(
                            AttributeModifier.replace("data-content-id", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$
                                private static final long serialVersionUID = 1L;

                                @Override
                                public String getObject() {
                                    if (dayTimeLessonDetails.isVisible()) {
                                        return "#" + dayTimeLessonDetails.getMarkupId(); //$NON-NLS-1$
                                    } else {
                                        return null;
                                    }
                                }
                            }));
                }
            });
        }
    });
}

From source file:es.usc.citius.servando.calendula.database.RoutineDao.java

License:Open Source License

public List<Routine> findInHour(int hour) {
    try {//from   www.  j a  v  a2 s.  c o  m
        LocalTime time = new LocalTime(hour, 0);
        // get one hour interval [h:00, h:59:]
        String start = time.toString("kk:mm");
        String end = time.plusMinutes(59).toString("kk:mm");

        LocalTime endTime = time.plusMinutes(59);

        return queryBuilder().where().between(Routine.COLUMN_TIME, time, endTime).query();
    } catch (Exception e) {
        Log.e(TAG, "Error in findInHour", e);
        throw new RuntimeException(e);
    }
}

From source file:hydrometeo_analysis.TidesAndTimeManager.java

private static String createStringSQL_T(float HInterval, float i, LocalTime T) {
    //i = i - HInterval;
    int aux = (int) (60 * Math.abs(HInterval));
    int aux2 = (aux / 2) - 1;
    if (HInterval == 0.25)
        aux2 = aux2 + 1;//from   w w  w.j a  v a 2 s  .  c  om
    aux2 += aux * i;
    LocalTime endT = T.plusMinutes(aux2);
    String h = Integer.toString(endT.getHourOfDay());
    String m = Integer.toString(endT.getMinuteOfHour());
    if (h.length() == 1)
        h = "0" + h;
    if (m.length() == 1)
        m = "0" + m;
    String endTime = "'" + h + ":" + m + ":00" + "'";
    LocalTime startT = T.plusMinutes((aux2 + 1) - aux);
    h = Integer.toString(startT.getHourOfDay());
    m = Integer.toString(startT.getMinuteOfHour());
    if (h.length() == 1)
        h = "0" + h;
    if (m.length() == 1)
        m = "0" + m;
    String startTime = "'" + h + ":" + m + ":00" + "'";

    if (i >= 0 && !T.isBefore(endT)) {
        endTime = "'23:59:59'";
        int minutes = Minutes.minutesBetween(startT, createLocalTime("23:59:59")).getMinutes();
        if (minutes > 60 * Math.abs(HInterval))
            startTime = "'23:59:59'";
    } else if (i <= 0 && T.isBefore(startT)) {
        startTime = "'00:00:00'";
        int minutes = Minutes.minutesBetween(createLocalTime("00:00:00"), endT).getMinutes();
        if (minutes > 60 * Math.abs(HInterval))
            endTime = "'00:00:00'";
    }

    return "`time` BETWEEN " + "time(" + startTime + ")" + " AND " + "time(" + endTime + ")";
}

From source file:io.jawg.osmcontributor.ui.adapters.parser.OpeningHoursValueParser.java

License:Open Source License

public void fromSingleValue(String value, List<OpeningHours> openingHoursList) {
    // TODO: 19/07/16 We,Fr-Sa 10:45-19:15, Tu,Sa-Su 05:30-17:30, We 08:00-18:00
    OpeningHours openingHours = new OpeningHours();
    openingHours.setAllDaysActivated(false);

    String[] openingHoursValues = value.split(DAYS_SEP);
    String daysPart = null;//  w  w  w . j a  v a 2  s  .  com
    String hoursPart = null;

    if (value.equals("24/7")) {
        daysPart = "Mo-Su";
        hoursPart = "24:00-24:00";
    } else if (openingHoursValues.length == 2) {
        daysPart = openingHoursValues[0];
        hoursPart = openingHoursValues[1];
    } else if (openingHoursValues.length == 1) {
        hoursPart = openingHoursValues[0];
    }

    if (daysPart != null) {
        String[] dayPeriods = daysPart.split(RULE_SEP);
        for (String period : dayPeriods) {
            if (isPeriod(period)) {
                OpeningHours.Days[] d = OpeningHours.Days.fromDatas(period.split(RANGE_SEP));
                for (int i = d[0].ordinal(); i <= d[1].ordinal(); i++) {
                    openingHours.setDayActivated(i, true);
                }
            } else {
                openingHours.setDayActivated(OpeningHours.Days.fromData(period).ordinal(), true);
            }
        }
    }

    if (hoursPart != null) {
        String[] hours = hoursPart.split(",");
        if (hours.length > 1) {
            for (String hour : hours) {
                value = daysPart + " " + hour;
                fromSingleValue(value, openingHoursList);
            }
        } else {
            String[] hourPeriod = hoursPart.split(RANGE_SEP);
            LocalTime from = TIME_FORMATTER.parseLocalTime(hourPeriod[0]);
            if (hourPeriod.length > 1) {
                LocalTime to = TIME_FORMATTER.parseLocalTime(hourPeriod[1]);
                openingHours.setToTime(to);
            } else {
                openingHours.setToTime(from.plusMinutes(5));
            }
            openingHours.setFromTime(from);
            openingHoursList.add(openingHours);
        }
    }
    //return openingHours;
}

From source file:javaapplication5.NewJFrame.java

public static LocalTime increaseTime(LocalTime time, int h, int m) {
    time = time.plusHours(h);/*  w w w  .  j  a  v a 2 s  .co  m*/
    time = time.plusMinutes(m);
    return time;
}

From source file:org.apereo.portal.events.aggr.PortalEventDimensionPopulatorImpl.java

License:Apache License

/** Populate the time dimensions */
final void doPopulateTimeDimensions() {
    final List<TimeDimension> timeDimensions = this.timeDimensionDao.getTimeDimensions();
    if (timeDimensions.isEmpty()) {
        logger.info("No TimeDimensions exist, creating them");
    } else if (timeDimensions.size() != (24 * 60)) {
        this.logger.info(
                "There are only " + timeDimensions.size() + " time dimensions in the database, there should be "
                        + (24 * 60) + " creating missing dimensions");
    } else {// w w w.ja v  a 2  s . c  o  m
        this.logger.debug("Found expected " + timeDimensions.size() + " time dimensions");
        return;
    }

    LocalTime nextTime = new LocalTime(0, 0);
    final LocalTime lastTime = new LocalTime(23, 59);

    for (final TimeDimension timeDimension : timeDimensions) {
        LocalTime dimensionTime = timeDimension.getTime();
        if (nextTime.isBefore(dimensionTime)) {
            do {
                checkShutdown();
                this.timeDimensionDao.createTimeDimension(nextTime);
                nextTime = nextTime.plusMinutes(1);
            } while (nextTime.isBefore(dimensionTime));
        } else if (nextTime.isAfter(dimensionTime)) {
            do {
                checkShutdown();
                this.timeDimensionDao.createTimeDimension(dimensionTime);
                dimensionTime = dimensionTime.plusMinutes(1);
            } while (nextTime.isAfter(dimensionTime));
        }

        nextTime = dimensionTime.plusMinutes(1);
    }

    //Add any missing times from the tail
    while (nextTime.isBefore(lastTime) || nextTime.equals(lastTime)) {
        checkShutdown();
        this.timeDimensionDao.createTimeDimension(nextTime);
        if (nextTime.equals(lastTime)) {
            break;
        }
        nextTime = nextTime.plusMinutes(1);
    }
}

From source file:org.freewheelschedule.freewheel.common.util.DatabasePopulator.java

License:Apache License

@Transactional
public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-CommonUtil.xml");
    JobDao jobDao = (JobDao) ctx.getBean("jobDao");
    MachineDao machineDao = (MachineDao) ctx.getBean("machineDao");
    TriggerDao triggerDao = (TriggerDao) ctx.getBean("triggerDao");

    Machine machine = new Machine();
    machine.setName("localhost");
    machine.setPort(12145L);/*  www. j a v  a  2 s.  co  m*/
    machineDao.create(machine);

    RepeatingTrigger trigger = new RepeatingTrigger();
    trigger.setTriggerInterval(50000L);
    triggerDao.create(trigger);

    CommandJob job = new CommandJob();
    List<Trigger> triggers = new ArrayList<Trigger>();
    triggers.add(trigger);

    job.setName("Test Job");
    job.setCommand("java -version");
    job.setStderr("stderr.log");
    job.setStdout("stdout.log");
    job.setAppendStderr(true);
    job.setExecutingServer(machine);
    job.setTriggers(triggers);

    jobDao.create(job);

    trigger.setJob(job);
    triggerDao.create(trigger);

    TimedTrigger timedTrigger = new TimedTrigger();
    LocalTime triggerTime = new LocalTime();
    timedTrigger.setTriggerTime(triggerTime.plusMinutes(5));
    timedTrigger.setDaysOfWeek(127);
    triggerDao.create(timedTrigger);

    List<Trigger> timedTriggers = new ArrayList<Trigger>();
    timedTriggers.add(timedTrigger);

    CommandJob job2 = new CommandJob();

    job2.setName("Test Job2");
    job2.setCommand("java -version");
    job2.setStderr("stderr.log");
    job2.setStdout("stdout.log");
    job2.setAppendStderr(true);
    job2.setExecutingServer(machine);
    job2.setTriggers(timedTriggers);
    jobDao.create(job2);

    timedTrigger.setJob(job2);
    triggerDao.create(timedTrigger);

    Job readJob = jobDao.readByName("Test Job");
    log.info("Record read: " + readJob);

    //        readJob = jobDao.readById(9999L);
    //        log.info("Record read: " + readJob);
    //
    List<Job> jobs = jobDao.read();
    for (Job job1 : jobs) {
        log.info("All jobs read: " + job1);
    }
}

From source file:org.jasig.portal.events.aggr.PortalEventAggregationManagerImpl.java

License:Apache License

/**
 * Populate the time dimensions //from ww  w. j av a 2s .  c o m
 */
void doPopulateTimeDimensions() {
    final List<TimeDimension> timeDimensions = this.timeDimensionDao.getTimeDimensions();
    if (timeDimensions.isEmpty()) {
        logger.info("No TimeDimensions exist, creating them");
    } else if (timeDimensions.size() != (24 * 60)) {
        this.logger.info(
                "There are only " + timeDimensions.size() + " time dimensions in the database, there should be "
                        + (24 * 60) + " creating missing dimensions");
    } else {
        this.logger.debug("Found expected " + timeDimensions.size() + " time dimensions");
        return;
    }

    LocalTime nextTime = new LocalTime(0, 0);
    final LocalTime lastTime = new LocalTime(23, 59);

    for (final TimeDimension timeDimension : timeDimensions) {
        LocalTime dimensionTime = timeDimension.getTime();
        if (nextTime.isBefore(dimensionTime)) {
            do {
                this.timeDimensionDao.createTimeDimension(nextTime);
                nextTime = nextTime.plusMinutes(1);
            } while (nextTime.isBefore(dimensionTime));
        } else if (nextTime.isAfter(dimensionTime)) {
            do {
                this.timeDimensionDao.createTimeDimension(dimensionTime);
                dimensionTime = dimensionTime.plusMinutes(1);
            } while (nextTime.isAfter(dimensionTime));
        }

        nextTime = dimensionTime.plusMinutes(1);
    }

    //Add any missing times from the tail
    while (nextTime.isBefore(lastTime) || nextTime.equals(lastTime)) {
        this.timeDimensionDao.createTimeDimension(nextTime);
        if (nextTime.equals(lastTime)) {
            break;
        }
        nextTime = nextTime.plusMinutes(1);
    }
}