List of usage examples for org.joda.time LocalDateTime plusDays
public LocalDateTime plusDays(int days)
From source file:at.wada811.dayscounter.view.appwidget.CounterAppWidgetProvider.java
License:Apache License
@TargetApi(Build.VERSION_CODES.KITKAT) public static void setDateChangeAlarm(Context context) { Intent intent = new Intent(DateTimeChangeReceiver.ACTION_DATE_CHANGED); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); LocalDateTime today = new LocalDateTime(); LocalDateTime tomorrow = today.plusDays(1); alarmManager.cancel(pendingIntent);//from w w w .j a v a 2 s.co m if (AndroidUtils.isLessThanBuildVersion(Build.VERSION_CODES.KITKAT)) { alarmManager.set(AlarmManager.RTC, tomorrow.toDateTime().getMillis(), pendingIntent); } else { alarmManager.setExact(AlarmManager.RTC, tomorrow.toDateTime().getMillis(), pendingIntent); } }
From source file:com.axelor.apps.crm.service.EventService.java
License:Open Source License
@Transactional public void addRecurrentEventsByWeeks(Event event, int periodicity, int endType, int repetitionsNumber, LocalDate endDate, Map<Integer, Boolean> daysCheckedMap) { Event lastEvent = event;/*w ww . j a v a 2 s . c om*/ List<Integer> list = new ArrayList<Integer>(); for (int day : daysCheckedMap.keySet()) { list.add(day); } Collections.sort(list); if (endType == 1) { int repeated = 0; Event copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); int dayOfWeek = copy.getStartDateTime().getDayOfWeek(); LocalDateTime nextDateTime = new LocalDateTime(); if (dayOfWeek < list.get(0)) { nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays(list.get(0) - dayOfWeek)); } else if (dayOfWeek > list.get(0)) { nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays((7 - dayOfWeek) + list.get(0))); } Duration dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime()); for (Integer integer : list) { nextDateTime.plusDays(integer - nextDateTime.getDayOfWeek()); copy.setStartDateTime(nextDateTime); copy.setEndDateTime(nextDateTime.plus(dur)); eventRepo.save(copy); lastEvent = copy; repeated++; } while (repeated < repetitionsNumber) { copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); copy.setStartDateTime(copy.getStartDateTime().plusWeeks(periodicity)); copy.setEndDateTime(copy.getEndDateTime().plusWeeks(periodicity)); dayOfWeek = copy.getStartDateTime().getDayOfWeek(); nextDateTime = new LocalDateTime(); if (dayOfWeek < list.get(0)) { nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays(list.get(0) - dayOfWeek)); } else if (dayOfWeek > list.get(0)) { nextDateTime = new LocalDateTime( copy.getStartDateTime().plusDays((7 - dayOfWeek) + list.get(0))); } dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime()); for (Integer integer : list) { nextDateTime.plusDays(integer - nextDateTime.getDayOfWeek()); copy.setStartDateTime(nextDateTime); copy.setEndDateTime(nextDateTime.plus(dur)); eventRepo.save(copy); lastEvent = copy; repeated++; } } } else { Event copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); int dayOfWeek = copy.getStartDateTime().getDayOfWeek(); LocalDateTime nextDateTime = new LocalDateTime(); if (dayOfWeek < list.get(0)) { nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays(list.get(0) - dayOfWeek)); } else if (dayOfWeek > list.get(0)) { nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays((7 - dayOfWeek) + list.get(0))); } Duration dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime()); for (Integer integer : list) { nextDateTime.plusDays(integer - nextDateTime.getDayOfWeek()); copy.setStartDateTime(nextDateTime); copy.setEndDateTime(nextDateTime.plus(dur)); eventRepo.save(copy); lastEvent = copy; } while (!copy.getStartDateTime().plusWeeks(periodicity).isAfter(endDate)) { copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); copy.setStartDateTime(copy.getStartDateTime().plusWeeks(periodicity)); copy.setEndDateTime(copy.getEndDateTime().plusWeeks(periodicity)); dayOfWeek = copy.getStartDateTime().getDayOfWeek(); nextDateTime = new LocalDateTime(); if (dayOfWeek < list.get(0)) { nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays(list.get(0) - dayOfWeek)); } else if (dayOfWeek > list.get(0)) { nextDateTime = new LocalDateTime( copy.getStartDateTime().plusDays((7 - dayOfWeek) + list.get(0))); } dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime()); for (Integer integer : list) { nextDateTime.plusDays(integer - nextDateTime.getDayOfWeek()); copy.setStartDateTime(nextDateTime); copy.setEndDateTime(nextDateTime.plus(dur)); eventRepo.save(copy); lastEvent = copy; } } } }
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;// w ww .j av a 2s . c o 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 w w w .j a va2 s . c o m dateTime = dateTime.withDayOfMonth(days); } } return dateTime; }
From source file:com.battlelancer.seriesguide.util.TimeTools.java
License:Apache License
/** * If the release time is within the hour past midnight (0:00 until 0:59) moves the date one day * into the future (currently US shows only). * * <p> This is based on late night shows being commonly listed as releasing the day before if * they air past midnight (e.g. "Monday night at 0:35" actually is Tuesday 0:35). * * <p>Example: https://thetvdb.com/?tab=series&id=292421 * * <p>See also: https://forums.thetvdb.com/viewtopic.php?t=22791 *//*from w w w . ja v a2 s . c om*/ private static LocalDateTime handleHourPastMidnight(@Nullable String country, LocalDateTime localDateTime) { // Example: if (ISO3166_1_UNITED_STATES.equals(country) && localDateTime.getHourOfDay() == 0) { return localDateTime.plusDays(1); } return localDateTime; }
From source file:com.effektif.workflow.api.model.AfterRelativeTime.java
License:Apache License
public LocalDateTime resolve(LocalDateTime base) { if (this.duration == null || this.durationUnit == null) { return null; }/*from w ww. j a v a2s . c om*/ ReadablePeriod period = null; if (DAYS.equals(durationUnit)) { period = Days.days(getDurationAsInt()); } else if (WEEKS.equals(durationUnit)) { period = Weeks.weeks(getDurationAsInt()); } else if (HOURS.equals(durationUnit)) { period = Hours.hours(getDurationAsInt()); } else if (MONTHS.equals(durationUnit)) { period = Months.months(getDurationAsInt()); } else if (YEARS.equals(durationUnit)) { period = Years.years(getDurationAsInt()); } else if (MINUTES.equals(durationUnit)) { period = Minutes.minutes(getDurationAsInt()); } else { return null; } LocalDateTime time = base.plus(period); if (atHour != null) { LocalDateTime atTime = time.withTime(atHour, atMinute != null ? atMinute : 0, 0, 0); if (atTime.isBefore(time)) { time = atTime.plusDays(1); } else { time = atTime; } } else if (isDayResolutionOrBigger()) { time = time.withTime(23, 59, 59, 999); } return time; }
From source file:com.effektif.workflow.api.model.NextRelativeTime.java
License:Apache License
@Override public LocalDateTime resolve(LocalDateTime base) { LocalDateTime time = null; if (HOUR_OF_DAY.equals(indexUnit)) { time = base.withTime(index, 0, 0, 0); if (!time.isAfter(base)) { return time.plusDays(1); }/*from w w w.j a va2s . co m*/ } else if (DAY_OF_WEEK.equals(indexUnit)) { time = base.withDayOfWeek(index).withTime(0, 0, 0, 0); if (!time.isAfter(base)) { time = time.plusWeeks(1); } } else if (DAY_OF_MONTH.equals(indexUnit)) { time = base.withDayOfMonth(index).withTime(0, 0, 0, 0); if (!time.isAfter(base)) { time = time.plusMonths(1); } } if (atHour != null) { time = time.withTime(atHour, atMinute != null ? atMinute : 0, 0, 0); } return time; }
From source file:com.ephemeraldreams.gallyshuttle.ui.MainFragment.java
License:Apache License
/** * Calculate time difference in milliseconds between now and next available shuttle arrival time. * * @param stationId Station id to get times from. * @return Duration between now and next arrival time in milliseconds. *//*from ww w .j a v a2 s .c o m*/ private long calculateTimeFromNowToNextArrivalAtStation(int stationId) { List<String> times = schedule.getTimes(stationId); LocalDateTime now = LocalDateTime.now(); arrivalTime = null; LocalDateTime stationTime; for (String time : times) { stationTime = DateUtils.parseToLocalDateTime(time); Timber.d(stationTime.toString()); //Workaround midnight exception case where station time was converted to midnight of current day instead of next day. if (stationTime.getHourOfDay() == 0 && now.getHourOfDay() != 0) { stationTime = stationTime.plusDays(1); } if (now.isBefore(stationTime)) { arrivalTime = stationTime; break; } } if (arrivalTime == null) { arrivalTimeTextView.setText(getString(R.string.arrival_not_available_message)); return -1; } else { arrivalTimeTextView.setText(String.format(getString(R.string.until_arrival_time_message), DateUtils.formatTime(arrivalTime))); Duration duration = new Duration(now.toDateTime(), arrivalTime.toDateTime()); long milliseconds = duration.getMillis(); Timber.d("Now: " + DateUtils.formatTime(now)); Timber.d("Arrival: " + DateUtils.formatTime(arrivalTime)); Timber.d("Time difference between now and arrival: " + DateUtils.convertMillisecondsToTime(milliseconds)); return milliseconds; } }
From source file:com.hamdikavak.humanmobility.modeling.RadiusOfGyration.java
License:Open Source License
/** * Calculates a list of progressing radius of gyration numbers based on time * unit given. Currently, day is supported. * /* ww w .jav a 2 s .co m*/ * @param traces * location traces of an individual * @param unit * spatial distance unit * @param timeUnit * time unit for radius of gyration calculation. Day is supported. * @return an array of calculated radius of gyration. * @throws TimeUnitNotSupportedException */ public double[] calculateRadiusOfGyrationOverTime(List<LocationTrace> traces, SpatialDistanceUnit unit, TimeUnit timeUnit) throws TimeUnitNotSupportedException { if (timeUnit != TimeUnit.DAYS) { throw new TimeUnitNotSupportedException(timeUnit + " is not supported. Please pass days as time unit."); } LocationTraceHelper traceHelper = new LocationTraceHelper(); List<LocationTrace> selectedTraces; LocalDateTime firstTraceTime = traces.get(0).getLocalTime().minusMinutes(1); LocalDateTime lastTraceTime = traces.get(traces.size() - 1).getLocalTime(); double[] rogResults; LocalDateTime curentEndDate; int numberOfDays = Days.daysBetween(firstTraceTime, lastTraceTime).getDays(); rogResults = new double[numberOfDays - 1]; for (int i = 1; i < numberOfDays; i++) { curentEndDate = firstTraceTime.plusDays(i).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); selectedTraces = traceHelper.selectBetweenDates(traces, firstTraceTime, curentEndDate); rogResults[i - 1] = calculateRadiusOfGyration(selectedTraces); } return rogResults; }
From source file:com.metinkale.prayerapp.vakit.times.Times.java
License:Apache License
@NonNull private LocalDateTime getTimeCal(@Nullable LocalDate date, int time) { if (date == null) { date = LocalDate.now();/*from w w w.j a va2 s. co m*/ } if ((time < 0) || (time > 5)) { while (time >= 6) { date = date.plusDays(1); time -= 6; } while (time <= -1) { date = date.minusDays(1); time += 6; } } LocalDateTime timeCal = date.toLocalDateTime(new LocalTime(getTime(date, time))); int h = timeCal.getHourOfDay(); if ((time >= 3) && (h < 5)) { timeCal = timeCal.plusDays(1); } return timeCal; }