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:org.springframework.ws.samples.airline.schema.support.SchemaConversionUtils.java

License:Apache License

public static XMLGregorianCalendar toXMLGregorianCalendar(LocalDate localDate)
        throws DatatypeConfigurationException {
    DatatypeFactory factory = DatatypeFactory.newInstance();
    return factory.newXMLGregorianCalendarDate(localDate.getYear(), localDate.getMonthOfYear(),
            localDate.getDayOfMonth(), DatatypeConstants.FIELD_UNDEFINED);
}

From source file:org.springsource.restbucks.payment.CreditCard.java

License:Apache License

/**
 * Protected setter to allow binding the expiration date.
 * /*from  w  w  w  .jav  a  2s. co m*/
 * @param date
 */
protected void setExpirationDate(LocalDate date) {

    this.expiryYear = Years.years(date.getYear());
    this.expiryMonth = Months.months(date.getMonthOfYear());
}

From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java

License:Apache License

protected CalendarItem[] buildDayItems() {

    LocalDate calendarFirstDay = getCalendarFirstDay();
    LocalDate calendarLastDay = getCalendarLastDay();

    LocalDate firstDayOfMonth = yearMonthDisplayed.toLocalDate(1);
    LocalDate lastDayOfMonth = yearMonthDisplayed.toLocalDate(1).dayOfMonth().withMaximumValue();

    LocalDate today = LocalDate.now();
    int numberOfDays = Days.daysBetween(calendarFirstDay, calendarLastDay).getDays() + 1;
    LocalDate date = calendarFirstDay;

    CalendarItem[] calendarItems = new CalendarItem[numberOfDays];
    LocalDate currentValue = getLocalDate();
    for (int i = 0; i < numberOfDays; i++, date = date.plusDays(1)) {
        calendarItems[i] = new CalendarItem();

        calendarItems[i].setIndex(i);/*from  w  w  w. j ava  2  s .  c  om*/
        if (date.getMonthOfYear() == yearMonthDisplayed.getMonthOfYear()) {
            calendarItems[i].setRelativeDateIndex(date.getDayOfMonth());
        } else {
            calendarItems[i].setRelativeDateIndex(-date.getDayOfMonth());
        }

        String calendarItemContent = null;
        if (cellItemCustomizer != null) {
            calendarItemContent = cellItemCustomizer.renderDay(date, this);
        }

        // fallback to default value
        if (calendarItemContent == null) {
            calendarItemContent = Integer.toString(date.getDayOfMonth());
        }
        calendarItems[i].setText(calendarItemContent);

        StringBuilder style = new StringBuilder();

        if (date.equals(today)) {
            style.append("today ");
        }

        if (currentValue != null && date.equals(currentValue)) {
            style.append("selected ");
        }

        if (date.isBefore(firstDayOfMonth)) {
            style.append("previousmonth ");
            calendarItems[i].setEnabled(!isPreviousMonthDisabled());
        } else if (date.isAfter(lastDayOfMonth)) {
            style.append("nextmonth ");
            calendarItems[i].setEnabled(!isNextMonthDisabled());
        } else {
            style.append("currentmonth ");
            calendarItems[i].setEnabled(isDateEnabled(date));
        }

        if (isWeekend(date)) {
            style.append("weekend ");
        }

        if (cellItemCustomizer != null) {
            String generatedStyle = cellItemCustomizer.getStyle(date, this);
            if (generatedStyle != null) {
                style.append(generatedStyle);
                style.append(" ");
            }

            String tooltip = cellItemCustomizer.getTooltip(date, this);
            if (tooltip != null) {
                calendarItems[i].setTooltip(tooltip);
            }
        }

        String computedStyle = style.toString();
        if (!computedStyle.isEmpty()) {
            calendarItems[i].setStyle(computedStyle);
        }
    }
    return calendarItems;
}

From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java

License:Apache License

