List of usage examples for org.joda.time DateTime minusYears
public DateTime minusYears(int years)
From source file:object.Patient.java
public static void main(String[] args) { if (AgeGroup.Adult instanceof AgeGroup) { System.out.println("Adult is an instance"); }/* w w w . j av a 2s . co m*/ DateTime tomorrow = new DateTime(); System.out.println("Should be current date: " + tomorrow); DateTime dob = tomorrow.minusYears(64); DateTime youthYears = tomorrow.minusYears(5); System.out.println("Should be younger then " + youthYears + " and dob is: " + dob); DateTime adultYears = tomorrow.minusYears(18); DateTime elderYears = tomorrow.minusYears(65); if (dob.isAfter(youthYears)) { System.out.println(youthYears); System.out.println("is Younger then 5."); } else if (dob.isAfter(adultYears)) { System.out.println(adultYears); System.out.println("Is Youth"); } else if (dob.isAfter(elderYears)) { System.out.println(elderYears); System.out.println("Is Adult"); } else { System.out.println("Is Elder "); } System.out.println(dob); }
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 ww w .j a v a2 s.c om*/ } 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(); }/*w w w . j a v a2s. 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 va2 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.egov.pgr.elasticsearch.repository.ComplaintIndexRepositoryImpl.java
License:Open Source License
@Override public Map<String, SearchResponse> findAllGrievanceByFilter( final ComplaintDashBoardRequest complaintDashBoardRequest, final BoolQueryBuilder query, final String grouByField) { /**/*from w w w . jav a 2 s. co m*/ * For Current day's complaint count if dates are sent in the request, consider the toDate, else take date range between * current date +1 day */ DateTime fromDate = new DateTime(); if (isNotBlank(complaintDashBoardRequest.getFromDate()) && isNotBlank(complaintDashBoardRequest.getToDate())) fromDate = new DateTime(complaintDashBoardRequest.getFromDate()); // This is size used to fetch those many number of documents int size = 120; if (complaintDashBoardRequest.getSize() >= 0) size = complaintDashBoardRequest.getSize(); DateTime currentYearFromDate = new DateTime(); if (fromDate.getMonthOfYear() < 4) currentYearFromDate = currentYearFromDate.minusYears(1).withMonthOfYear(4).dayOfMonth() .withMinimumValue(); else currentYearFromDate = currentYearFromDate.withMonthOfYear(4).dayOfMonth().withMinimumValue(); final SearchResponse consolidatedResponse = elasticsearchTemplate.getClient().prepareSearch(PGR_INDEX_NAME) .setQuery(query).setSize(0).addAggregation(getCount("countAggregation", "crn")) .addAggregation(getCountWithGrouping("closedCount", IF_CLOSED, 2)) .addAggregation(getCountWithGrouping("slaCount", IF_SLA, 2)) .addAggregation(getAverageWithFilter(IF_CLOSED, 1, "AgeingInWeeks", COMPLAINT_AGEINGDAYS_FROM_DUE)) .addAggregation(getAverageWithExclusion(SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .addAggregation(getCountBetweenSpecifiedDates("currentYear", CREATED_DATE, currentYearFromDate.toString(formatter), new DateTime().plusDays(1).toString(formatter))) .addAggregation(getCountBetweenSpecifiedDates(TODAY_COMPLAINT_COUNT, CREATED_DATE, new DateTime().toString(formatter), new DateTime().plusDays(1).toString(formatter))) .execute().actionGet(); SearchResponse tableResponse; if (complaintDashBoardRequest.getType().equalsIgnoreCase(DASHBOARD_GROUPING_ALL_WARDS)) tableResponse = elasticsearchTemplate.getClient().prepareSearch(PGR_INDEX_NAME).setQuery(query) .setSize(0) .addAggregation(getCountWithGroupingAndOrder(COMPLAINT_TYPE_WISE, COMPLAINT_TYPE_NAME, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion(COMPLAINT_TYPE_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(getCountWithGrouping(COMPLAINT_TYPE_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8).addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(HOURWISE_COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13).addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation( getCountWithGrouping(COMPLAINT_TYPE_SLA, IF_SLA, 2)))) .addAggregation(AggregationBuilders.terms(ULBWISE).field(CITY_CODE).size(120) .subAggregation(getCountWithGroupingAndOrder(GROUP_BY_FIELD, grouByField, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion( GROUP_BY_FIELD_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(AggregationBuilders.topHits(COMPLAINT_RECORD) .addField(CITY_CODE).addField(DISTRICT_NAME).addField(CITY_NAME) .addField(WARD_NAME).setSize(1)) .subAggregation( getCountWithGrouping(GROUP_FIELD_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2).subAggregation( AggregationBuilders.range(GROUP_BY_FIELD_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8) .addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING_FOR_HOURS) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13) .addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation(getCountWithGrouping( GROUP_BY_FIELD_SLA, IF_SLA, 2))))) .execute().actionGet(); else if (complaintDashBoardRequest.getType().equalsIgnoreCase(DASHBOARD_GROUPING_ALL_LOCALITIES)) tableResponse = elasticsearchTemplate.getClient().prepareSearch(PGR_INDEX_NAME).setQuery(query) .setSize(0) .addAggregation(getCountWithGroupingAndOrder(COMPLAINT_TYPE_WISE, COMPLAINT_TYPE_NAME, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion(COMPLAINT_TYPE_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(getCountWithGrouping(COMPLAINT_TYPE_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8).addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(HOURWISE_COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13).addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation( getCountWithGrouping(COMPLAINT_TYPE_SLA, IF_SLA, 2)))) .addAggregation(AggregationBuilders.terms(ULBWISE).field(CITY_CODE).size(120) .subAggregation(AggregationBuilders.terms(WARDWISE).field(WARD_NUMBER).size(size) .subAggregation(getCountWithGroupingAndOrder(GROUP_BY_FIELD, grouByField, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()).subAggregation( getAverageWithExclusion(GROUP_BY_FIELD_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(AggregationBuilders.topHits(COMPLAINT_RECORD) .addField(CITY_CODE).addField(CITY_DISTRICT_NAME) .addField(CITY_NAME).addField(WARD_NAME) .addField(LOCALITY_NAME).setSize(1)) .subAggregation(getCountWithGrouping( GROUP_FIELD_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING).field( COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8) .addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING_FOR_HOURS) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13) .addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation(getCountWithGrouping( GROUP_BY_FIELD_SLA, IF_SLA, 2)))))) .execute().actionGet(); else if (complaintDashBoardRequest.getType().equalsIgnoreCase(DASHBOARD_GROUPING_ALL_FUNCTIONARY)) tableResponse = elasticsearchTemplate.getClient().prepareSearch(PGR_INDEX_NAME).setQuery(query) .setSize(0) .addAggregation(getCountWithGroupingAndOrder(COMPLAINT_TYPE_WISE, COMPLAINT_TYPE_NAME, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion(COMPLAINT_TYPE_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(getCountWithGrouping(COMPLAINT_TYPE_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8).addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(HOURWISE_COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13).addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation( getCountWithGrouping(COMPLAINT_TYPE_SLA, IF_SLA, 2)))) .addAggregation(AggregationBuilders.terms(ULBWISE).field(CITY_CODE).size(120) .subAggregation(AggregationBuilders.terms(DEPARTMENTWISE).field(DEPARTMENT_CODE) .size(size) .subAggregation(getCountWithGroupingAndOrder(GROUP_BY_FIELD, grouByField, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()).subAggregation( getAverageWithExclusion(GROUP_BY_FIELD_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(AggregationBuilders.topHits(COMPLAINT_RECORD) .addField(CITY_CODE).addField(CITY_DISTRICT_NAME) .addField(CITY_NAME).addField(DEPARTMENT_NAME) .addField(INITIAL_FUNCTIONARY_MOBILE_NUMBER).setSize(1)) .subAggregation(getCountWithGrouping( GROUP_FIELD_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING).field( COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8) .addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING_FOR_HOURS) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13) .addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation(getCountWithGrouping( GROUP_BY_FIELD_SLA, IF_SLA, 2)))))) .execute().actionGet(); else tableResponse = elasticsearchTemplate.getClient().prepareSearch(PGR_INDEX_NAME).setQuery(query) .setSize(0) .addAggregation(getCountWithGroupingAndOrder(COMPLAINT_TYPE_WISE, COMPLAINT_TYPE_NAME, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion(COMPLAINT_TYPE_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(getCountWithGrouping(COMPLAINT_TYPE_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8).addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(HOURWISE_COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13).addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation( getCountWithGrouping(COMPLAINT_TYPE_SLA, IF_SLA, 2)))) .addAggregation(getCountWithGroupingAndOrder(GROUP_BY_FIELD, grouByField, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion(GROUP_BY_FIELD_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(getCountWithGrouping(GROUP_FIELD_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(GROUP_BY_FIELD_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8).addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING_FOR_HOURS) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13).addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation( getCountWithGrouping(GROUP_BY_FIELD_SLA, IF_SLA, 2)))) .execute().actionGet(); final HashMap<String, SearchResponse> result = new HashMap<>(); if (grouByField.equals(LOCALITY_NAME)) { final SearchResponse localityMissingResponse = elasticsearchTemplate.getClient() .prepareSearch(PGR_INDEX_NAME).setQuery(query).setSize(0) .addAggregation(AggregationBuilders.missing(NOLOCALITY).field(LOCALITY_NAME) .subAggregation(getAverageWithExclusion(GROUP_BY_FIELD_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation( getCountWithGrouping(GROUP_FIELD_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(GROUP_BY_FIELD_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE).addRange(ONE_WEEK, 0, 8) .addRange(ONE_MONTH, 8, 32).addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING_FOR_HOURS) .field(COMPLAINT_AGEING_FROM_DUE).addRange(TWELVE_HOURS, 0, 13) .addRange("1day", 13, 25).addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation(getCountWithGrouping(GROUP_BY_FIELD_SLA, IF_SLA, 2)))) .execute().actionGet(); result.put("noLocality", localityMissingResponse); } result.put("consolidatedResponse", consolidatedResponse); result.put("tableResponse", tableResponse); return result; }
From source file:org.elasticsearch.xpack.monitoring.cleaner.AbstractIndicesCleanerTestCase.java
License:Open Source License
public void testDeleteIndices() throws Exception { internalCluster().startNode();//w w w . j a va2s . c o m CleanerService.Listener listener = getListener(); final DateTime now = now(); createTimestampedIndex(now.minusYears(1)); createTimestampedIndex(now.minusMonths(6)); createTimestampedIndex(now.minusMonths(1)); createTimestampedIndex(now.minusDays(10)); createTimestampedIndex(now.minusDays(1)); assertIndicesCount(5); // Clean indices that have expired two years ago listener.onCleanUpIndices(years(2)); assertIndicesCount(5); // Clean indices that have expired 8 months ago listener.onCleanUpIndices(months(8)); assertIndicesCount(4); // Clean indices that have expired 3 months ago listener.onCleanUpIndices(months(3)); assertIndicesCount(3); // Clean indices that have expired 15 days ago listener.onCleanUpIndices(days(15)); assertIndicesCount(2); // Clean indices that have expired 7 days ago listener.onCleanUpIndices(days(7)); assertIndicesCount(1); // Clean indices until now listener.onCleanUpIndices(days(0)); assertIndicesCount(0); }
From source file:org.elasticsearch.xpack.monitoring.cleaner.AbstractIndicesCleanerTestCase.java
License:Open Source License
protected static TimeValue years(int years) { DateTime now = now(); return TimeValue.timeValueMillis(now.getMillis() - now.minusYears(years).getMillis()); }
From source file:org.epics.archiverappliance.common.TimeUtils.java
/** * Given an epoch seconds and a granularity, this method gives you the last second in the previous partition as epoch seconds. * @param epochSeconds/*from w w w.ja v a2s .com*/ * @param granularity * @return */ public static long getPreviousPartitionLastSecond(long epochSeconds, PartitionGranularity granularity) { DateTime dateTime = new DateTime(epochSeconds * 1000, DateTimeZone.UTC); DateTime previousPartitionLastSecond = null; switch (granularity) { case PARTITION_YEAR: previousPartitionLastSecond = dateTime.minusYears(1).withMonthOfYear(12).withDayOfMonth(31) .withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_MONTH: previousPartitionLastSecond = dateTime.withDayOfMonth(1).minusDays(1).withHourOfDay(23) .withMinuteOfHour(59).withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_DAY: previousPartitionLastSecond = dateTime.minusDays(1).withHourOfDay(23).withMinuteOfHour(59) .withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_HOUR: previousPartitionLastSecond = dateTime.minusHours(1).withMinuteOfHour(59).withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_5MIN: case PARTITION_15MIN: case PARTITION_30MIN: int approxMinutesPerChunk = granularity.getApproxMinutesPerChunk(); int startOfPartition_Min = (dateTime.getMinuteOfHour() / approxMinutesPerChunk) * approxMinutesPerChunk; previousPartitionLastSecond = dateTime.withMinuteOfHour(startOfPartition_Min).withSecondOfMinute(0) .minusSeconds(1); return previousPartitionLastSecond.getMillis() / 1000; default: throw new UnsupportedOperationException("Invalid Partition type " + granularity); } }
From source file:org.fam.jsf.bootstrap.Bootstrap.java
public void createPlayer() { DataFactory df = new DataFactory(); FamPlayer item = new FamPlayer(); item.setEmail("gbougeard@gmail.com"); item.setFirstName("Gregory"); item.setLastName("Bougeard"); DateTime dt = new DateTime(); item.setDtBirth(df.getBirthDate());/*www . j a v a2 s .c o m*/ item.setDtArrival(df.getDateBetween(dt.minusYears(15).toDate(), new Date())); item.setAddress("4, rue Roland Garros"); item.setZipcode("31200"); item.setCity("TOULOUSE"); item.setNumLicense(1L); try { ejbPlayer.create(item); listPlayer.add(item); createProfilePlayer(item); } catch (Exception e) { String msg = "create player failed"; logErrorMsg(msg, e); } item = new FamPlayer(); item.setEmail("toto@gmail.com"); item.setFirstName("Toto"); item.setLastName("Test"); item.setDtBirth(df.getBirthDate()); item.setDtArrival(df.getDateBetween(dt.minusYears(15).toDate(), new Date())); item.setNumLicense(2L); //toto = ejbUser.find(54); item.setFamUser(toto); try { ejbPlayer.create(item); listPlayer.add(item); createProfilePlayer(item); } catch (Exception e) { String msg = "create player failed"; logErrorMsg(msg, e); } toto.setCurrentClub(item.getCurrentClub()); ejbUser.edit(toto); for (int i = 0; i < 200; i++) { item = new FamPlayer(); item.setFirstName(df.getFirstName()); item.setLastName(df.getLastName()); item.setDtBirth(df.getBirthDate()); dt = new DateTime(); item.setDtArrival(df.getDateBetween(dt.minusYears(15).toDate(), new Date())); item.setNumLicense(new Long(df.getNumberUpTo(99999))); item.setAddress(df.getAddress()); item.setZipcode(df.getNumberText(5)); item.setCity(df.getCity()); item.setTel(df.getNumberText(10)); item.setIceContact(df.getName()); item.setIceTel(df.getNumberText(10)); setEmailPlayer(item); try { ejbPlayer.create(item); listPlayer.add(item); createProfilePlayer(item); } catch (Exception e) { String msg = "create player failed"; logErrorMsg(msg, e); } // ejbPlayer.edit(item); } }
From source file:org.killbill.billing.subscription.alignment.BaseAligner.java
License:Apache License
private DateTime addOrRemoveDuration(final DateTime input, final Duration duration, boolean add) { DateTime result = input; switch (duration.getUnit()) { case DAYS://from w ww .j a v a2 s . com result = add ? result.plusDays(duration.getNumber()) : result.minusDays(duration.getNumber()); ; break; case MONTHS: result = add ? result.plusMonths(duration.getNumber()) : result.minusMonths(duration.getNumber()); break; case YEARS: result = add ? result.plusYears(duration.getNumber()) : result.minusYears(duration.getNumber()); break; case UNLIMITED: default: throw new RuntimeException("Trying to move to unlimited time period"); } return result; }