Example usage for org.joda.time LocalDate getMonthOfYear

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

Introduction

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

Prototype

public int getMonthOfYear() 

Source Link

Document

Get the month of year field value.

Usage

From source file:at.jclehner.rxdroid.preferences.DatePreference.java

License:Open Source License

@TargetApi(11)
@Override/*  w ww . ja va2s .  com*/
protected View onCreateDialogView() {
    final LocalDate value = getValue();
    final DatePicker picker = new DatePicker(getThemedContext());

    if (Version.SDK_IS_HONEYCOMB_OR_NEWER)
        picker.setMinDate(mToday.toDate().getTime());

    picker.init(value.getYear(), value.getMonthOfYear() - 1, value.getDayOfMonth(), this);

    return picker;
}

From source file:at.jclehner.rxdroid.util.Util.java

License:Open Source License

@TargetApi(11)
public static AlertDialog createDatePickerDialog(Context context, LocalDate date,
        final DatePickerDialog.OnDateSetListener listener) {
    final DatePicker picker = new DatePicker(context);
    picker.init(date.getYear(), date.getMonthOfYear() - 1, date.getDayOfMonth(), null);
    if (Version.SDK_IS_HONEYCOMB_OR_NEWER && !context.getResources().getBoolean(R.bool.is_tablet))
        picker.setCalendarViewShown(false);

    final AlertDialog.Builder ab = new AlertDialog.Builder(context);
    ab.setView(picker);//from www  .  j  a  v  a  2  s  .c o m
    ab.setNegativeButton(android.R.string.cancel, null);
    ab.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            listener.onDateSet(picker, picker.getYear(), picker.getMonth(), picker.getDayOfMonth());
        }
    });

    return ab.create();
}

From source file:cache.BreakerCache.java

Vector<ElectricalValue> get_data(Breaker breaker, LocalDate startDate, LocalDate endDate, BaseCache cache)
        throws NoActiveDbConnectionException, NoItemSelectedException {
    Vector<ElectricalValue> toreturn = new Vector<>();
    LocalDate currdate = null;

    int cacheditems = 0;
    int totalitems = 0;

    currdate = new LocalDate(startDate);
    while (currdate.isBefore(endDate)) {

        YearCache wanted_year = null;/*www  . j  a  v a  2  s  .  c om*/
        for (YearCache yc : years) {
            if (yc.year == currdate.getYear()) {
                wanted_year = yc;
                break;
            }

        }
        if (wanted_year == null) {

            wanted_year = new YearCache(currdate.getYear());
            years.add(wanted_year);

        }

        MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
        DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

        if (wanted_day.data != null) {
            cacheditems++;
        }
        totalitems++;

        currdate = currdate.plusDays(1);
    }

    if (cacheditems / totalitems > 0.9) {

        currdate = new LocalDate(startDate);
        while (currdate.isBefore(endDate)) {

            YearCache wanted_year = null;
            for (YearCache yc : years) {
                if (yc.year == currdate.getYear()) {
                    wanted_year = yc;
                    break;
                }

            }
            if (wanted_year == null) {

                wanted_year = new YearCache(currdate.getYear());
                years.add(wanted_year);

            }

            MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
            DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

            cache.cache_day(wanted_day);
            if (wanted_day.data == null) {
                wanted_day.data = LoadDataFromDB.get_data(breaker, currdate, currdate.plusDays(1));
            }
            toreturn.addAll(wanted_day.data);
            currdate = currdate.plusDays(1);

        }
    } else {
        toreturn = LoadDataFromDB.get_data(breaker, startDate, endDate);

        currdate = new LocalDate(startDate);

        YearCache wanted_year = null;
        for (YearCache yc : years) {
            if (yc.year == currdate.getYear()) {
                wanted_year = yc;
                break;
            }

        }
        if (wanted_year == null) {
            wanted_year = new YearCache(currdate.getYear());
            years.add(wanted_year);
        }

        MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
        DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

        currdate = currdate.plusDays(1);

        Vector<ElectricalValue> daydata = new Vector<>();
        for (int i = 0; i < toreturn.size(); i++) {
            if (toreturn.get(i).datetime.toLocalDate().isBefore(currdate)) {
                daydata.add(toreturn.get(i));

            } else {

                if (daydata.size() > 0) {
                    wanted_day.data = daydata;
                    cache.cache_day(wanted_day);
                    daydata = new Vector<>();
                }

                wanted_year = null;
                for (YearCache yc : years) {
                    if (yc.year == currdate.getYear()) {
                        wanted_year = yc;
                        break;
                    }

                }
                if (wanted_year == null) {
                    wanted_year = new YearCache(currdate.getYear());
                    years.add(wanted_year);
                }

                wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
                wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

                currdate = currdate.plusDays(1);

            }

        }

    }
    return toreturn;
}

