List of usage examples for org.joda.time DateTime plusWeeks
public DateTime plusWeeks(int weeks)
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;// w ww . ja v a 2 s .co m } 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.jimcat.gui.histogram.image.DateTakenDimension.java
License:Open Source License
/** * this methode will reload statistical information from the library * //ww w . j ava2 s . co m * @param library */ private void reloadValues(ImageLibrary library) { // get images List<Image> images = new ArrayList<Image>(library.getAll()); // 1) find min / max date int i = 0; DateTime min = null; DateTime max = null; while (min == null && i < images.size()) { min = getDateTaken(images.get(i)); max = min; i++; } if (min == null || max == null) { // result is an empty vector values = new int[RESOLUTION_COUNT][0]; maxValues = new int[RESOLUTION_COUNT]; minDate = null; fireStructureChangedEvent(); return; } // iterate through images for (; i < images.size(); i++) { Image img = images.get(i); DateTime date = getDateTaken(img); if (date != null && min.isAfter(date)) { min = date; } if (date != null && max.isBefore(date)) { max = date; } } // save min dates // get references // must be a pure day DateTime dayRef = new DateTime(2000, 1, 1, 0, 0, 0, 0); // must be a monday DateTime weekRef = new DateTime(2000, 1, 3, 0, 0, 0, 0); // must be the first of any month DateTime monthRef = dayRef; minDate = new DateTime[RESOLUTION_COUNT]; minDate[DAYS] = dayRef.plusDays(Days.daysBetween(dayRef, min).getDays()); minDate[WEEKS] = weekRef.plusWeeks(Weeks.weeksBetween(weekRef, min).getWeeks()); minDate[MONTHS] = monthRef.plusMonths(Months.monthsBetween(monthRef, min).getMonths()); // 2) build arrays values = new int[RESOLUTION_COUNT][]; values[DAYS] = new int[Days.daysBetween(minDate[DAYS], max).getDays() + 1]; values[WEEKS] = new int[Weeks.weeksBetween(minDate[WEEKS], max).getWeeks() + 1]; values[MONTHS] = new int[Months.monthsBetween(minDate[MONTHS], max).getMonths() + 1]; // 3) fill in values for (Image img : images) { // extract date DateTime date = getDateTaken(img); if (date != null) { values[DAYS][Days.daysBetween(minDate[DAYS], date).getDays()]++; values[WEEKS][Weeks.weeksBetween(minDate[WEEKS], date).getWeeks()]++; values[MONTHS][Months.monthsBetween(minDate[MONTHS], date).getMonths()]++; } } // 4) get max values maxValues = new int[RESOLUTION_COUNT]; for (int j = 0; j < RESOLUTION_COUNT; j++) { maxValues[j] = values[j][0]; for (int k = 1; k < values[j].length; k++) { if (maxValues[j] < values[j][k]) { maxValues[j] = values[j][k]; } } } // 6) notify listners fireStructureChangedEvent(); }
From source file:org.kairosdb.util.Util.java
License:Apache License
/** Computes the duration of the sampling (value * unit) starting at timestamp. /* w w w. j ava 2s.c o m*/ @param timestamp unix timestamp of the start time. @return the duration of the sampling in millisecond. */ public static long getSamplingDuration(long timestamp, Sampling sampling, DateTimeZone timeZone) { long ret = sampling.getValue(); DateTime dt = new DateTime(timestamp, timeZone); switch (sampling.getUnit()) { case YEARS: ret = new org.joda.time.Duration(dt, dt.plusYears((int) sampling.getValue())).getMillis(); break; case MONTHS: ret = new org.joda.time.Duration(dt, dt.plusMonths((int) sampling.getValue())).getMillis(); break; case WEEKS: ret = new org.joda.time.Duration(dt, dt.plusWeeks((int) sampling.getValue())).getMillis(); break; case DAYS: ret = new org.joda.time.Duration(dt, dt.plusDays((int) sampling.getValue())).getMillis(); break; case HOURS: ret = new org.joda.time.Duration(dt, dt.plusHours((int) sampling.getValue())).getMillis(); break; case MINUTES: ret = new org.joda.time.Duration(dt, dt.plusMinutes((int) sampling.getValue())).getMillis(); break; case SECONDS: ret = new org.joda.time.Duration(dt, dt.plusSeconds((int) sampling.getValue())).getMillis(); break; case MILLISECONDS: ret = (long) sampling.getValue(); break; } return ret; }
From source file:org.medcada.android.db.DatabaseHandler.java
License:Open Source License
public List<Integer> getAverageGlucoseReadingsByWeek() { JodaTimeAndroid.init(mContext);/*from w w w. j av a2 s . co m*/ DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime()); DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime()); DateTime currentDateTime = minDateTime; DateTime newDateTime = minDateTime; ArrayList<Integer> averageReadings = new ArrayList<Integer>(); // The number of weeks is at least 1 since we do have average for the current week even if incomplete int weeksNumber = Weeks.weeksBetween(minDateTime, maxDateTime).getWeeks() + 1; for (int i = 0; i < weeksNumber; i++) { newDateTime = currentDateTime.plusWeeks(1); RealmResults<GlucoseReading> readings = realm.where(GlucoseReading.class) .between("created", currentDateTime.toDate(), newDateTime.toDate()).findAll(); averageReadings.add(((int) readings.average("reading"))); currentDateTime = newDateTime; } return averageReadings; }
From source file:org.medcada.android.db.DatabaseHandler.java
License:Open Source License
public List<String> getGlucoseDatetimesByWeek() { JodaTimeAndroid.init(mContext);//from ww w .ja va 2 s.c o m DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime()); DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime()); DateTime currentDateTime = minDateTime; DateTime newDateTime = minDateTime; ArrayList<String> finalWeeks = new ArrayList<String>(); // The number of weeks is at least 1 since we do have average for the current week even if incomplete int weeksNumber = Weeks.weeksBetween(minDateTime, maxDateTime).getWeeks() + 1; DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); for (int i = 0; i < weeksNumber; i++) { newDateTime = currentDateTime.plusWeeks(1); finalWeeks.add(inputFormat.format(newDateTime.toDate())); currentDateTime = newDateTime; } return finalWeeks; }
From source file:org.mifos.calendar.CalendarUtils.java
License:Open Source License
public static DateTime nearestDayOfWeekTo(final int dayOfWeek, final DateTime date) { DateTime withDayOfWeek = date.withDayOfWeek(dayOfWeek); if (date.getYear() == withDayOfWeek.getYear()) { if (date.getDayOfYear() > withDayOfWeek.getDayOfYear()) { return withDayOfWeek.plusWeeks(1); }//ww w . j av a 2 s . c o m return withDayOfWeek; } // back a year if (date.getYear() > withDayOfWeek.getYear()) { return withDayOfWeek.plusWeeks(1); } return withDayOfWeek; }
From source file:org.mifos.calendar.DayOfWeek.java
License:Open Source License
public static DateTime oneWeekFrom(final DateTime lastScheduledDate) { return lastScheduledDate.plusWeeks(1); }
From source file:org.mifos.dmt.business.Meetings.schedule.MonthlyScheduleWithROD.java
License:Open Source License
protected void getMeetingStartDate() { sanitizeDays();//w w w . j a v a 2 s.c o m DateTime initialDate = this.createdDate; initialDate = initialDate.withDayOfMonth(1); initialDate = initialDate.plusWeeks((this.rankOfDays - 1)); initialDate = initialDate.withDayOfWeek(this.days); if (initialDate.isBefore(this.createdDate) || initialDate.isEqual(this.createdDate)) { initialDate = initialDate.plusMonths(1); initialDate = initialDate.withDayOfMonth(1); initialDate = initialDate.plusWeeks((this.rankOfDays - 1)); initialDate = initialDate.withDayOfWeek(this.days); } this.startDate = initialDate; }
From source file:org.mifos.dmt.business.Meetings.schedule.MonthlyScheduleWithROD.java
License:Open Source License
public void generateSchedule(int numberOfDates) { numberOfDates--;// www. j a va 2 s.c o m getMeetingStartDate(); fastForwardTillDisbursement(); DateTime meetingScheduleDate = this.startDate; Date meetingDateInMifosFormat; for (int i = 0; i <= numberOfDates; i++) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); meetingDateInMifosFormat = getWorkingDay(meetingScheduleDate).toDate(); this.scheduleList.add(formatter.format(meetingDateInMifosFormat)); meetingScheduleDate = meetingScheduleDate.plusMonths(this.recAfter); meetingScheduleDate = meetingScheduleDate.withDayOfMonth(1); meetingScheduleDate = meetingScheduleDate.plusWeeks((this.rankOfDays - 1)); meetingScheduleDate = meetingScheduleDate.withDayOfWeek(this.days); } }
From source file:org.mifos.dmt.business.Meetings.schedule.WeeklySchedule.java
License:Open Source License
protected void getMeetingStartDate() { sanitizeDays();/*from www .j a v a2s. c om*/ //generate start date DateTime initialDate = this.createdDate.withDayOfWeek(this.days); if (initialDate.isBefore(this.createdDate)) { initialDate = initialDate.plusWeeks(1); } this.startDate = initialDate; }