List of usage examples for org.joda.time DateTime withFields
public DateTime withFields(ReadablePartial partial)
From source file:azkaban.app.Scheduler.java
License:Apache License
/** * Schedule the given job to run at the next occurance of the partially * specified date, and repeating on the given period. For example if the * partial date is 12:00pm then the job will kick of the next time it is * 12:00pm// w w w .j a v a 2s . c o m * * @param jobId An id for the job * @param partial A description of the date to run on * @param period The period on which the job should repeat */ public ScheduledFuture<?> schedule(String jobId, ReadablePartial partial, ReadablePeriod period, boolean ignoreDep) { // compute the next occurrence of this date DateTime now = new DateTime(); DateTime date = now.withFields(partial); if (period != null) { date = updatedTime(date, period); } else if (now.isAfter(date)) { // Will try to schedule non recurring for tomorrow date = date.plusDays(1); } if (now.isAfter(date)) { // Schedule is non recurring. logger.info("Scheduled Job " + jobId + " was originally scheduled for " + _dateFormat.print(date)); return null; } logger.info("Scheduling job '" + jobId + "' for " + _dateFormat.print(date) + (period != null ? " with a period of " + PeriodFormat.getDefault().print(period) : "")); return schedule(new ScheduledJob(jobId, date, period, ignoreDep), true); }
From source file:org.fenixedu.spaces.domain.occupation.config.DailyConfig.java
License:Open Source License
@Override public List<Interval> getIntervals() { List<Interval> intervals = new ArrayList<>(); DateTime startDate = getInterval().getStart(); DateTime endDate = getInterval().getEnd(); DateTime start = startDate; while (start.isBefore(endDate) || start.isEqual(endDate)) { intervals.add(new Interval(start.withFields(getStartTime()), start.withFields(getEndTime()))); start = start.plusDays(getRepeatsEvery()); }/*from w w w. jav a2 s. co m*/ return intervals; }
From source file:org.fenixedu.spaces.domain.occupation.config.MonthlyConfig.java
License:Open Source License
private List<Interval> getDayOfWeekIntervals() { final List<Interval> intervals = new ArrayList<>(); DateTime startDate = getInterval().getStart(); int nthDayOfWeek = getNthDayOfWeek(startDate); int dayOfWeek = startDate.getDayOfWeek(); DateTime endDate = getInterval().getEnd(); DateTime start = startDate; while (start.isBefore(endDate) || start.isEqual(endDate)) { intervals.add(new Interval(start.withFields(getStartTime()), start.withFields(getEndTime()))); start = start.plusMonths(getRepeatsEvery()); start = getNextNthdayOfWeek(start, nthDayOfWeek, dayOfWeek); }/*from w ww . j a va 2 s.c o m*/ return intervals; }
From source file:org.fenixedu.spaces.domain.occupation.config.MonthlyConfig.java
License:Open Source License
private List<Interval> getDayOfMonthIntervals() { final List<Interval> intervals = new ArrayList<>(); DateTime startDate = getInterval().getStart(); DateTime endDate = getInterval().getEnd(); DateTime start = startDate; while (start.isBefore(endDate) || start.isEqual(endDate)) { intervals.add(new Interval(start.withFields(getStartTime()), start.withFields(getEndTime()))); start = start.plusMonths(getRepeatsEvery()); }//ww w . j a va 2 s . com return intervals; }
From source file:org.fenixedu.spaces.domain.occupation.config.WeeklyConfig.java
License:Open Source License
@Override public List<Interval> getIntervals() { final List<Interval> intervals = new ArrayList<>(); DateTime start = getInterval().getStart(); DateTime end = getInterval().getEnd(); // adjust start date to correct day of the week int firstDayOfWeekIndex = daysOfWeek.indexOf(start.getDayOfWeek()); if (firstDayOfWeekIndex == -1) { firstDayOfWeekIndex = 0;//from ww w . ja v a 2 s. c om } DateTime checkpoint = start.withDayOfWeek(daysOfWeek.get(firstDayOfWeekIndex)); if (checkpoint.isBefore(start)) { checkpoint.plusWeeks(1); } int i = firstDayOfWeekIndex; while (checkpoint.isBefore(end) || checkpoint.isEqual(end)) { intervals.add(new Interval(checkpoint.withFields(getStartTime()), checkpoint.withFields(getEndTime()))); if (i == daysOfWeek.size() - 1) { i = 0; checkpoint = checkpoint.plusWeeks(getRepeatsEvery()); } else { i++; } checkpoint = checkpoint.withDayOfWeek(daysOfWeek.get(i)); } return intervals; }
From source file:org.fenixedu.spaces.domain.occupation.config.YearlyConfig.java
License:Open Source License
@Override public List<Interval> getIntervals() { List<Interval> intervals = new ArrayList<>(); DateTime startDate = getInterval().getStart(); DateTime endDate = getInterval().getEnd(); DateTime start = startDate; while (start.isBefore(endDate) || start.isEqual(endDate)) { intervals.add(new Interval(start.withFields(getStartTime()), start.withFields(getEndTime()))); start = start.plusYears(getRepeatsEvery()); }/*from w w w.j av a 2 s. c om*/ return intervals; }