From source file:cache.TransformerCache.java

Vector<ElectricalValue> get_data(Transformer transformer, LocalDate startDate, LocalDate endDate,
        BaseCache cache) throws NoActiveDbConnectionException, NoItemSelectedException {
    Vector<ElectricalValue> toreturn = new Vector<>();
    LocalDate currdate = null;

    int cacheditems = 0;
    int totalitems = 0;

    currdate = new LocalDate(startDate);
    while (currdate.isBefore(endDate)) {

        YearCache wanted_year = null;/*ww w. j a  v a 2 s .c o m*/
        for (YearCache yc : years) {
            if (yc.year == currdate.getYear()) {
                wanted_year = yc;
                break;
            }

        }
        if (wanted_year == null) {

            wanted_year = new YearCache(currdate.getYear());
            years.add(wanted_year);

        }

        MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
        DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

        if (wanted_day.data != null) {
            cacheditems++;
        }
        totalitems++;

        currdate = currdate.plusDays(1);
    }

    if (cacheditems / totalitems > 0.9) {

        currdate = new LocalDate(startDate);
        while (currdate.isBefore(endDate)) {

            YearCache wanted_year = null;
            for (YearCache yc : years) {
                if (yc.year == currdate.getYear()) {
                    wanted_year = yc;
                    break;
                }

            }
            if (wanted_year == null) {

                wanted_year = new YearCache(currdate.getYear());
                years.add(wanted_year);

            }

            MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
            DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

            cache.cache_day(wanted_day);
            if (wanted_day.data == null) {
                wanted_day.data = LoadDataFromDB.get_data(transformer, currdate, currdate.plusDays(1));
            }
            toreturn.addAll(wanted_day.data);
            currdate = currdate.plusDays(1);

        }
    } else {
        toreturn = LoadDataFromDB.get_data(transformer, startDate, endDate);

        currdate = new LocalDate(startDate);

        YearCache wanted_year = null;
        for (YearCache yc : years) {
            if (yc.year == currdate.getYear()) {
                wanted_year = yc;
                break;
            }

        }
        if (wanted_year == null) {
            wanted_year = new YearCache(currdate.getYear());
            years.add(wanted_year);
        }

        MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
        DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

        currdate = currdate.plusDays(1);

        Vector<ElectricalValue> daydata = new Vector<>();
        for (int i = 0; i < toreturn.size(); i++) {
            if (toreturn.get(i).datetime.toLocalDate().isBefore(currdate)) {
                daydata.add(toreturn.get(i));

            } else {

                if (daydata.size() > 0) {
                    wanted_day.data = daydata;
                    cache.cache_day(wanted_day);
                    daydata = new Vector<>();
                }

                wanted_year = null;
                for (YearCache yc : years) {
                    if (yc.year == currdate.getYear()) {
                        wanted_year = yc;
                        break;
                    }

                }
                if (wanted_year == null) {
                    wanted_year = new YearCache(currdate.getYear());
                    years.add(wanted_year);
                }

                wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
                wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

                currdate = currdate.plusDays(1);

            }

        }

    }
    return toreturn;
}

From source file:cherry.goods.util.JodaTimeUtil.java

License:Apache License

/**
 * @param ldt ???{@link LocalDate}/*  w  ww. java2 s.  co m*/
 * @return ?????{@link Calendar}(?)????????(?00:00:00.000)
 */
