Example usage for org.joda.time DateTime getMonthOfYear

List of usage examples for org.joda.time DateTime getMonthOfYear

Introduction

In this page you can find the example usage for org.joda.time DateTime getMonthOfYear.

Prototype

public int getMonthOfYear() 

Source Link

Document

Get the month of year field value.

Usage

From source file:com.mvcoding.financius.feature.DateDialogFragment.java

License:Open Source License

public static Observable<DateDialogResult> show(@NonNull FragmentManager fragmentManager, int requestCode,
        @NonNull RxBus rxBus, long timestamp) {
    final DateTime date = new DateTime(timestamp);
    return show(fragmentManager, requestCode, rxBus, date.getYear(), date.getMonthOfYear(),
            date.getDayOfMonth());/*from w ww.  ja  va2 s  .  co  m*/
}

From source file:com.mvcoding.financius.feature.transaction.TransactionActivity.java

License:Open Source License

@NonNull
@Override//  www  . j  a v a  2 s  .  c  o  m
public Observable<Long> onDateChanged() {
    final Observable<Long> dateObservable = rxBus.observe(DateDialogFragment.DateDialogResult.class)
            .mergeWith(RxView.clicks(dateButton).flatMap(o -> DateDialogFragment
                    .show(getSupportFragmentManager(), REQUEST_DATE, rxBus, transaction.getDate())))
            .map(dateDialogResult -> {
                final DateTime dateTime = new DateTime(transaction.getDate());
                return new DateTime(dateDialogResult.getYear(), dateDialogResult.getMonthOfYear(),
                        dateDialogResult.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour())
                                .getMillis();
            });

    final Observable<Long> timeObservable = rxBus.observe(TimeDialogFragment.TimeDialogResult.class)
            .mergeWith(RxView.clicks(timeButton).flatMap(o -> TimeDialogFragment
                    .show(getSupportFragmentManager(), REQUEST_TIME, rxBus, transaction.getDate())))
            .map(timeDialogResult -> {
                final DateTime dateTime = new DateTime(transaction.getDate());
                return new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                        timeDialogResult.getHourOfDay(), timeDialogResult.getMinuteOfHour()).getMillis();
            });

    return Observable.merge(dateObservable, timeObservable);
}

From source file:com.mycompany.login.mb.DateBean.java

public static void main(String[] args) {
    Date date = new Date();
    DateTime dateTime = new DateTime(date);
    DateTime dateTeste = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
            dateTime.getHourOfDay(), dateTime.getMinuteOfHour());

    // System.out.println("ANO: " + dateTime.getYear());
    // System.out.println("MES: " + dateTime.getMonthOfYear());
    // System.out.println("DIA: " + dateTime.getDayOfMonth());
    // System.out.println("HORA: " + dateTime.getHourOfDay());
    // System.out.println("MINUTO: " + dateTime.getMinuteOfHour());
    // System.out.println("Data Formatada:" + dateTime.getYear() + "/" + dateTime.getMonthOfYear() + "/" + dateTime.getDayOfMonth());
    //System.out.println(dateTeste.toString("YYYY-MM-dd HH:mm"));
    LocalDate local = new LocalDate(date);
    System.out.println("Local Date: " + local);

}

From source file:com.netflix.raigad.indexmanagement.ElasticSearchIndexManager.java

License:Apache License

/**
 * Courtesy Jae Bae/*from  ww w .j a v a 2s.  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   www .  j  ava2s.c  o  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:/*  w ww . ja  v a  2s . 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;//from   w  w  w.j  a va  2 s.c  o m
    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/*from w  w w.  j  ava2  s.c o m*/
                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());//  w  ww  .  ja v a  2  s  .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());//  ww  w . ja  v  a2s  .c o m
}