List of usage examples for org.joda.time DateTime plusMonths
public DateTime plusMonths(int months)
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// w w w. j a v a 2 s . co m * @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.egov.pgr.dashboard.service.DashboardService.java
License:Open Source License
public Map<String, Object> topComplaints() { DateTime currentDate = new DateTime(); List<Object> dataHolderNumber = constructListOfMonthPlaceHolder(currentDate.minusMonths(5), currentDate.plusMonths(1), "MM"); List<Object> dataHolderString = constructListOfMonthPlaceHolder(currentDate.minusMonths(5), currentDate.plusMonths(1), "MMM"); List<Object[]> topFiveCompTypeData = dashboardRepository.fetchTopComplaintsBetween( startOfGivenDate(currentDate.minusMonths(5).withDayOfMonth(1)).toDate(), endOfGivenDate(currentDate).toDate()); List<Object[]> topFiveCompTypeCurrentMonth = dashboardRepository.fetchTopComplaintsForCurrentMonthBetween( startOfGivenDate(currentDate.minusMonths(5).withDayOfMonth(1)).toDate(), endOfGivenDate(currentDate).toDate()); Map<Object, Object> constructResultPlaceholder = new LinkedHashMap<>(); Map<Object, Object> actualdata = new LinkedHashMap<>(); for (Object complaintType : topFiveCompTypeCurrentMonth) for (Object month : dataHolderNumber) constructResultPlaceholder.put(month + "-" + complaintType, BigInteger.ZERO); for (Object[] top5CompType : topFiveCompTypeData) actualdata.put(top5CompType[0] + "-" + top5CompType[2], top5CompType[1]); Map<Object, Object> newdata = new LinkedHashMap<>(); for (Object placeholderMapKey : constructResultPlaceholder.keySet()) if (actualdata.get(placeholderMapKey) == null) newdata.put(placeholderMapKey, BigInteger.ZERO); else/*from w w w.ja v a2 s .c om*/ newdata.put(placeholderMapKey, actualdata.get(placeholderMapKey)); Map<String, Object> topFiveCompDataHolder = new LinkedHashMap<>(); List<Object> dataHolder = new LinkedList<>(); List<Object> compCount = new ArrayList<>(); Iterator<Entry<Object, Object>> entries = newdata.entrySet().iterator(); int index = 0; while (entries.hasNext()) { Map<String, Object> tmpdata = new LinkedHashMap<>(); Entry<Object, Object> entry = entries.next(); if (index < 5) { compCount.add(entry.getValue()); index++; } else if (index == 5) { compCount.add(entry.getValue()); String[] parts = entry.getKey().toString().split("-"); tmpdata.put("name", parts[1]); tmpdata.put("data", new LinkedList<Object>(compCount)); HashMap<String, Object> ctypeCountMap = new LinkedHashMap<>(); ctypeCountMap.putAll(tmpdata); dataHolder.add(ctypeCountMap); index = 0; compCount.clear(); tmpdata.clear(); } } topFiveCompDataHolder.put("year", dataHolderString); topFiveCompDataHolder.put("series", dataHolder); return topFiveCompDataHolder; }
From source file:org.egov.pgr.service.dashboard.DashboardService.java
License:Open Source License
public Map<String, Object> topComplaints() { final DateTime currentDate = new DateTime(); final List<Object> dataHolderNumber = constructListOfMonthPlaceHolder(currentDate.minusMonths(5), currentDate.plusMonths(1), "MM"); final List<Object> dataHolderString = constructListOfMonthPlaceHolder(currentDate.minusMonths(5), currentDate.plusMonths(1), "MMM"); final List<Object[]> topFiveCompTypeData = dashboardRepository.fetchTopComplaintsBetween( startOfGivenDate(currentDate.minusMonths(5).withDayOfMonth(1)).toDate(), endOfGivenDate(currentDate).toDate()); final List<Object[]> topFiveCompTypeCurrentMonth = dashboardRepository .fetchTopComplaintsForCurrentMonthBetween( startOfGivenDate(currentDate.minusMonths(5).withDayOfMonth(1)).toDate(), endOfGivenDate(currentDate).toDate()); final Map<Object, Object> constructResultPlaceholder = new LinkedHashMap<Object, Object>(); final Map<Object, Object> actualdata = new LinkedHashMap<Object, Object>(); for (final Object complaintType : topFiveCompTypeCurrentMonth) for (final Object month : dataHolderNumber) constructResultPlaceholder.put(month + "-" + complaintType, BigInteger.ZERO); for (final Object[] top5CompType : topFiveCompTypeData) actualdata.put(top5CompType[0] + "-" + top5CompType[2], top5CompType[1]); final Map<Object, Object> newdata = new LinkedHashMap<Object, Object>(); for (final Object placeholderMapKey : constructResultPlaceholder.keySet()) if (actualdata.get(placeholderMapKey) == null) newdata.put(placeholderMapKey, BigInteger.ZERO); else/*from ww w . j a v a2 s.c o m*/ newdata.put(placeholderMapKey, actualdata.get(placeholderMapKey)); final Map<String, Object> topFiveCompDataHolder = new LinkedHashMap<String, Object>(); final List<Object> dataHolder = new LinkedList<Object>(); final List<Object> compCount = new ArrayList<Object>(); final Iterator<Entry<Object, Object>> entries = newdata.entrySet().iterator(); int index = 0; while (entries.hasNext()) { final Map<String, Object> tmpdata = new LinkedHashMap<String, Object>(); final Entry<Object, Object> entry = entries.next(); if (index < 5) { compCount.add(entry.getValue()); index++; } else if (index == 5) { compCount.add(entry.getValue()); final String[] parts = entry.getKey().toString().split("-"); tmpdata.put("name", parts[1]); tmpdata.put("data", new LinkedList<Object>(compCount)); final HashMap<String, Object> ctypeCountMap = new LinkedHashMap<String, Object>(); ctypeCountMap.putAll(tmpdata); dataHolder.add(ctypeCountMap); index = 0; compCount.clear(); tmpdata.clear(); } } topFiveCompDataHolder.put("year", dataHolderString); topFiveCompDataHolder.put("series", dataHolder); return topFiveCompDataHolder; }
From source file:org.egov.wtms.web.controller.application.MeterReadingController.java
License:Open Source License
private WaterConnectionDetails calculateDemandForDamagedMeter( final WaterConnectionDetails waterConnectionDetails, final Date previousDate, final int noOfMonths, final Boolean currentMonthIncluded) { BigDecimal amountValue;// w ww. jav a2 s .c o m new WaterConnectionDetails(); Installment currentInstallment; List<Installment> newInstallmentList; DateTime dateTime = new DateTime(previousDate); DateTime lastInstReadingDate; DateTime lastInstStartDate; newInstallmentList = installmentDao.getInstallmentsByModuleForGivenDateAndInstallmentType( moduleService.getModuleByName(MODULE_NAME), previousDate, MONTHLY); currentInstallment = connectionDemandService.getCurrentInstallment(MODULE_NAME, MONTHLY, new Date()); if (newInstallmentList.isEmpty() || !newInstallmentList.contains(currentInstallment)) newInstallmentList.add(currentInstallment); for (final Installment installment : newInstallmentList) { lastInstReadingDate = dateTime.minusMonths(6); lastInstStartDate = lastInstReadingDate.withDayOfMonth(1).withTimeAtStartOfDay(); final List<Installment> lastInstallmentList = installmentDao .getInstallmentsByModuleBetweenFromDateAndToDateAndInstallmentType( moduleService.getModuleByName(MODULE_NAME), lastInstStartDate.toDate(), installment.getFromDate(), MONTHLY); amountValue = calculateDamagedMeterAverageDemand(lastInstallmentList, waterConnectionDetails); if (amountValue.compareTo(BigDecimal.ZERO) > 0) connectionDemandService.updateDemandForMeteredConnection(waterConnectionDetails, amountValue, installment.getFromDate(), previousDate, noOfMonths, currentMonthIncluded); dateTime = new DateTime(installment.getFromDate()); dateTime = dateTime.plusMonths(1); } return waterConnectionDetails; }
From source file:org.elasticsearch.xpack.security.Security.java
License:Open Source License
static void validateAutoCreateIndex(Settings settings) { String value = settings.get("action.auto_create_index"); if (value == null) { return;/* w ww. j av a2 s . c o m*/ } final boolean indexAuditingEnabled = Security.indexAuditLoggingEnabled(settings); if (indexAuditingEnabled) { String auditIndex = IndexAuditTrailField.INDEX_NAME_PREFIX + "*"; String errorMessage = LoggerMessageFormat.format( "the [action.auto_create_index] setting value [{}] is too" + " restrictive. disable [action.auto_create_index] or set it to include " + "[{}]", (Object) value, auditIndex); if (Booleans.isFalse(value)) { throw new IllegalArgumentException(errorMessage); } if (Booleans.isTrue(value)) { return; } String[] matches = Strings.commaDelimitedListToStringArray(value); List<String> indices = new ArrayList<>(); DateTime now = new DateTime(DateTimeZone.UTC); // just use daily rollover indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now, IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusDays(1), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(1), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(2), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(3), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(4), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(5), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(6), IndexNameResolver.Rollover.DAILY)); for (String index : indices) { boolean matched = false; for (String match : matches) { char c = match.charAt(0); if (c == '-') { if (Regex.simpleMatch(match.substring(1), index)) { throw new IllegalArgumentException(errorMessage); } } else if (c == '+') { if (Regex.simpleMatch(match.substring(1), index)) { matched = true; break; } } else { if (Regex.simpleMatch(match, index)) { matched = true; break; } } } if (!matched) { throw new IllegalArgumentException(errorMessage); } } logger.warn("the [action.auto_create_index] setting is configured to be restrictive [{}]. " + " for the next 6 months audit indices are allowed to be created, but please make sure" + " that any future history indices after 6 months with the pattern " + "[.security_audit_log*] are allowed to be created", value); } }
From source file:org.elasticsearch.xpack.watcher.Watcher.java
static void validAutoCreateIndex(final Settings settings) { final String value = settings.get("action.auto_create_index"); if (value == null) { return;/* w w w. j a v a2 s.c o m*/ } final String errorMessage = LoggerMessageFormat.format( "the [action.auto_create_index] setting value [{}] is too restrictive. disable [action.auto_create_index] or set it to [{}, {}, {}*]", new Object[] { value, ".watches", ".triggered_watches", ".watcher-history-" }); if (Booleans.isExplicitFalse(value)) { throw new IllegalArgumentException(errorMessage); } if (Booleans.isExplicitTrue(value)) { return; } final String[] matches = Strings.commaDelimitedListToStringArray(value); final List<String> indices = new ArrayList<String>(); indices.add(".watches"); indices.add(".triggered_watches"); final DateTime now = new DateTime(DateTimeZone.UTC); indices.add(HistoryStore.getHistoryIndexNameForTime(now)); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusDays(1))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(1))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(2))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(3))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(4))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(5))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(6))); for (final String index : indices) { boolean matched = false; for (final String match : matches) { final char c = match.charAt(0); if (c == '-') { if (Regex.simpleMatch(match.substring(1), index)) { throw new IllegalArgumentException(errorMessage); } } else if (c == '+') { if (Regex.simpleMatch(match.substring(1), index)) { matched = true; break; } } else if (Regex.simpleMatch(match, index)) { matched = true; break; } } if (!matched) { throw new IllegalArgumentException(errorMessage); } } Watcher.logger.warn( "the [action.auto_create_index] setting is configured to be restrictive [{}]. for the next 6 months daily history indices are allowed to be created, but please make sure that any future history indices after 6 months with the pattern [.watcher-history-YYYY.MM.dd] are allowed to be created", (Object) value); }
From source file:org.emonocot.model.registry.Resource.java
License:Open Source License
public void updateNextAvailableDate() { if (getScheduled()) { DateTime nextAvailableDate = new DateTime(); switch (getSchedulingPeriod()) { case YEARLY: nextAvailableDate = nextAvailableDate.plusYears(1); break; case MONTHLY: nextAvailableDate = nextAvailableDate.plusMonths(1); break; case WEEKLY: nextAvailableDate = nextAvailableDate.plusWeeks(1); break; case DAILY: nextAvailableDate = nextAvailableDate.plusDays(1); break; default:/*www . java 2s . co m*/ nextAvailableDate = null; } setNextAvailableDate(nextAvailableDate); } }
From source file:org.emonocot.portal.view.Functions.java
License:Open Source License
public static String formatDateRange(String dateRange) { Matcher matcher = pattern.matcher(dateRange); if (matcher.matches()) { String beginningString = matcher.group(1); String endString = matcher.group(2); DateTime beginning = solrDateTimeFormatter.parseDateTime(beginningString); DateTime end = solrDateTimeFormatter.parseDateTime(endString); Integer gap = Integer.parseInt(matcher.group(3)); String increment = matcher.group(4); DateTimeFormatter dateTimeFormatter = null; switch (increment) { case "DAY": end = end.plusDays(gap);//from w w w . jav a2s .com dateTimeFormatter = DateTimeFormat.shortDate(); break; case "WEEK": end = end.plusWeeks(gap); dateTimeFormatter = DateTimeFormat.shortDate(); break; case "MONTH": end = end.plusMonths(gap); dateTimeFormatter = DateTimeFormat.forPattern("yyyy/MM"); break; case "YEAR": end = end.plusYears(gap); dateTimeFormatter = DateTimeFormat.forPattern("yyyy"); break; } return dateTimeFormatter.print(beginning) + " - " + dateTimeFormatter.print(end); } else { return dateRange; } }
From source file:org.epics.archiverappliance.common.TimeUtils.java
/** * Given an epoch seconds and a granularity, this method gives you the first second in the next partition as epoch seconds. * @param epochSeconds/*from w ww.j a v a2s . com*/ * @param granularity * @return */ public static long getNextPartitionFirstSecond(long epochSeconds, PartitionGranularity granularity) { DateTime dateTime = new DateTime(epochSeconds * 1000, DateTimeZone.UTC); DateTime nextPartitionFirstSecond = null; switch (granularity) { case PARTITION_YEAR: nextPartitionFirstSecond = dateTime.plusYears(1).withMonthOfYear(1).withDayOfMonth(1).withHourOfDay(0) .withMinuteOfHour(0).withSecondOfMinute(0); return nextPartitionFirstSecond.getMillis() / 1000; case PARTITION_MONTH: nextPartitionFirstSecond = dateTime.plusMonths(1).withDayOfMonth(1).withHourOfDay(0).withMinuteOfHour(0) .withSecondOfMinute(0); return nextPartitionFirstSecond.getMillis() / 1000; case PARTITION_DAY: nextPartitionFirstSecond = dateTime.plusDays(1).withHourOfDay(0).withMinuteOfHour(0) .withSecondOfMinute(0); return nextPartitionFirstSecond.getMillis() / 1000; case PARTITION_HOUR: nextPartitionFirstSecond = dateTime.plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0); return nextPartitionFirstSecond.getMillis() / 1000; case PARTITION_5MIN: case PARTITION_15MIN: case PARTITION_30MIN: int approxMinutesPerChunk = granularity.getApproxMinutesPerChunk(); DateTime nextPartForMin = dateTime.plusMinutes(approxMinutesPerChunk); int startOfPartitionForMin = (nextPartForMin.getMinuteOfHour() / approxMinutesPerChunk) * approxMinutesPerChunk; nextPartitionFirstSecond = nextPartForMin.withMinuteOfHour(startOfPartitionForMin) .withSecondOfMinute(0); return nextPartitionFirstSecond.getMillis() / 1000; default: throw new UnsupportedOperationException("Invalid Partition type " + granularity); } }
From source file:org.fenixedu.spaces.domain.occupation.config.MonthlyConfig.java
License:Open Source License
private List<Interval> getDayOfWeekIntervals() { final List<Interval> intervals = new ArrayList<>(); DateTime startDate = getInterval().getStart(); int nthDayOfWeek = getNthDayOfWeek(startDate); int dayOfWeek = startDate.getDayOfWeek(); DateTime endDate = getInterval().getEnd(); DateTime start = startDate; while (start.isBefore(endDate) || start.isEqual(endDate)) { intervals.add(new Interval(start.withFields(getStartTime()), start.withFields(getEndTime()))); start = start.plusMonths(getRepeatsEvery()); start = getNextNthdayOfWeek(start, nthDayOfWeek, dayOfWeek); }//from w w w . ja v a2 s. c om return intervals; }