List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:elw.web.FormatTool.java
License:Open Source License
public String format(final long dateLong, String pattern, String patternWeek, String patternToday) { final DateTimeFormatter formatter = lookupFormatter(pattern); final DateTimeFormatter formatterToday = lookupFormatter(patternToday); final DateTimeFormatter formatterWeek = lookupFormatter(patternWeek); final DateTime now = new DateTime(System.currentTimeMillis()); final DateTime midnight = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0, 0, 0, 0);/*from w w w .j av a 2 s .co m*/ if (midnight.isBefore(dateLong) && midnight.plusDays(1).isAfter(dateLong)) { return formatterToday.print(dateLong); } else if (now.minusDays(7).isBefore(dateLong) && now.plusDays(7).isAfter(dateLong)) { return formatterWeek.print(dateLong); } else { return formatter.print(dateLong); } }
From source file:emhs.db.model.GBEntryBook.java
public ArrayList<String[]> getEntries() { ArrayList<String[]> entries = new ArrayList<>(); for (int i = guestSheet.getPhysicalNumberOfRows() - 1; i > 0; i--) { Row r = guestSheet.getRow(i);/*from w ww . java 2 s . c o m*/ if (isRowEmpty(r, 4) || !isRowSafe(r, new int[] { 0, 2, 3 })) continue; DateTime startOfToday = DateTime.now().withTimeAtStartOfDay(); DateTime entryTime = DateTimeFormat.forPattern("MMM d yyyy HH:mm:ss") .parseDateTime(r.getCell(3).getStringCellValue().replaceAll("(\\d{1,2})(?:st|nd|rd|th)", "$1")); DateTime returnTime = null; if (r.getCell(4) != null && r.getCell(4).getStringCellValue().trim().length() != 0) returnTime = DateTimeFormat.forPattern("MMM d yyyy HH:mm:ss").parseDateTime( r.getCell(4).getStringCellValue().replaceAll("(\\d{1,2})(?:st|nd|rd|th)", "$1")); if (!new Interval(startOfToday, startOfToday.plusDays(1)).contains(entryTime)) break; entries.add(new String[] { r.getCell(0).getStringCellValue(), "Guest", DateTimeFormat.forPattern("HH:mm").print(entryTime), i + "", r.getCell(1) == null ? "" : r.getCell(1).getStringCellValue(), r.getCell(2).getStringCellValue(), returnTime == null ? "" : DateTimeFormat.forPattern("HH:mm").print(returnTime) }); } for (int i = staffSheet.getPhysicalNumberOfRows() - 1; i > 0; i--) { Row r = staffSheet.getRow(i); if (isRowEmpty(r, 3) || !isRowSafe(r, new int[] { 0, 1, 2 })) continue; DateTime startOfToday = DateTime.now().withTimeAtStartOfDay(); DateTime entryTime = DateTimeFormat.forPattern("MMM d yyyy HH:mm:ss") .parseDateTime(r.getCell(2).getStringCellValue().replaceAll("(\\d{1,2})(?:st|nd|rd|th)", "$1")); DateTime returnTime = null; if (r.getCell(3) != null && r.getCell(3).getStringCellValue().trim().length() != 0) returnTime = DateTimeFormat.forPattern("MMM d yyyy HH:mm:ss").parseDateTime( r.getCell(3).getStringCellValue().replaceAll("(\\d{1,2})(?:st|nd|rd|th)", "$1")); if (!new Interval(startOfToday, startOfToday.plusDays(1)).contains(entryTime)) break; entries.add(new String[] { r.getCell(0).getStringCellValue(), "Staff", DateTimeFormat.forPattern("HH:mm").print(entryTime), i + "", r.getCell(1).getStringCellValue(), returnTime == null ? "" : DateTimeFormat.forPattern("HH:mm").print(returnTime) }); } for (int i = substituteSheet.getPhysicalNumberOfRows() - 1; i > 0; i--) { Row r = substituteSheet.getRow(i); if (isRowEmpty(r, 6) || !isRowSafe(r, new int[] { 0, 1, 2, 3, 4, 5 })) continue; DateTime startOfToday = DateTime.now().withTimeAtStartOfDay(); DateTime entryTime = DateTimeFormat.forPattern("MMM d yyyy HH:mm:ss") .parseDateTime(r.getCell(6).getStringCellValue().replaceAll("(\\d{1,2})(?:st|nd|rd|th)", "$1")); if (!new Interval(startOfToday, startOfToday.plusDays(1)).contains(entryTime)) break; entries.add(new String[] { r.getCell(0).getStringCellValue(), "Substitute", DateTimeFormat.forPattern("HH:mm").print(entryTime), i + "", r.getCell(1).getStringCellValue(), r.getCell(2).getStringCellValue(), r.getCell(3).getStringCellValue(), r.getCell(4).getStringCellValue(), r.getCell(5) == null ? "" : r.getCell(5).getStringCellValue() }); } return entries; }
From source file:es.jpons.temporal.types.PossibilisticVTP.java
License:Open Source License
/** * Constructor/*from ww w . j av a 2 s . c om*/ * * @param sday Starting day of month * @param smonth Starting month of year * @param syear Starting year * @param sLeftDays Number of days of the left starting margin. * @param sRightDays Number of days of the right starting margin. * @param eday Ending day of month. * @param emonth Ending month of year. * @param eyear Ending year. * @param eLeftDays Number of days of the ending margin. * @param eRightDays Number of days of the right ending margin. */ public PossibilisticVTP(Integer sday, Integer smonth, Integer syear, Integer sLeftDays, Integer sRightDays, Integer eday, Integer emonth, Integer eyear, Integer eLeftDays, Integer eRightDays) { DateTime dateStartingMainPoint, dateStartingLeft, dateStartingRight; DateTime dateEndingMainPoint, dateEndingLeft, dateEndingRight; dateStartingMainPoint = new DateTime(syear, smonth, sday, 0, 0); dateStartingLeft = dateStartingMainPoint.minusDays(sLeftDays); dateStartingRight = dateStartingMainPoint.plusDays(sRightDays); Duration d = new Duration(dateStartingLeft, dateStartingMainPoint); Duration d1 = new Duration(dateStartingMainPoint, dateStartingRight); dateEndingMainPoint = new DateTime(eyear, emonth, eday, 0, 0); dateEndingLeft = dateEndingMainPoint.minusDays(eLeftDays); dateEndingRight = dateEndingMainPoint.plusDays(eRightDays); Duration d2 = new Duration(dateEndingLeft, dateEndingMainPoint); Duration d3 = new Duration(dateEndingMainPoint, dateEndingRight); // PossibilisticTP start, end; PossibilisticVTP pvp; // // start = new PossibilisticTP( // dateStartingMainPoint.toDate(), // dateStartingLeft.toDate(), // dateStartingRight.toDate()); // end = new PossibilisticTP( // dateEndingMainPoint.toDate(), // dateEndingLeft.toDate(), // dateEndingRight.toDate()); //PossibilisticVTP(dateStartingMainPoint.toDate(),d.getMillis(),d1.getMillis(),dateEndingMainPoint.toDate(),d2.getMillis(),d3.getMillis()); this.startMP = dateStartingMainPoint.getMillis(); this.startLeft = d.getMillis(); this.startRight = d1.getMillis(); this.endMP = dateEndingMainPoint.getMillis(); this.endLeft = d2.getMillis(); this.endRight = d3.getMillis(); this.startDate = dateStartingMainPoint.toDate(); this.endDate = dateEndingMainPoint.toDate(); convertToTM(); }
From source file:es.jpons.temporal.types.PossibilisticVTP.java
License:Open Source License
public PossibilisticVTP(Integer day, Integer month, Integer year, Integer leftDays, Integer rightDays, OpenInterval side) {/* ww w. j a v a2 s. c o m*/ DateTime dateMainPoint, dateLeft, dateRight; dateMainPoint = new DateTime(year, month, day, 0, 0); dateLeft = dateMainPoint.minusDays(leftDays); dateRight = dateMainPoint.plusDays(rightDays); Duration d = new Duration(dateLeft, dateMainPoint); Duration d1 = new Duration(dateMainPoint, dateRight); switch (side) { case UC: this.startMP = dateMainPoint.getMillis(); this.startLeft = d.getMillis(); this.startRight = d1.getMillis(); this.startDate = dateMainPoint.toDate(); this.side = OpenInterval.UC; break; case FB: this.endMP = dateMainPoint.getMillis(); this.endLeft = d.getMillis(); this.endRight = d1.getMillis(); this.endDate = dateMainPoint.toDate(); this.side = OpenInterval.FB; break; } }
From source file:es.progmac.cuadrante.lib.CalendarAdapter.java
License:Apache License
public void refreshDays() { // clear items items.clear();/*ww w . java 2 s. c o m*/ pasObj = new Pas(mContext); int lastDay = month.getActualMaximum(Calendar.DAY_OF_MONTH); // MyLog.d(TAG, "lastDay: " + lastDay); int firstDay = (int) month.get(Calendar.DAY_OF_WEEK); // MyLog.d(TAG, "firstDay: " + firstDay); // obtenemos todos los servicios del mes List<ServicioInfo> servicios = db.getServicesInMonth(month.get(Calendar.YEAR), month.get(Calendar.MONTH) + 1); //obtenemos todas las comisiones del mes List<ComisionInfo> comisions = db.getComisionInMonth(month.get(Calendar.YEAR), month.get(Calendar.MONTH) + 1); /** * Numero de celdas del mes, contando con las iniciales del mes pasado */ int numDays; // figure size of the array if (firstDay == 1) { numDays = lastDay + (FIRST_DAY_OF_WEEK * 6); } else { numDays = lastDay + firstDay - (FIRST_DAY_OF_WEEK + 1); } days = new String[numDays]; daysWithServices = new ServicioInfo[numDays]; daysWithComisions = new ComisionInfo[numDays]; int j = FIRST_DAY_OF_WEEK; // populate empty days before first real day if (firstDay > 1) { for (j = 0; j < firstDay - FIRST_DAY_OF_WEEK; j++) { days[j] = ""; daysWithServices[j] = new ServicioInfo(); daysWithComisions[j] = new ComisionInfo(); // MyLog.d("firstDay > 1 j", "" + j); } } else { for (j = 0; j < FIRST_DAY_OF_WEEK * 6; j++) { days[j] = ""; daysWithServices[j] = new ServicioInfo(); daysWithComisions[j] = new ComisionInfo(); } j = FIRST_DAY_OF_WEEK * 6 + 1; // sunday => 1, monday => 7 } // populate days int dayNumber = 1; DateTime dateDay = new DateTime(month.get(Calendar.YEAR), month.get(Calendar.MONTH) + 1, dayNumber, 0, 0); for (int i = j - 1; i < days.length; i++) { daysWithServices[i] = new ServicioInfo(); for (ServicioInfo servicio : servicios) { if (servicio.getDay() == dayNumber) { daysWithServices[i] = servicio; break; } } daysWithComisions[i] = new ComisionInfo(); for (ComisionInfo comision : comisions) { if (comision.getInterval().contains(dateDay)) { daysWithComisions[i] = comision; break; } } dateDay = dateDay.plusDays(1); days[i] = "" + dayNumber; dayNumber++; } }
From source file:es.ugr.decsai.jpons.testapplication.Main.java
License:Open Source License
protected static PossibilisticVTP createVTP(Integer sday, Integer smonth, Integer syear, Integer eday, Integer emonth, Integer eyear) { DateTime dateStartingMainPoint, dateStartingLeft, dateStartingRight; DateTime dateEndingMainPoint, dateEndingLeft, dateEndingRight; dateStartingMainPoint = new DateTime(syear, smonth, sday, 0, 0); dateStartingLeft = dateStartingMainPoint.minusDays(3); dateStartingRight = dateStartingMainPoint.plusDays(3); Duration d = new Duration(dateStartingLeft, dateStartingMainPoint); Duration d1 = new Duration(dateStartingMainPoint, dateStartingRight); dateEndingMainPoint = new DateTime(eyear, emonth, eday, 0, 0); dateEndingLeft = dateEndingMainPoint.minusDays(3); dateEndingRight = dateEndingMainPoint.plusDays(3); Duration d2 = new Duration(dateEndingLeft, dateEndingMainPoint); Duration d3 = new Duration(dateEndingMainPoint, dateEndingRight); PossibilisticTP start, end;//w w w . j av a 2 s . c om PossibilisticVTP pvp; // start = new PossibilisticTP( // dateStartingMainPoint.toDate(), // dateStartingLeft.toDate(), // dateStartingRight.toDate()); // end = new PossibilisticTP( // dateEndingMainPoint.toDate(), // dateEndingLeft.toDate(), // dateEndingRight.toDate()); pvp = new PossibilisticVTP(dateStartingMainPoint.toDate(), d.getMillis(), d1.getMillis(), dateEndingMainPoint.toDate(), d2.getMillis(), d3.getMillis()); return pvp; }
From source file:es.usc.citius.servando.calendula.activities.SummaryCalendarActivity.java
License:Open Source License
private void setupCalendar() { calendar = (CalendarPickerView) findViewById(R.id.calendar_view); calendar.setVerticalScrollBarEnabled(false); RepetitionRule r;/* w ww .ja v a2 s. c om*/ String rule = getIntent().getStringExtra("rule"); String date = getIntent().getStringExtra("start"); int activeDays = getIntent().getIntExtra("active_days", -1); int restDays = getIntent().getIntExtra("rest_days", -1); LocalDate from = date != null ? LocalDate.parse(date, fmt) : LocalDate.now(); LocalDate to = from.plusMonths(6); if (rule != null) { r = new RepetitionRule(rule); List<DateTime> dates = r.occurrencesBetween(from.toDateTimeAtStartOfDay(), to.toDateTimeAtStartOfDay(), from.toDateTimeAtStartOfDay()); Set<Date> hdates = new HashSet<>(); for (DateTime d : dates) hdates.add(d.toDate()); List<CalendarCellDecorator> decorators = new ArrayList<>(); DateValue v = r.iCalRule().getUntil(); Date start = date != null ? from.toDate() : null; Date end = v != null ? new LocalDate(v.year(), v.month(), v.day()).toDate() : null; decorators.add(new HighlightDecorator(new ArrayList<>(hdates), start, end, color)); calendar.setDecorators(decorators); } else if (activeDays > 0 && restDays > 0) { List<Date> hdates = new ArrayList<>(); LocalDate d = from.plusDays(0); // copy while (d.isBefore(to)) { if (ScheduleHelper.cycleEnabledForDate(d, from, activeDays, restDays)) { hdates.add(d.toDate()); } d = d.plusDays(1); } List<CalendarCellDecorator> decorators = new ArrayList<>(); //DateValue v = r.iCalRule().getUntil(); //Date start = date != null ? from.toDate() : null; //Date end = v != null ? new LocalDate(v.year(), v.month(), v.day()).toDate() : null; decorators.add(new HighlightDecorator(hdates, from.toDate(), to.toDate(), color)); calendar.setDecorators(decorators); } calendar.init(from.toDate(), to.toDate()) .setShortWeekdays(getResources().getStringArray(R.array.calendar_weekday_names)); }
From source file:es.usc.citius.servando.calendula.persistence.Schedule.java
License:Open Source License
public List<DateTime> hourlyItemsToday() { DateTime today = DateTime.now().withTimeAtStartOfDay(); // get schedule occurrences for the current day return rrule.occurrencesBetween(today, today.plusDays(1), startDateTime()); }
From source file:es.usc.citius.servando.calendula.persistence.Schedule.java
License:Open Source License
public List<DateTime> hourlyItemsAt(DateTime d) { DateTime date = d.withTimeAtStartOfDay(); // get schedule occurrences for the current day return rrule.occurrencesBetween(date, date.plusDays(1), startDateTime()); }
From source file:es.usc.citius.servando.calendula.persistence.Schedule.java
License:Open Source License
public boolean enabledForDate(LocalDate date) { if (type == SCHEDULE_TYPE_CYCLE) { return cycleEnabledForDate(date); } else {// w ww.j av a2s. co m DateTime dt = date.toDateTimeAtStartOfDay(); List<DateTime> occurrences = rrule.occurrencesBetween(dt, dt.plusDays(1), startDateTime()); return occurrences.size() > 0; } }