protected CalendarItem[] buildMonthItems() {

    YearMonth calendarFirstMonth = getCalendarFirstMonth();
    YearMonth calendarLastMonth = getCalendarLastMonth();

    YearMonth currentMonth = YearMonth.now();

    int numberOfMonths = Months.monthsBetween(calendarFirstMonth, calendarLastMonth).getMonths() + 1;

    CalendarItem[] calendarItems = new CalendarItem[numberOfMonths];
    YearMonth month = calendarFirstMonth;
    LocalDate currentValue = getLocalDate();
    YearMonth currentYearMonthValue = currentValue == null ? null
            : new YearMonth(currentValue.getYear(), currentValue.getMonthOfYear());
    for (int i = 0; i < numberOfMonths; i++, month = month.plusMonths(1)) {
        calendarItems[i] = new CalendarItem();

        calendarItems[i].setIndex(i);/*from   w ww  .  j ava  2 s.c  o  m*/
        calendarItems[i].setRelativeDateIndex(month.getMonthOfYear());
        calendarItems[i].setEnabled(true); // By default

        StringBuilder style = new StringBuilder("");

        if (month.equals(currentMonth)) {
            style.append("currentmonth ");
        }

        if (currentYearMonthValue != null && month.equals(currentYearMonthValue)) {
            style.append("selected ");
        }

        if (cellItemCustomizer != null) {
            String generatedStyle = cellItemCustomizer.getStyle(month, this);
            if (generatedStyle != null) {
                style.append(generatedStyle);
                style.append(" ");
            }

            String tooltip = cellItemCustomizer.getTooltip(month, this);
            if (tooltip != null) {
                calendarItems[i].setTooltip(tooltip);
            }
        }

        if (isMonthEnabled(month)) {
            calendarItems[i].setEnabled(true);
        }

        String computedStyle = style.toString();
        if (!computedStyle.isEmpty()) {
            calendarItems[i].setStyle(computedStyle);
        }

        String calendarItemContent = null;
        if (cellItemCustomizer != null) {
            calendarItemContent = cellItemCustomizer.renderMonth(currentYearMonthValue, this);
        }
        // fallback to default value
        if (calendarItemContent == null) {
            calendarItemContent = shortMonthTexts[i];
        }

        calendarItems[i].setText(calendarItemContent);
    }
    return calendarItems;
}

From source file:org.zkoss.ganttz.timetracker.zoom.DetailThreeTimeTrackerState.java

License:Open Source License

@Override
protected LocalDate round(LocalDate date, boolean down) {
    if ((date.getMonthOfYear() == 1 || date.getMonthOfYear() == 7) && date.getDayOfMonth() == 1) {
        return date;
    }/*w  w w  .jav a  2s  .c o  m*/

    date = date.withDayOfMonth(1);

    if (date.getMonthOfYear() < 7) {
        return down ? date.withMonthOfYear(1) : date.withMonthOfYear(7);
    } else {
        return down ? date.withMonthOfYear(7) : date.plusYears(1).withMonthOfYear(1);
    }
}

From source file:pt.ist.expenditureTrackingSystem.domain.EmailDigesterUtil.java

License:Open Source License

private static Stream<Person> getPeopleToProcess() {
    Stream<Person> people;/*ww  w. j  a va  2  s  .  co  m*/

    final LocalDate today = new LocalDate();
    final ExpenditureTrackingSystem instance = ExpenditureTrackingSystem.getInstance();

    people = instance.getAuthorizationsSet().stream().filter(a -> a.isValidFor(today)).map(a -> a.getPerson());

    for (final RoleType roleType : RoleType.values()) {
        people = Stream.concat(people, peopleWithRole(roleType));
    }

    for (final AccountingUnit accountingUnit : instance.getAccountingUnitsSet()) {
        people = Stream.concat(people, accountingUnit.getPeopleSet().stream());
        people = Stream.concat(people, accountingUnit.getProjectAccountantsSet().stream());
        people = Stream.concat(people, accountingUnit.getResponsiblePeopleSet().stream());
        people = Stream.concat(people, accountingUnit.getResponsibleProjectAccountantsSet().stream());
        people = Stream.concat(people, accountingUnit.getTreasuryMembersSet().stream());
    }

    final PaymentProcessYear paymentProcessYear = PaymentProcessYear
            .getPaymentProcessYearByYear(Calendar.getInstance().get(Calendar.YEAR));
    people = Stream.concat(people, requestors(paymentProcessYear));
    if (today.getMonthOfYear() == Month.JANUARY) {
        final PaymentProcessYear previousYear = PaymentProcessYear
                .getPaymentProcessYearByYear(Calendar.getInstance().get(Calendar.YEAR) - 1);
        people = Stream.concat(people, requestors(previousYear));
    }

    return people.filter(p -> p.getOptions().getReceiveNotificationsByEmail()).distinct();
}