public static Calendar getCalendar(LocalDate ldt) {
    Calendar cal = Calendar.getInstance();
    cal.set(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), 0, 0, 0);
    cal.set(MILLISECOND, 0);
    return cal;
}

From source file:cherry.goods.util.LocalDateUtil.java

License:Apache License

/**
 * (??)?????(Y/M/1?)???/*from  w w w . jav  a  2s .c om*/
 * 
 * @param dt ??
 * @return (??)???
 */
public static LocalDate normalizeYm(LocalDate dt) {
    if (dt == null) {
        return null;
    }
    return new LocalDate(dt.getYear(), dt.getMonthOfYear(), 1);
}

From source file:Classes.HijriTime.java

License:Open Source License

public String getHijriTime() {////get final translated hijri date
    this.dayFormatter = new DecimalFormat("00");
    this.yearFormatter = new DecimalFormat("0000");

    Chronology iSOChronology = ISOChronology.getInstanceUTC();//get ISOChronology instance
    Chronology islamicChronology = IslamicChronology.getInstanceUTC();//get IslamicChronology instance

    LocalDate localDateISOChronology = new LocalDate(year, month, day, iSOChronology);//get local date
    LocalDate HijriDate = new LocalDate(localDateISOChronology.toDate(), islamicChronology);//get hijri date

    return hijriDaysNames[calendar.get(Calendar.DAY_OF_WEEK)] + " "
            + dayFormatter.format(HijriDate.getDayOfMonth()) + " "
            + hijriMonthsNames[HijriDate.getMonthOfYear()] + " " + yearFormatter.format(HijriDate.getYear());
}

From source file:com.alliander.osgp.domain.core.valueobjects.smartmetering.CosemDate.java

License:Open Source License

public CosemDate(final LocalDate date) {
    this(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), DAY_OF_WEEK_NOT_SPECIFIED);
}

From source file:com.alliander.osgp.dto.valueobjects.smartmetering.CosemDateDto.java

License:Open Source License

public CosemDateDto(final LocalDate date) {
    this(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), DAY_OF_WEEK_NOT_SPECIFIED);
}

From source file:com.axelor.apps.cash.management.service.ForecastRecapService.java

License:Open Source License

public void populateWithSalaries(ForecastRecap forecastRecap) {
    List<Employee> employeeList = new ArrayList<Employee>();
    if (forecastRecap.getBankDetails() != null) {
        employeeList = Beans.get(EmployeeRepository.class).all()
                .filter("self.user.activeCompany = ?1 AND self.bankDetails = ?2", forecastRecap.getCompany(),
                        forecastRecap.getBankDetails())
                .fetch();//  ww w.  j  a  v a 2  s .  c  o m
    } else {
        employeeList = Beans.get(EmployeeRepository.class).all()
                .filter("self.user.activeCompany = ?1", forecastRecap.getCompany()).fetch();
    }
    LocalDate itDate = new LocalDate(forecastRecap.getFromDate());
    while (!itDate.isAfter(forecastRecap.getToDate())) {
        if (itDate.isEqual(new LocalDate(itDate.getYear(), itDate.getMonthOfYear(),
                itDate.dayOfMonth().getMaximumValue()))) {
            for (Employee employee : employeeList) {
                forecastRecap.setCurrentBalance(forecastRecap.getCurrentBalance().subtract(employee
                        .getHourlyRate().multiply(employee.getWeeklyWorkHours().multiply(new BigDecimal(4)))));
                forecastRecap.addForecastRecapLineListItem(this.createForecastRecapLine(itDate, 2, null,
                        employee.getHourlyRate()
                                .multiply(employee.getWeeklyWorkHours().multiply(new BigDecimal(4))),
                        forecastRecap.getCurrentBalance()));
            }
            itDate = itDate.plusMonths(1);
        } else {
            itDate = new LocalDate(itDate.getYear(), itDate.getMonthOfYear(),
                    itDate.dayOfMonth().getMaximumValue());
        }
    }
}