List of usage examples for org.joda.time DateTime plusWeeks
public DateTime plusWeeks(int weeks)
From source file:com.sos.scheduler.model.objects.JSObjWeekdaysDay.java
License:Apache License
private RunTimeElements getNextSingleStarts(DateTime baseDate) { DateTimeFormatter fmtDate = DateTimeFormat.forPattern("yyyy-MM-dd"); DateTimeFormatter fmtDateTime = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); RunTimeElements result = new RunTimeElements(baseDate); logger.debug(getDay().size() + " day elements detected."); Iterator<String> it = getDay().iterator(); while (it.hasNext()) { String dayString = it.next(); logger.debug("parsing day string " + dayString); List<Integer> days = JodaTools.getJodaWeekdays(dayString); for (int i = 0; i < days.size(); i++) { DateTime nextWeekDay = JodaTools.getNextWeekday(baseDate, days.get(i)); logger.debug("calculated date " + fmtDate.print(nextWeekDay)); List<Period> periods = getPeriod(); Iterator<Period> itP = periods.iterator(); logger.debug(periods.size() + " periods found."); while (itP.hasNext()) { Period p = itP.next(); JSObjPeriod period = new JSObjPeriod(objFactory); period.setObjectFieldsFrom(p); DateTime start = period.getDtSingleStartOrNull(nextWeekDay); if (start != null) { logger.debug("start from period " + fmtDateTime.print(start)); if (start.isBefore(baseDate)) { start = start.plusWeeks(1); logger.debug("start is corrected to " + fmtDateTime.print(start)); }/*ww w . j a v a 2 s . c o m*/ result.add(new RunTimeElement(start, period.getWhenHoliday())); } } } // Collections.sort(result, DateTimeComparator.getInstance()); } return result; }
From source file:com.tremolosecurity.provisioning.tasks.Approval.java
License:Apache License
public Approval(WorkflowTaskType taskConfig, ConfigManager cfg, Workflow wf) throws ProvisioningException { super(taskConfig, cfg, wf); this.approvers = new ArrayList<Approver>(); this.azRules = new ArrayList<AzRule>(); this.failed = false; ApprovalType att = (ApprovalType) taskConfig; for (AzRuleType azr : att.getApprovers().getRule()) { Approver approver = new Approver(); if (azr.getScope().equalsIgnoreCase("filter")) { approver.type = ApproverType.Filter; } else if (azr.getScope().equalsIgnoreCase("group")) { approver.type = ApproverType.StaticGroup; } else if (azr.getScope().equalsIgnoreCase("dn")) { approver.type = ApproverType.DN; } else if (azr.getScope().equalsIgnoreCase("dynamicGroup")) { approver.type = ApproverType.DynamicGroup; } else if (azr.getScope().equalsIgnoreCase("custom")) { approver.type = ApproverType.Custom; }/*w w w . j av a 2 s . c o m*/ approver.constraint = azr.getConstraint(); setupCustomParameters(approver); this.approvers.add(approver); AzRule rule = new AzRule(azr.getScope(), azr.getConstraint(), azr.getClassName(), cfg, wf); this.azRules.add(rule); approver.customAz = rule.getCustomAuthorization(); } this.label = att.getLabel(); this.emailTemplate = att.getEmailTemplate(); this.mailAttr = att.getMailAttr(); this.failureEmailSubject = att.getFailureEmailSubject(); this.failureEmailMsg = att.getFailureEmailMsg(); this.escalationRules = new ArrayList<EscalationRule>(); if (att.getEscalationPolicy() != null) { DateTime now = new DateTime(); for (EscalationType ert : att.getEscalationPolicy().getEscalation()) { EscalationRule erule = new EsclationRuleImpl(); DateTime when; if (ert.getExecuteAfterUnits().equalsIgnoreCase("sec")) { when = now.plusSeconds(ert.getExecuteAfterTime()); } else if (ert.getExecuteAfterUnits().equals("min")) { when = now.plusMinutes(ert.getExecuteAfterTime()); } else if (ert.getExecuteAfterUnits().equals("hr")) { when = now.plusHours(ert.getExecuteAfterTime()); } else if (ert.getExecuteAfterUnits().equals("day")) { when = now.plusDays(ert.getExecuteAfterTime()); } else if (ert.getExecuteAfterUnits().equals("wk")) { when = now.plusWeeks(ert.getExecuteAfterTime()); } else { throw new ProvisioningException("Unknown time unit : " + ert.getExecuteAfterUnits()); } erule.setCompleted(false); erule.setExecuteTS(when.getMillis()); if (ert.getValidateEscalationClass() != null && !ert.getValidateEscalationClass().isEmpty()) { try { erule.setVerify( (VerifyEscalation) Class.forName(ert.getValidateEscalationClass()).newInstance()); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new ProvisioningException("Could not initialize escalation rule", e); } } else { erule.setVerify(null); } erule.setAzRules(new ArrayList<AzRule>()); for (AzRuleType azr : ert.getAzRules().getRule()) { Approver approver = new Approver(); if (azr.getScope().equalsIgnoreCase("filter")) { approver.type = ApproverType.Filter; } else if (azr.getScope().equalsIgnoreCase("group")) { approver.type = ApproverType.StaticGroup; } else if (azr.getScope().equalsIgnoreCase("dn")) { approver.type = ApproverType.DN; } else if (azr.getScope().equalsIgnoreCase("dynamicGroup")) { approver.type = ApproverType.DynamicGroup; } else if (azr.getScope().equalsIgnoreCase("custom")) { approver.type = ApproverType.Custom; } approver.constraint = azr.getConstraint(); setupCustomParameters(approver); //this.approvers.add(approver); AzRule rule = new AzRule(azr.getScope(), azr.getConstraint(), azr.getClassName(), cfg, wf); erule.getAzRules().add(rule); approver.customAz = rule.getCustomAuthorization(); } this.escalationRules.add(erule); now = when; } if (att.getEscalationPolicy().getEscalationFailure().getAction() != null) { switch (att.getEscalationPolicy().getEscalationFailure().getAction()) { case "leave": this.failureAzRules = null; this.failOnNoAZ = false; break; case "assign": this.failOnNoAZ = true; this.failureAzRules = new ArrayList<AzRule>(); for (AzRuleType azr : att.getEscalationPolicy().getEscalationFailure().getAzRules().getRule()) { Approver approver = new Approver(); if (azr.getScope().equalsIgnoreCase("filter")) { approver.type = ApproverType.Filter; } else if (azr.getScope().equalsIgnoreCase("group")) { approver.type = ApproverType.StaticGroup; } else if (azr.getScope().equalsIgnoreCase("dn")) { approver.type = ApproverType.DN; } else if (azr.getScope().equalsIgnoreCase("dynamicGroup")) { approver.type = ApproverType.DynamicGroup; } else if (azr.getScope().equalsIgnoreCase("custom")) { approver.type = ApproverType.Custom; } approver.constraint = azr.getConstraint(); setupCustomParameters(approver); //this.approvers.add(approver); AzRule rule = new AzRule(azr.getScope(), azr.getConstraint(), azr.getClassName(), cfg, wf); this.failureAzRules.add(rule); approver.customAz = rule.getCustomAuthorization(); } break; default: throw new ProvisioningException("Unknown escalation failure action : " + att.getEscalationPolicy().getEscalationFailure().getAction()); } } } }
From source file:com.vaushell.superpipes.nodes.buffer.Slot.java
License:Open Source License
/** * Return the time to wait to be in a slot and not to burst. * * @param date Actual date/* w w w.j a v a2 s . co m*/ * @return the time to wait */ public Duration getSmallestDiff(final DateTime date) { if (areWeInside(date)) { return new Duration(0L); } Duration smallest = null; for (final int dayOfWeek : daysOfWeek) { DateTime next = date.withDayOfWeek(dayOfWeek).withMillisOfDay(minMillisOfDay); if (next.isBefore(date)) { next = next.plusWeeks(1); } final Duration duration = new Duration(date, next); if (smallest == null || duration.isShorterThan(smallest)) { smallest = duration; } } return smallest; }
From source file:cron.DateTimes.java
License:Open Source License
public static DateTime nthOfMonth(DateTime t, int dayOfWeek, int desiredNumber) { int month = t.getMonthOfYear(); t = t.withDayOfMonth(1).withDayOfWeek(dayOfWeek); if (t.getMonthOfYear() != month) t = t.plusWeeks(1); int number = 1; while (number < desiredNumber && t.getMonthOfYear() == month) { number++;//from w ww. j a va2s . c o m t = t.plusWeeks(1); } return t; }
From source file:cron.DayOfWeekField.java
License:Open Source License
public boolean matches(DateTime time) { if (unspecified) return true; final int dayOfWeek = time.getDayOfWeek(); int number = number(dayOfWeek); if (hasLast) { return last.contains(number) && time.getMonthOfYear() != time.plusWeeks(1).getMonthOfYear(); } else if (hasNth) { for (int possibleMatch : nth.get(number)) { DateTime midnight = time.withTimeAtStartOfDay(); DateTime first = midnight.withDayOfMonth(1).withDayOfWeek(dayOfWeek); if (first.getMonthOfYear() != time.getMonthOfYear()) first = first.plusWeeks(1); DateTime tomorrow = midnight.plusDays(1); int weekNumber = 1 + (int) ((tomorrow.getMillis() - first.getMillis()) / MILLISECONDS_PER_WEEK); if (possibleMatch == weekNumber) return true; }//from w ww . j a v a2 s.c om } return contains(number); }
From source file:cron.Times.java
License:Open Source License
private void addDaysOfWeek(ImmutableSortedSet.Builder<DateTime> builder, DateTime base) { int month = base.getMonthOfYear(); Iterator<Integer> iterator = daysOfWeek.iterator(); base = base.withDayOfWeek(iterator.next()); if (base.getMonthOfYear() != month) base = base.plusWeeks(1); do {// w ww.j a v a2s. c om builder.add(base); base = base.plusWeeks(1); } while (base.getMonthOfYear() == month); }
From source file:edu.nyu.vida.data_polygamy.utils.FrameworkUtils.java
License:BSD License
public static int addTimeSteps(int tempRes, int increment, DateTime start) { DateTime d;//w w w . java 2 s. co m switch (tempRes) { case FrameworkUtils.HOUR: d = start.plusHours(increment); break; case FrameworkUtils.DAY: d = start.plusDays(increment); break; case FrameworkUtils.WEEK: d = start.plusWeeks(increment); break; case FrameworkUtils.MONTH: d = start.plusMonths(increment); break; case FrameworkUtils.YEAR: d = start.plusYears(increment); break; default: d = start.plusHours(increment); break; } return (int) (d.getMillis() / 1000); }
From source file:edu.nyu.vida.data_polygamy.utils.FrameworkUtils.java
License:BSD License
public static DateTime addTime(int tempRes, int increment, DateTime start) { DateTime d = null;//from w ww . ja va 2 s .c o m switch (tempRes) { case FrameworkUtils.HOUR: d = start.plusHours(increment); break; case FrameworkUtils.DAY: d = start.plusDays(increment); break; case FrameworkUtils.WEEK: d = start.plusWeeks(increment); break; case FrameworkUtils.MONTH: d = start.plusMonths(increment); break; case FrameworkUtils.YEAR: d = start.plusYears(increment); break; default: d = start.plusHours(increment); break; } return d; }
From source file:influent.server.dataaccess.DataAccessHelper.java
License:MIT License
public static DateTime getExclusiveEndDate(FL_DateRange date) { if (date == null) { return null; }/*from www . j av a 2 s . c o m*/ DateTime d = new DateTime((long) date.getStartDate(), DateTimeZone.UTC); switch (date.getDurationPerBin().getInterval()) { case SECONDS: return d.plusSeconds(date.getNumBins().intValue()); case HOURS: return d.plusHours(date.getNumBins().intValue()); case DAYS: return d.plusDays(date.getNumBins().intValue()); case WEEKS: return d.plusWeeks(date.getNumBins().intValue()); case MONTHS: return d.plusMonths(date.getNumBins().intValue()); case QUARTERS: return d.plusMonths(date.getNumBins().intValue() * 3); case YEARS: return d.plusYears(date.getNumBins().intValue()); } return d; }
From source file:io.renren.common.utils.DateUtils.java
License:Apache License
/** * ????//from w ww. j a v a 2 s.c om * @param week 0-1-212 * @return date[0]?date[1]? */ public static Date[] getWeekStartAndEnd(int week) { DateTime dateTime = new DateTime(); LocalDate date = new LocalDate(dateTime.plusWeeks(week)); date = date.dayOfWeek().withMinimumValue(); Date beginDate = date.toDate(); Date endDate = date.plusDays(6).toDate(); return new Date[] { beginDate, endDate }; }