List of usage examples for org.joda.time LocalDateTime minusDays
public LocalDateTime minusDays(int days)
From source file:com.axelor.apps.crm.service.batch.BatchEventReminder.java
License:Open Source License
private boolean isExpired(EventReminder eventReminder) { LocalDateTime startDateTime = eventReminder.getEvent().getStartDateTime(); int durationTypeSelect = eventReminder.getDurationTypeSelect(); switch (durationTypeSelect) { case IEventReminder.DURATION_MINUTES: if ((startDateTime.minusMinutes(eventReminder.getDuration())).isBefore(today)) { return true; }//w w w.j a v a 2 s . co m break; case IEventReminder.DURATION_HOURS: if ((startDateTime.minusHours(eventReminder.getDuration())).isBefore(today)) { return true; } break; case IEventReminder.DURATION_DAYS: if ((startDateTime.minusDays(eventReminder.getDuration())).isBefore(today)) { return true; } break; case IEventReminder.DURATION_WEEKS: if ((startDateTime.minusWeeks(eventReminder.getDuration())).isBefore(today)) { return true; } break; } return false; }
From source file:com.axelor.apps.crm.service.EventService.java
License:Open Source License
@Transactional public void addRecurrentEventsByMonths(Event event, int periodicity, int endType, int repetitionsNumber, LocalDate endDate, int monthRepeatType) { Event lastEvent = event;//from ww w . j a v a 2 s . co m if (monthRepeatType == 1) { int dayOfMonth = event.getStartDateTime().getDayOfMonth(); if (endType == 1) { int repeated = 0; while (repeated != repetitionsNumber) { Event copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); if (copy.getStartDateTime().plusMonths(periodicity).dayOfMonth() .getMaximumValue() >= dayOfMonth) { copy.setStartDateTime(copy.getStartDateTime().plusMonths(periodicity)); copy.setEndDateTime(copy.getEndDateTime().plusMonths(periodicity)); eventRepo.save(copy); repeated++; lastEvent = copy; } } } else { while (!lastEvent.getStartDateTime().plusMonths(periodicity).isAfter(endDate)) { Event copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); if (copy.getStartDateTime().plusMonths(periodicity).dayOfMonth() .getMaximumValue() >= dayOfMonth) { copy.setStartDateTime(copy.getStartDateTime().plusMonths(periodicity)); copy.setEndDateTime(copy.getEndDateTime().plusMonths(periodicity)); eventRepo.save(copy); lastEvent = copy; } } } } else { int dayOfWeek = event.getStartDateTime().getDayOfWeek(); int positionInMonth = 0; if (event.getStartDateTime().getDayOfMonth() % 7 == 0) { positionInMonth = event.getStartDateTime().getDayOfMonth() / 7; } else { positionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1; } if (endType == 1) { int repeated = 0; while (repeated != repetitionsNumber) { Event copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); LocalDateTime nextDateTime = new LocalDateTime(copy.getStartDateTime()); nextDateTime.plusMonths(periodicity); int nextDayOfWeek = nextDateTime.getDayOfWeek(); if (nextDayOfWeek > dayOfWeek) { nextDateTime.minusDays(nextDayOfWeek - dayOfWeek); } else { nextDateTime.plusDays(dayOfWeek - nextDayOfWeek); } int nextPositionInMonth = 0; if (event.getStartDateTime().getDayOfMonth() % 7 == 0) { nextPositionInMonth = event.getStartDateTime().getDayOfMonth() / 7; } else { nextPositionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1; } if (nextPositionInMonth > positionInMonth) { nextDateTime.minusWeeks(nextPositionInMonth - positionInMonth); } else { nextDateTime.plusWeeks(positionInMonth - nextPositionInMonth); } Duration dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime()); copy.setStartDateTime(nextDateTime); copy.setEndDateTime(nextDateTime.plus(dur)); eventRepo.save(copy); repeated++; lastEvent = copy; } } else { LocalDateTime nextDateTime = new LocalDateTime(lastEvent.getStartDateTime()); nextDateTime.plusMonths(periodicity); int nextDayOfWeek = nextDateTime.getDayOfWeek(); if (nextDayOfWeek > dayOfWeek) { nextDateTime.minusDays(nextDayOfWeek - dayOfWeek); } else { nextDateTime.plusDays(dayOfWeek - nextDayOfWeek); } int nextPositionInMonth = 0; if (event.getStartDateTime().getDayOfMonth() % 7 == 0) { nextPositionInMonth = event.getStartDateTime().getDayOfMonth() / 7; } else { nextPositionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1; } if (nextPositionInMonth > positionInMonth) { nextDateTime.minusWeeks(nextPositionInMonth - positionInMonth); } else { nextDateTime.plusWeeks(positionInMonth - nextPositionInMonth); } while (!nextDateTime.isAfter(endDate)) { Event copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); Duration dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime()); copy.setStartDateTime(nextDateTime); copy.setEndDateTime(nextDateTime.plus(dur)); eventRepo.save(copy); lastEvent = copy; nextDateTime = new LocalDateTime(lastEvent.getStartDateTime()); nextDateTime.plusMonths(periodicity); nextDayOfWeek = nextDateTime.getDayOfWeek(); if (nextDayOfWeek > dayOfWeek) { nextDateTime.minusDays(nextDayOfWeek - dayOfWeek); } else { nextDateTime.plusDays(dayOfWeek - nextDayOfWeek); } nextPositionInMonth = 0; if (event.getStartDateTime().getDayOfMonth() % 7 == 0) { nextPositionInMonth = event.getStartDateTime().getDayOfMonth() / 7; } else { nextPositionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1; } if (nextPositionInMonth > positionInMonth) { nextDateTime.minusWeeks(nextPositionInMonth - positionInMonth); } else { nextDateTime.plusWeeks(positionInMonth - nextPositionInMonth); } } } } }
From source file:com.axelor.csv.script.ImportDateTime.java
License:Open Source License
public LocalDateTime updateDay(LocalDateTime dateTime, String day) { if (!Strings.isNullOrEmpty(day)) { Matcher matcher = patternMonth.matcher(day); if (matcher.find()) { Integer days = Integer.parseInt(matcher.group()); if (day.startsWith("+")) dateTime = dateTime.plusDays(days); else if (day.startsWith("-")) dateTime = dateTime.minusDays(days); else/*from ww w . j av a 2 s .co m*/ dateTime = dateTime.withDayOfMonth(days); } } return dateTime; }
From source file:com.gs.fw.common.mithra.test.cacheloader.PYETopLevelLoaderFactory.java
License:Apache License
protected Timestamp shiftBusinessDate(Timestamp businessDate) { LocalDate localDate = new LocalDate(businessDate); int year = localDate.getYear(); LocalDateTime pye = new LocalDateTime(year - 1, 12, 31, 23, 59, 0, 0); int dayOfWeek = pye.dayOfWeek().get(); if (dayOfWeek > 5) { pye = pye.minusDays(dayOfWeek - 5); }/* w w w. j a v a 2 s. c o m*/ return new Timestamp(pye.toDateTime().getMillis()); }
From source file:com.ramzcalender.utils.CalUtil.java
License:Open Source License
/** * Initial calculation of the week//from w w w . j av a 2 s . c o m * * @param mStartDate */ public void calculate(LocalDateTime mStartDate, int type) { //Initializing Start with current month final LocalDateTime currentDateTime = mStartDate; setStartDate(currentDateTime.getYear(), currentDateTime.getMonthOfYear(), currentDateTime.getDayOfMonth()); /*Check for difference of weeks for alignment of days*/ int weekGap = CalUtil.mDateGap(currentDateTime.dayOfWeek().getAsText().substring(0, 3).toLowerCase()); if (weekGap != 0) { //If the there is week gap we need to maintain in the calender else alignment will be a mess if (type == RWeekCalendar.FDF_CALENDER) { //If the week gap is in FDF calender first get the current days number of the week int currentWeekNumber = new LocalDateTime().dayOfWeek().get(); //Subtract it with the rest of the days(Week gap) to get the rest of the days weekGap = weekGap - currentWeekNumber; } //This will add the additional days LocalDateTime ldt = mStartDate.minusDays(weekGap); // Set the the new startDate after new calculated days setStartDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth()); } else { //Some times the week gap will be zero in that case If the selected calender is FDFCalender if (type == RWeekCalendar.FDF_CALENDER) { //Subtract total days of week (7) with the week day number of current date int currentWeekNumber = 7 - new LocalDateTime().dayOfWeek().get(); if (currentWeekNumber != 0) { // Set the the new startDate after new calculated days LocalDateTime ldt = mStartDate.minusDays(currentWeekNumber); setStartDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth()); } } } }
From source file:com.sam.moca.server.expression.operators.arith.MinusExpression.java
License:Open Source License
protected MocaValue doOper(MocaValue left, MocaValue right) { if (left.getType() == MocaType.DATETIME) { if (right.getType() == MocaType.DOUBLE || right.getType() == MocaType.INTEGER) { Date d = left.asDate(); // If the left side is null, return a null result. if (d == null) { return new MocaValue(MocaType.DATETIME, null); }/* w ww . j a v a 2 s . c o m*/ LocalDateTime dt = new LocalDateTime(d); int wholeDays = right.asInt(); double dayPart = right.asDouble() - wholeDays; int msDiff = (int) (dayPart * 1000.0 * 3600.0 * 24.0); dt = dt.minusDays(wholeDays).minusMillis(msDiff); return new MocaValue(MocaType.DATETIME, dt.toDateTime().toDate()); } else if (right.getType() == MocaType.DATETIME) { Date leftDate = left.asDate(); Date rightDate = right.asDate(); // If either the left side or the right side is null, return null if (leftDate == null || rightDate == null) { return new MocaValue(MocaType.DOUBLE, null); } DateTime leftDt = new DateTime(leftDate); DateTime rightDt = new DateTime(rightDate); int fullDays = Days.daysBetween(rightDt, leftDt).getDays(); LocalTime leftTime = new LocalTime(leftDt); LocalTime rightTime = new LocalTime(rightDt); int ms = leftTime.getMillisOfDay() - rightTime.getMillisOfDay(); double partial = ((double) ms / (1000.0 * 3600.0 * 24.0)); if (partial < 0.0 && leftDate.after(rightDate)) { partial += 1.0; } else if (partial > 0.0 && rightDate.after(leftDate)) { partial -= 1.0; } double daysDiff = (double) fullDays + partial; return new MocaValue(MocaType.DOUBLE, daysDiff); } } else { if (left.getType() == MocaType.DOUBLE || right.getType() == MocaType.DOUBLE) { return new MocaValue(MocaType.DOUBLE, Double.valueOf(left.asDouble() - right.asDouble())); } else { return new MocaValue(MocaType.INTEGER, Integer.valueOf(left.asInt() - right.asInt())); } } return null; }
From source file:de.avanux.smartapplianceenabler.appliance.TimeOfDayOfWeek.java
License:Open Source License
public LocalDateTime toLastOccurrence(LocalDateTime now) { LocalDateTime dateTime = new LocalDateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), getHour(), getMinute(), getSecond()); while (dateTime.get(DateTimeFieldType.dayOfWeek()) != dayOfWeek) { dateTime = dateTime.minusDays(1); }/*from ww w . j a v a 2 s . c o m*/ return dateTime; }
From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.SemLeidmiseAbimeetodid.java
License:Open Source License
/** * Leiab <tt>currentDateTime</tt> granulaarsuse <tt>superField</tt> * <i>n</i>-inda alamosa, mis vastab tingimustele <tt>subField == soughtValueOfSubField</tt>. * <p>//from w w w.j a v a 2s. c om * Negatiivsete <i>n</i> vaartuste korral voetakse alamosa "tagantpoolt": vaartus * <i>n</i> == -1 tahistab <i>viimast</i>, <i>n</i> == -2 tahistab <i>eelviimast</i> * jne alamosa. * <p> * Praegu on defineeritud ainult <i>kuu n-inda nadalapaeva leidmise</i> operatsioon ( * <tt>superField == MONTH</tt>, <tt>subField == DAY_OF_WEEK</tt>, <tt>soughtValueOfSubField == a weekdayname</tt> ). */ public static LocalDateTime findNthSubpartOfGranularity(Granulaarsus superField, Granulaarsus subField, int soughtValueOfSubField, int n, LocalDateTime currentDateTime) { if (superField == Granulaarsus.MONTH) { // -------------------------------------- // Kuu n-inda nadalapaeva leidmine ... // -------------------------------------- if (subField == Granulaarsus.DAY_OF_WEEK && DateTimeConstants.MONDAY <= soughtValueOfSubField && soughtValueOfSubField <= DateTimeConstants.SUNDAY) { if (n > 0) { // // Algoritm: // http://msdn.microsoft.com/en-us/library/aa227532(VS.60).aspx // // Kerime kaesoleva kuu esimese kuupaeva peale ... LocalDateTime newDate = currentDateTime.withDayOfMonth(1); // Leiame esimese otsitud nadalapaeva while (newDate.getDayOfWeek() != soughtValueOfSubField) { newDate = newDate.plusDays(1); } int currentMonth = newDate.getMonthOfYear(); newDate = newDate.plusDays((n - 1) * 7); if (currentMonth == newDate.getMonthOfYear()) { // Kui kuu j2i kindlalt samaks, tagastame leitud nadalapaeva return newDate; } } else if (n < 0) { // Negatiivsete vaartuste korral otsime lahendust lopust: // Kerime kuu viimase vaartuse peale LocalDateTime newDate = currentDateTime .withDayOfMonth(currentDateTime.dayOfMonth().getMaximumValue()); // Leiame viimase otsitud nadalapaeva while (newDate.getDayOfWeek() != soughtValueOfSubField) { newDate = newDate.minusDays(1); } int currentMonth = newDate.getMonthOfYear(); newDate = newDate.minusDays(((n * (-1)) - 1) * 7); if (currentMonth == newDate.getMonthOfYear()) { // Kui kuu j2i kindlalt samaks, tagastame leitud nadalapaeva return newDate; } } } // ------------------------------------------------- // Kuu n-inda ndala/ndalavahetuse leidmine ... // ------------------------------------------------- // ------------------------------------------------------------------- // Teeme eelduse, et kuu esimene ndal on ndal, mis sisaldab kuu // esimest nadalapaeva {soughtValueOfSubField}; // Ning analoogselt, kuu viimane ndal on ndal, mis sisaldab kuu // viimast nadalapaeva {soughtValueOfSubField}; // ------------------------------------------------------------------- if (subField == Granulaarsus.WEEK_OF_YEAR && DateTimeConstants.MONDAY <= soughtValueOfSubField && soughtValueOfSubField <= DateTimeConstants.SUNDAY) { if (n > 0) { // Kerime kaesoleva kuu esimese paeva peale ... LocalDateTime newDate = currentDateTime.withDayOfMonth(1); // Leiame kuu esimese neljapaeva/laupaeva while (newDate.getDayOfWeek() != soughtValueOfSubField) { newDate = newDate.plusDays(1); } newDate = newDate.plusDays((n - 1) * 7); return newDate; } else if (n < 0) { // Negatiivsete vaartuste korral otsime lahendust lopust: // Kerime kuu viimase vaartuse peale LocalDateTime newDate = currentDateTime .withDayOfMonth(currentDateTime.dayOfMonth().getMaximumValue()); // Leiame viimase neljapaeva/laupaeva while (newDate.getDayOfWeek() != soughtValueOfSubField) { newDate = newDate.minusDays(1); } newDate = newDate.minusDays(((n * (-1)) - 1) * 7); return newDate; } } } return null; }
From source file:energy.usef.dso.workflow.operate.DsoOperateCoordinator.java
License:Apache License
private PtuContainer fetchPreviousPtuContainer(LocalDateTime ptuDate, Integer ptuIndex) { PtuContainer previousPtuContainer;//from w w w . j a v a2 s. c o m int previousPtuIndex = ptuIndex - 1; if (previousPtuIndex < 1) { int amountOfPtus = MINUTES_PER_DAY / config.getIntegerProperty(ConfigParam.PTU_DURATION); previousPtuContainer = dsoPlanboardBusinessService.findPtuContainer(ptuDate.minusDays(1).toLocalDate(), previousPtuIndex + amountOfPtus); } else { previousPtuContainer = dsoPlanboardBusinessService.findPtuContainer(ptuDate.toLocalDate(), previousPtuIndex); } return previousPtuContainer; }
From source file:org.apache.isis.viewer.wicket.ui.components.scalars.jodatime.DateConverterForJodaLocalDateTime.java
License:Apache License
@Override protected LocalDateTime doConvertToObject(String value, Locale locale) { LocalDateTime dateTime = convert(value); LocalDateTime adjustedDateTime = dateTime.minusDays(adjustBy); return adjustedDateTime; }