From source file:py.com.palermo.servicioarthy.impl.gestioncomercial.PortalGeneralService.java

public Meta getMetaActual(Vendedor v) throws AccesoDenegadoException {

    Meta R = null;/*from   w ww  .  j a  v  a  2s .  c o  m*/
    if (v != null) {

        String refExterna = v.getEmpresasid() + "," + v.getSucursalesid() + "," + v.getVendedorid();
        LocalDate localDate = new LocalDate();
        int mes = localDate.getMonthOfYear();
        int anio = localDate.getYear();
        try {
            R = (Meta) em.createQuery(
                    "SELECT m from Meta m  WHERE m.estado = 'ACTIVO' AND m.refExterna = ?1 AND m.mes = ?2 AND m.anio = ?3")
                    .setParameter(1, refExterna).setParameter(2, mes).setParameter(3, anio).getSingleResult();

            R.setDiasTrabajados(ConsultasPalermo.calculaDiasTrabajados(new Date()));
            R.setEmpresaId(v.getEmpresasid());
            R.setSucursalId(v.getSucursalesid());
            R.setVendedorId(new Integer(v.getVendedorid()));
            R.setCantidadAlcanzada(0d);

        } catch (Exception e) {
            System.err.println("No hay metas para este vendedor: " + e.getMessage());
        }
    }
    return R;
}

From source file:rabbit.data.internal.xml.DataStore.java

License:Apache License

@Override
public List<File> getDataFiles(LocalDate start, LocalDate end, IPath location) {
    // Work out the number of months between the two dates, regardless of the
    // dateOfMonth of each date:
    int numMonths = (end.getYear() - start.getYear()) * 12;
    numMonths += end.getMonthOfYear() - start.getMonthOfYear();

    List<File> result = Lists.newLinkedList();
    for (; numMonths >= 0; numMonths--) {
        File f = getDataFile(end.minusMonths(numMonths), location);
        if (f.exists()) {
            result.add(f);/*w  w w .  j  a  v a2s .com*/
        }
    }
    return result;
}

From source file:rabbit.data.internal.xml.DatatypeUtil.java

License:Apache License

/**
 * Checks whether the two dates are representing the same year and same month.
 * /*from   w  w w .ja v  a 2 s . com*/
 * @param cal1 The first date.
 * @param cal2 The second date.
 * @return True if both dates are representing the same year and same month.
 */
public static boolean isSameMonthInYear(DateTime cal1, LocalDate cal2) {
    return (cal1.getYear() == cal2.getYear()) && (cal1.getMonthOfYear() == cal2.getMonthOfYear());
}

From source file:rabbit.data.internal.xml.DatatypeUtil.java

License:Apache License

/**
 * Converts a {@link LocalDate} to {@link XMLGregorianCalendar}. The
 * converted calendar is a date, which means only the year, month and day of
 * month fields are set.// ww  w  .  j  a  v a 2 s.c  o  m
 * 
 * @param cal The calendar to convert from.
 * @return The converted calendar.
 */
public static XMLGregorianCalendar toXmlDate(LocalDate cal) {
    return datatypeFactory.newXMLGregorianCalendarDate(cal.getYear(), cal.getMonthOfYear(), cal.getDayOfMonth(),
            DatatypeConstants.FIELD_UNDEFINED);
}