List of usage examples for org.joda.time DateTime minusWeeks
public DateTime minusWeeks(int weeks)
From source file:net.tourbook.ui.views.calendar.CalendarGraph.java
License:Open Source License
private DateTime scrollBarStart() { // DateTime dt = _dataProvider.getFirstDateTime().plusWeeks(_scrollBarShift); DateTime dt = _dataProvider.getFirstDateTime(); final DateTime now = new DateTime(); final int weeks = (int) ((now.getMillis() - dt.getMillis()) / _WEEK_MILLIS); if (weeks < _MIN_SCROLLABLE_WEEKS) { // ensure the scrollable area has a reasonable size dt = now.minusWeeks(_MIN_SCROLLABLE_WEEKS); }//from w w w . jav a 2 s . c o m dt = dt.plusWeeks(_scrollBarShift); // ensure the date return is a "FirstDayOfTheWeek" !!! return dt.minusWeeks(1).withDayOfWeek(getFirstDayOfWeek()); }
From source file:org.countandra.utils.CountandraUtils.java
License:Apache License
private long getStartMillis(String timeQuery) { DateTime dt = new DateTime(DateTimeZone.UTC); TimePeriod tq = hshSupportedTimePeriods.get(timeQuery); if (tq != null) { switch (tq) { case THISHOUR: return dt.minusHours(1).getMillis(); case LASTHOUR: return dt.minusHours(2).getMillis(); case LASTTFHOURS: return dt.minusHours(24).getMillis(); case TODAY: return dt.minusHours(24).getMillis(); case YESTERDAY: return dt.minusHours(48).getMillis(); case THISWEEK: return dt.minusWeeks(1).getMillis(); case LASTWEEK: return dt.minusWeeks(2).getMillis(); case THISMONTH: return dt.minusMonths(1).getMillis(); case LASTMONTH: return dt.minusMonths(2).getMillis(); case THISYEAR: return dt.minusYears(1).getMillis(); case LASTYEAR: return dt.minusYears(2).getMillis(); }//from w ww. j a va2 s . c o m } else { return 0L; } return 0; }
From source file:org.countandra.utils.CountandraUtils.java
License:Apache License
private long getEndMillis(String timeQuery) { DateTime dt = new DateTime(DateTimeZone.UTC); TimePeriod tq = hshSupportedTimePeriods.get(timeQuery); if (tq != null) { switch (tq) { case THISHOUR: return dt.getMillis(); case LASTHOUR: return dt.minusHours(1).getMillis(); case LASTTFHOURS: return dt.getMillis(); case TODAY: return dt.getMillis(); case YESTERDAY: return dt.minusHours(24).getMillis(); case THISWEEK: return dt.getMillis(); case LASTWEEK: return dt.minusWeeks(1).getMillis(); case THISMONTH: return dt.getMillis(); case LASTMONTH: return dt.minusMonths(1).getMillis(); case THISYEAR: return dt.getMillis(); case LASTYEAR: return dt.minusYears(1).getMillis(); }//from w w w. j a v a 2 s . co m } else { return 0L; } return 0L; }
From source file:org.efaps.esjp.common.uitable.MultiPrint_Base.java
License:Apache License
/** * @param _field Field the date is wanted for * @return datetime array//from w ww. ja v a2 s .c om * @throws EFapsException on error */ protected Object[] getFilter(final Field _field) throws EFapsException { Object[] ret = null; final String filter = _field.getFilter().getDefaultValue(); if (filter != null) { final String[] parts = filter.split(":"); final String range = parts[0]; final int fromSub = parts.length > 1 ? Integer.parseInt(parts[1]) : 0; final int rangeCount = parts.length > 2 ? Integer.parseInt(parts[2]) : 1; DateTime dateFrom = new DateTime(); DateTime dateTo = new DateTime(); if (range != null) { final FilterDefault def = FilterDefault.valueOf(range.toUpperCase()); // to get a timezone dependent DateTim DateTime tmp = DateTimeUtil.translateFromUI(new DateTime()).withTimeAtStartOfDay(); switch (def) { case TODAY: dateFrom = tmp.toDateTime().minusDays(fromSub).minusMinutes(1); dateTo = dateFrom.plusDays(rangeCount).plusSeconds(1); ret = new DateTime[] { dateFrom, dateTo }; break; case WEEK: // the first of the current week tmp = tmp.minusDays(tmp.getDayOfWeek() - 1); dateFrom = tmp.minusWeeks(fromSub).minusMinutes(1); dateTo = tmp.plusWeeks(rangeCount); ret = new DateTime[] { dateFrom, dateTo }; break; case MONTH: // the first of the current month tmp = tmp.minusDays(tmp.getDayOfMonth() - 1); // substract the month and a minute before dateFrom = tmp.minusMonths(fromSub).minusMinutes(1); // add the month dateTo = tmp.plusMonths(rangeCount); ret = new DateTime[] { dateFrom, dateTo }; break; case YEAR: tmp = tmp.minusDays(tmp.getDayOfYear() - 1); dateFrom = tmp.minusYears(fromSub).minusMinutes(1); dateTo = tmp.plusYears(rangeCount); ret = new DateTime[] { dateFrom, dateTo }; break; case ALL: ret = new String[] { "*" }; break; case NONE: break; default: ret = new String[] { range + "*" }; break; } } } return ret; }
From source file:org.encuestame.business.service.StreamService.java
License:Apache License
/** * Classify notifications by {@link DateClasificatedEnum}. * @throws EnMeNoResultsFoundException/* w ww . jav a 2s .c o m*/ */ public HashMap<DateClasificatedEnum, List<UtilNotification>> classifyNotificationList( final List<UtilNotification> utilNotifications, final HttpServletRequest request) throws EnMeNoResultsFoundException { final HashMap<DateClasificatedEnum, List<UtilNotification>> response = new HashMap<DateClasificatedEnum, List<UtilNotification>>(); // today notification final List<Notification> todayNotifications = filterByDate(DateUtil.getTodayStartDate(), DateUtil.getNextDayMidnightDate()); // this week (minus today) DateTime thisWeek = new DateTime(DateUtil.getTodayStartDate()); thisWeek = thisWeek.minusMinutes(1); Date finalThisWeek = thisWeek.minusWeeks(1).toDate(); final List<Notification> thisWeekList = filterByDate(finalThisWeek, thisWeek.toDate()); // this months notifications final DateTime finalThisWeekMinusOne = new DateTime(finalThisWeek).minusMinutes(1); final DateTime finalThisMonth = finalThisWeekMinusOne.minusWeeks(3); final List<Notification> thisMonth = filterByDate(finalThisMonth.toDate(), finalThisWeekMinusOne.toDate()); // last months notifications final DateTime lastMontFinal = finalThisMonth.minusMinutes(1); final DateTime lastMontInit = lastMontFinal.minusDays(DateClasificatedEnum.THIS_MONTH.toNumber()); final List<Notification> lastMonth = filterByDate(lastMontInit.toDate(), lastMontFinal.toDate()); // few months ago final DateTime lastFewMontFinal = lastMontInit.minusMinutes(1); final DateTime lastFewMontInit = lastFewMontFinal.minusMonths(4); // 4 months, 4 + (1) last + 1 (current) = 6 final List<Notification> fewMonth = filterByDate(lastFewMontInit.toDate(), lastFewMontFinal.toDate()); // last year final DateTime lastYearFinal = lastFewMontInit.minusMinutes(1); final DateMidnight lastYeaInit = new DateMidnight(lastYearFinal).withWeekOfWeekyear(1).withDayOfWeek(1); final List<Notification> lastYear = filterByDate(lastYeaInit.toDate(), lastYearFinal.toDate()); // long time ago final DateTime longTimeFinal = new DateTime(lastYeaInit).minusMinutes(1); final DateMidnight longTimeInit = new DateMidnight(longTimeFinal).minusYears(3).withWeekOfWeekyear(1) .withDayOfWeek(1); final List<Notification> longtime = filterByDate(longTimeInit.toDate(), longTimeFinal.toDate()); response.put(DateClasificatedEnum.TODAY, convertNotificationList(todayNotifications, request)); response.put(DateClasificatedEnum.THIS_WEEK, convertNotificationList(thisWeekList, request)); response.put(DateClasificatedEnum.THIS_MONTH, convertNotificationList(thisMonth, request)); response.put(DateClasificatedEnum.LAST_MONTH, convertNotificationList(lastMonth, request)); response.put(DateClasificatedEnum.FEW_MONTHS_AGO, convertNotificationList(fewMonth, request)); response.put(DateClasificatedEnum.LAST_YEAR, convertNotificationList(lastYear, request)); response.put(DateClasificatedEnum.LONG_TIME_AGO, convertNotificationList(longtime, request)); return response; }
From source file:org.encuestame.utils.DateUtil.java
License:Apache License
/** * * @param startDate//from w ww . j a v a 2s . c o m * @return */ public static Date decreaseDateAsWeek(final Date startDate) { final DateTime midnightDate = new DateTime(startDate); final DateTime weekDate = midnightDate.minusWeeks(1); return weekDate.toDate(); }
From source file:org.entcore.feeder.timetable.udt.UDTImporter.java
License:Open Source License
private JsonObject generateCourse(String start, String end, JsonObject entity, int periodWeek, int endPeriodWeek, boolean theoretical) { JsonObject ficheTStart = fichesT.get(start); JsonObject ficheTEnd = fichesT.get(end); if (ficheTStart == null || ficheTEnd == null) { report.addError("invalid.ficheT"); return null; }/*from w w w.j a v a 2s .c o m*/ final Slot slotStart = slots.get(ficheTStart.getString("jour") + padLeft(ficheTStart.getString("demi_seq"), 2, '0') + ficheTStart.getString("site")); final Slot slotEnd = slots.get(ficheTEnd.getString("jour") + padLeft(ficheTEnd.getString("demi_seq"), 2, '0') + ficheTEnd.getString("site")); if (slotStart == null || slotEnd == null) { report.addError("invalid.slot"); return null; } final int day = Integer.parseInt(ficheTStart.getString("jour")); final int cpw = (periodWeek < startDateWeek1.getWeekOfWeekyear()) ? periodWeek + maxYearWeek : periodWeek; DateTime startDate = startDateWeek1.plusWeeks(cpw - startDateWeek1.getWeekOfWeekyear()).plusDays(day - 1); while (holidays.contains(startDate)) { startDate = startDate.plusWeeks(1); } startDate = startDate.plusSeconds(slotStart.getStart()); //final int epw = periods.get(periodWeek); final int cepw = (endPeriodWeek < startDateWeek1.getWeekOfWeekyear()) ? endPeriodWeek + maxYearWeek : endPeriodWeek; DateTime endDate = startDateWeek1.plusWeeks(cepw - startDateWeek1.getWeekOfWeekyear()).plusDays(day - 1); while (holidays.contains(endDate)) { endDate = endDate.minusWeeks(1); } endDate = endDate.plusSeconds(slotEnd.getEnd()); if (endDate.isBefore(startDate)) { log.error("endDate before start date. cpw : " + cpw + ", cepw : " + cepw + ", startDateWeek1 : " + startDateWeek1 + ", endPeriodOfWeek : " + endPeriodWeek); } final Set<String> ce = coens.get(start); JsonArray teacherIds; if (ce != null && ce.size() > 0) { teacherIds = new fr.wseduc.webutils.collections.JsonArray(new ArrayList<>(ce)); } else { teacherIds = new fr.wseduc.webutils.collections.JsonArray(); } final String pId = teachers.get(entity.getString("prof")); if (isNotEmpty(pId)) { teacherIds.add(pId); } final JsonObject c = new JsonObject().put("structureId", structureId).put("startDate", startDate.toString()) .put("endDate", endDate.toString()).put("dayOfWeek", day).put("teacherIds", teacherIds) .put("theoretical", theoretical); final String sId = subjects.get(entity.getString("mat")); if (isNotEmpty(sId)) { c.put("subjectId", sId); } final String rId = rooms.get(entity.getString("salle")); if (isNotEmpty(rId)) { c.put("roomLabels", new fr.wseduc.webutils.collections.JsonArray().add(rId)); } final JsonObject cId = classes.get(entity.getString("div")); if (cId != null && isNotEmpty(cId.getString("className"))) { c.put("classes", new fr.wseduc.webutils.collections.JsonArray().add(cId.getString("className"))); } JsonArray groups; if (isNotEmpty(entity.getString("rgpmt")) || isNotEmpty(entity.getString("gpe"))) { groups = new fr.wseduc.webutils.collections.JsonArray(); c.put("groups", groups); String name = regroup.get(entity.getString("rgpmt")); if (isNotEmpty(name)) { groups.add(name); } String gName = entity.getString("gpe"); if (isNotEmpty(gName)) { groups.add(entity.getString("div") + " Gr " + gName); } } try { c.put("_id", JsonUtil.checksum(c)); } catch (NoSuchAlgorithmException e) { log.error("Error generating course checksum", e); } return c; }
From source file:org.everit.jira.reporting.plugin.web.JiraTimetrackerChartWebAction.java
License:Apache License
private void initDatesIfNecessary() { if (dateFromFormated == null) { DateTime dateTimeFrom = new DateTime(TimetrackerUtil.getLoggedUserTimeZone()); dateTimeFrom = dateTimeFrom.minusWeeks(1); dateFromFormated = DateTimeConverterUtil.convertDateTimeToDate(dateTimeFrom).getTime(); }/* w ww. j a va 2s . c o m*/ if (dateToFormated == null) { DateTime dateTimeTo = new DateTime(TimetrackerUtil.getLoggedUserTimeZone()); dateToFormated = DateTimeConverterUtil.convertDateTimeToDate(dateTimeTo).getTime(); } }
From source file:org.everit.jira.reporting.plugin.web.ReportingWebAction.java
License:Apache License
private void initDatesIfNecessary() { if (filterCondition.getWorklogStartDate() == null) { DateTime dateFrom = new DateTime(TimetrackerUtil.getLoggedUserTimeZone()); dateFrom = dateFrom.minusWeeks(1); filterCondition.setWorklogStartDate(DateTimeConverterUtil.convertDateTimeToDate(dateFrom).getTime()); }/* w w w .j a va 2s. c o m*/ if (filterCondition.getWorklogEndDate() == null) { DateTime dateTo = new DateTime(TimetrackerUtil.getLoggedUserTimeZone()); filterCondition.setWorklogEndDate(DateTimeConverterUtil.convertDateTimeToDate(dateTo).getTime()); } }
From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java
License:Educational Community License
@Override public DateTime getPreviousAccrualIntervalDate(String earnInterval, DateTime aDate) { DateTime previousAccrualIntervalDate = null; if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.DAILY)) { previousAccrualIntervalDate = aDate.minusDays(1); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.WEEKLY)) { previousAccrualIntervalDate = aDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.SATURDAY); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.SEMI_MONTHLY)) { previousAccrualIntervalDate = aDate.minusDays(15); if (previousAccrualIntervalDate.getDayOfMonth() <= 15) { previousAccrualIntervalDate = previousAccrualIntervalDate.withDayOfMonth(15); } else {//from w w w . j a v a2 s. c om previousAccrualIntervalDate = previousAccrualIntervalDate .withDayOfMonth(previousAccrualIntervalDate.dayOfMonth().getMaximumValue()); } } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.MONTHLY)) { previousAccrualIntervalDate = aDate.minusMonths(1); previousAccrualIntervalDate = previousAccrualIntervalDate .withDayOfMonth(previousAccrualIntervalDate.dayOfMonth().getMaximumValue()); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.YEARLY)) { previousAccrualIntervalDate = aDate.minusYears(1); previousAccrualIntervalDate = previousAccrualIntervalDate .withDayOfYear(previousAccrualIntervalDate.dayOfYear().getMaximumValue()); } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.NO_ACCRUAL)) { previousAccrualIntervalDate = aDate; } return previousAccrualIntervalDate; }