List of usage examples for org.joda.time DateTime getYear
public int getYear()
From source file:com.netflix.raigad.indexmanagement.ElasticSearchIndexManager.java
License:Apache License
/** * Courtesy Jae Bae// w w w. j a va2s .c o m */ public void preCreateIndex(IndexMetadata indexMetadata, Client esTransportClient) throws UnsupportedAutoIndexException { logger.info("Running PreCreate Index task"); IndicesStatusResponse getIndicesResponse = getIndicesStatusResponse(esTransportClient); Map<String, IndexStatus> indexStatusMap = getIndicesResponse.getIndices(); if (!indexStatusMap.isEmpty()) { for (String indexNameWithDateSuffix : indexStatusMap.keySet()) { if (config.isDebugEnabled()) logger.debug("Index Name = <" + indexNameWithDateSuffix + ">"); if (indexMetadata.getIndexNameFilter().filter(indexNameWithDateSuffix) && indexMetadata.getIndexNameFilter().getNamePart(indexNameWithDateSuffix) .equalsIgnoreCase(indexMetadata.getIndexName())) { for (int i = 0; i < indexMetadata.getRetentionPeriod(); ++i) { DateTime dt = new DateTime(); int addedDate; switch (indexMetadata.getRetentionType()) { case DAILY: dt = dt.plusDays(i); addedDate = Integer.parseInt(String.format("%d%02d%02d", dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth())); break; case MONTHLY: dt = dt.plusMonths(i); addedDate = Integer .parseInt(String.format("%d%02d", dt.getYear(), dt.getMonthOfYear())); break; case YEARLY: dt = dt.plusYears(i); addedDate = Integer.parseInt(String.format("%d", dt.getYear())); break; default: throw new UnsupportedAutoIndexException( "Given index is not (DAILY or MONTHLY or YEARLY), please check your configuration."); } if (config.isDebugEnabled()) logger.debug("Added Date = " + addedDate); if (!esTransportClient.admin().indices() .prepareExists(indexMetadata.getIndexName() + addedDate).execute() .actionGet(config.getAutoCreateIndexTimeout()).isExists()) { esTransportClient.admin().indices() .prepareCreate(indexMetadata.getIndexName() + addedDate).execute() .actionGet(config.getAutoCreateIndexTimeout()); logger.info(indexMetadata.getIndexName() + addedDate + " is created"); } else { //TODO: Change to Debug after Testing logger.warn(indexMetadata.getIndexName() + addedDate + " already exists"); } } } } } else { logger.info("No existing indices, hence can not pre-create any indices"); } }
From source file:com.netflix.raigad.indexmanagement.IndexUtils.java
License:Apache License
public static int getPastRetentionCutoffDate(IndexMetadata indexMetadata) throws UnsupportedAutoIndexException { DateTime dt = new DateTime(); int currentDate; switch (indexMetadata.getRetentionType()) { case DAILY:/*from w w w . j a v a2 s. co m*/ dt = dt.minusDays(indexMetadata.getRetentionPeriod()); currentDate = Integer .parseInt(String.format("%d%02d%02d", dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth())); break; case MONTHLY: dt = dt.minusMonths(indexMetadata.getRetentionPeriod()); currentDate = Integer.parseInt(String.format("%d%02d", dt.getYear(), dt.getMonthOfYear())); break; case YEARLY: dt = dt.minusYears(indexMetadata.getRetentionPeriod()); currentDate = Integer.parseInt(String.format("%d", dt.getYear())); break; default: throw new UnsupportedAutoIndexException( "Given index is not (DAILY or MONTHLY or YEARLY), please check your configuration."); } return currentDate; }
From source file:com.netflix.raigad.indexmanagement.IndexUtils.java
License:Apache License
public static int getFutureRetentionDate(IndexMetadata indexMetadata) throws UnsupportedAutoIndexException { DateTime dt = new DateTime(); int currentDate; switch (indexMetadata.getRetentionType()) { case DAILY:/*from w ww . ja v a2 s.c o m*/ dt = dt.plusDays(indexMetadata.getRetentionPeriod()); currentDate = Integer .parseInt(String.format("%d%02d%02d", dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth())); break; case MONTHLY: dt = dt.plusMonths(indexMetadata.getRetentionPeriod()); currentDate = Integer.parseInt(String.format("%d%02d", dt.getYear(), dt.getMonthOfYear())); break; case YEARLY: dt = dt.plusYears(indexMetadata.getRetentionPeriod()); currentDate = Integer.parseInt(String.format("%d", dt.getYear())); break; default: throw new UnsupportedAutoIndexException( "Given index is not (DAILY or MONTHLY or YEARLY), please check your configuration."); } return currentDate; }
From source file:com.ning.billing.meter.timeline.consumer.AccumulatorSampleConsumer.java
License:Apache License
@Override public void processOneSample(final DateTime time, final SampleOpcode opcode, final Object value) { // Round the sample timestamp according to the aggregation mode final long millis = time.toDateTime(DateTimeZone.UTC).getMillis(); final DateTime roundedTime; switch (timeAggregationMode) { case SECONDS: roundedTime = new DateTime((millis / 1000) * 1000L, DateTimeZone.UTC); break;// w w w. j a va2 s .com case MINUTES: roundedTime = new DateTime((millis / (60 * 1000)) * 60 * 1000L, DateTimeZone.UTC); break; case HOURS: roundedTime = new DateTime((millis / (60 * 60 * 1000)) * 60 * 60 * 1000L, DateTimeZone.UTC); break; case DAYS: roundedTime = new DateTime((millis / (24 * 60 * 60 * 1000)) * 24 * 60 * 60 * 1000L, DateTimeZone.UTC); break; case MONTHS: roundedTime = new DateTime(time.getYear(), time.getMonthOfYear(), 1, 0, 0, 0, 0, DateTimeZone.UTC); break; case YEARS: roundedTime = new DateTime(time.getYear(), 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); break; default: roundedTime = time; break; } // Get the sample value to aggregate // TODO Should we ignore conversion errors (e.g. Strings)? final double doubleValue = ScalarSample.getDoubleValue(opcode, value); // Output if it's not the first value and the current rounded time differ from the previous one if (lastRoundedTime != null && !lastRoundedTime.equals(roundedTime)) { outputAndResetAccumulators(); } // Perform (or restart) the aggregation if (accumulators.get(opcode) == null) { accumulators.put(opcode, Double.valueOf("0")); } accumulators.put(opcode, accumulators.get(opcode) + doubleValue); lastRoundedTime = roundedTime; }
From source file:com.njlabs.amrita.aid.gpms.ui.PassApplyActivity.java
License:Open Source License
private void loadDateTimePicker(final DateTime startDate, final View v, final String toModify) { MonthAdapter.CalendarDay calendarDay = new MonthAdapter.CalendarDay(); calendarDay.setDay(startDate.getYear(), startDate.getMonthOfYear() - 1, startDate.getDayOfMonth()); CalendarDatePickerDialogFragment cdp = new CalendarDatePickerDialogFragment() .setOnDateSetListener(new CalendarDatePickerDialogFragment.OnDateSetListener() { @Override// ww w .j ava2 s . c om public void onDateSet(CalendarDatePickerDialogFragment dialog, final int year, final int monthOfYear, final int dayOfMonth) { RadialTimePickerDialogFragment rtpd = new RadialTimePickerDialogFragment() .setOnTimeSetListener(new RadialTimePickerDialogFragment.OnTimeSetListener() { @Override public void onTimeSet(RadialTimePickerDialogFragment dialog, int hourOfDay, int minute) { Ln.d(minute); boolean error = false; DateTime selectedDateTime = new DateTime(year, monthOfYear + 1, dayOfMonth, hourOfDay, minute); if (toModify.equals("fromDate")) { fromDate = selectedDateTime; findViewById(R.id.to_date_btn).setEnabled(true); } else if (toModify.equals("toDate")) { toDate = selectedDateTime; if (toDate.getMillis() <= fromDate.getMillis()) { error = true; Snackbar.make(parentView, "The end date should be after the from date.", Snackbar.LENGTH_LONG).show(); } } if (!error) { ((Button) v).setText(selectedDateTime.toString(Gpms.dateFormat)); } } }).setStartTime(startDate.getHourOfDay(), (startDate.getMinuteOfHour() - 1 == -1 ? 0 : startDate.getMinuteOfHour() - 1)) .setThemeDark(false); rtpd.show(getSupportFragmentManager(), "FRAG_TAG_TIME_PICKER"); } }).setFirstDayOfWeek(Calendar.SUNDAY) .setPreselectedDate(startDate.getYear(), startDate.getMonthOfYear() - 1, startDate.getDayOfMonth()) .setDateRange(calendarDay, null).setThemeLight(); cdp.show(getSupportFragmentManager(), "FRAG_TAG_DATE_PICKER"); }
From source file:com.pureblue.quant.util.frequency.Daily.java
@Override public DateTime periodBegin(DateTime t) { DateTime currentDayStart = new DateTime(t.getYear(), t.getMonthOfYear(), t.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), t.getZone());/*from w w w . j ava 2s.c o m*/ if (currentDayStart.isAfter(t)) { return currentDayStart.minusDays(1); } else { return currentDayStart; } }
From source file:com.pureblue.quant.util.frequency.Hourly.java
@Override public DateTime periodBegin(DateTime time) { return new DateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), time.getHourOfDay(), 0, 0, 0, time.getZone());// w w w. j a v a 2s . c o m }
From source file:com.pureblue.quant.util.frequency.Minute.java
@Override public DateTime periodBegin(DateTime time) { return new DateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), 0, 0, time.getZone()); }
From source file:com.pureblue.quant.util.frequency.Monthly.java
@Override public DateTime periodBegin(DateTime time) { return new DateTime(time.getYear(), time.getMonthOfYear(), 1, 0, 0, 0, 0, time.getZone()); }
From source file:com.pureblue.quant.util.frequency.Quarterly.java
@Override public DateTime periodBegin(DateTime time) { return new DateTime(time.getYear(), time.getMonthOfYear() - ((time.getMonthOfYear() - 1) % 3), 1, 0, 0, 0, 0, time.getZone());/*from w w w .j av a 2 s . c o m*/ }