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:com.tkmtwo.sarapi.convert.LocalDateToValueConverter.java

License:Apache License

@Override
public Value convert(LocalDate ld) {
    if (ld == null) {
        return new Value();
    }/*from   w  ww . j  a  v a  2 s  .c  om*/
    DateInfo di = new DateInfo(ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth());
    return new Value(di);
}

From source file:cz.krtinec.birthday.dto.Event.java

License:Open Source License

public Event(String displayName, long contactId, LocalDate eventDate, String lookupKey, DateIntegrity integrity,
        long rawContactId) {
    this.integrity = integrity;
    this.displayName = displayName;
    this.contactId = contactId;
    this.lookupKey = lookupKey;
    this.eventDate = eventDate;

    if (this.eventDate != null) {
        eventDaySort = SHORT_FORMAT.print(this.eventDate);
    } else {/*from   w ww. j a v  a2s .c o m*/
        eventDaySort = "0000";
    }

    nextYear = eventDaySort.compareTo(pivot) < 0;

    if (this.eventDate != null) {
        int year = nextYear ? today.getYear() + 1 : today.getYear();
        LocalDate tempCalendar;
        try {
            tempCalendar = new LocalDate(year, eventDate.getMonthOfYear(), eventDate.getDayOfMonth());
        } catch (IllegalFieldValueException e) {
            //Probably February 29th
            tempCalendar = new LocalDate(year, eventDate.getMonthOfYear(), eventDate.getDayOfMonth() - 1);
        }
        daysToEvent = Days.daysBetween(today, tempCalendar).getDays();
    }
    this.rawContactId = rawContactId;
}

From source file:cz.krtinec.birthday.dto.Zodiac.java

License:Open Source License

public static Zodiac toZodiac(LocalDate birthday) {
    for (Zodiac zodiac : values()) {
        LocalDate fromWithYear = zodiac.from.withYear(birthday.getYear());
        LocalDate toWithYear = zodiac.to.withYear(birthday.getYear());

        if (birthday.getMonthOfYear() == 12 && Zodiac.CAPRICORN.equals(zodiac)) {
            toWithYear = toWithYear.plusYears(1);
        } else if (birthday.getMonthOfYear() == 1 && Zodiac.CAPRICORN.equals(zodiac)) {
            fromWithYear = fromWithYear.minusYears(1);
        }//from   w ww . j  a v a 2 s. co  m

        if ((fromWithYear.isBefore(birthday) || fromWithYear.isEqual(birthday))
                && (toWithYear.isAfter(birthday) || toWithYear.isEqual(birthday))) {
            return zodiac;
        }
    }

    throw new IllegalArgumentException("Cannot find zodiac sign for date: " + birthday);
}

From source file:DB_data_loader.LoadDataFromDB.java

public static Vector<ElectricalValue> get_data(DataItem item, LocalDate start_date, LocalDate end_date)
        throws NoActiveDbConnectionException, NoItemSelectedException {

    Vector<ElectricalValue> data = new Vector<ElectricalValue>();

    if (item != null) {
        String startdate = "'" + start_date.getYear() + "-" + start_date.getMonthOfYear() + "-"
                + start_date.getDayOfMonth() + "'";
        String enddate;/*from  w ww . j a va2s. com*/
        enddate = "'" + end_date.getYear() + "-" + end_date.getMonthOfYear() + "-" + end_date.getDayOfMonth()
                + "'";

        if (item.getClass() == Breaker.class) {
            Breaker b = (Breaker) item;
            if (conn != null) {
                try {

                    String query = "SELECT datetime,current FROM breaker_data " + " where datetime  BETWEEN  "
                            + startdate + " and " + enddate + " and Breaker_ID = " + b.id + ";";

                    Statement stmt = conn.conn.createStatement();
                    stmt.execute(query);

                    ResultSet rs = stmt.getResultSet();

                    while (rs.next()) {
                        data.add(new ElectricalValue(new DateTime(rs.getTimestamp(1)), rs.getFloat(2)));
                    }
                    return data;
                } catch (SQLException ex) {

                    System.out.println("bad query");
                    System.out.println(ex.getMessage());

                }
            }
            throw new NoItemSelectedException();
        } else {
            if (item.getClass() == Transformer.class) {
                Transformer t = (Transformer) item;
                if (conn != null) {
                    try {

                        String query = "SELECT datetime,current FROM transformer_data "
                                + " where datetime  BETWEEN  " + startdate + " and " + enddate
                                + " and Transformer_ID = " + t.id + ";";

                        Statement stmt = conn.conn.createStatement();
                        stmt.execute(query);
                        ResultSet rs = stmt.getResultSet();
                        while (rs.next()) {
                            data.add(new ElectricalValue(new DateTime(rs.getTimestamp(1)), rs.getFloat(2)));
                        }
                        return data;
                    } catch (SQLException ex) {

                        System.out.println("bad query");
                        System.out.println(ex.getMessage());

                    }
                }
                throw new NoActiveDbConnectionException();
            }

        }
    }

    throw new NoItemSelectedException();
}

From source file:de.appsolve.padelcampus.controller.RootController.java

private void addPageEntries(Module module, ModelAndView mav) {
    List<PageEntry> pageEntries = pageEntryDAO.findByModule(module);
    mav.addObject("PageEntries", pageEntries);
    for (PageEntry pageEntry : pageEntries) {
        if (pageEntry.getShowEventCalendar()) {
            List<Event> events = eventDAO.findAllActiveStartingWith(LocalDate.now());
            List<JSEvent> jsEvents = new ArrayList<>();
            for (Event event : events) {
                jsEvents.add(new JSEvent(event));
            }//  w w w .j a va  2  s  . c  o m
            try {
                mav.addObject("Events", objectMapper.writeValueAsString(jsEvents));
            } catch (JsonProcessingException e) {
                LOG.error(e);
            }
            break;
        }
        if (pageEntry.getShowEventOverview()) {
            LocalDate today = LocalDate.now();
            List<Event> currentEvents = eventDAO.findAllActiveStartingWith(today);
            Map<Integer, ArrayList<Event>> eventMap = new TreeMap<>();
            for (Event event : currentEvents) {
                int monthOfYear = event.getStartDate().getMonthOfYear() - 1;
                if (eventMap.get(monthOfYear) == null) {
                    eventMap.put(monthOfYear, new ArrayList<>());
                }
                eventMap.get(monthOfYear).add(event);
            }

            // add passed events of current month AFTER upcoming events of current month
            LocalDate firstOfMonth = today.withDayOfMonth(1);
            int currentMonth = firstOfMonth.getMonthOfYear() - 1;
            List<Event> passedEvents = eventDAO.findAllActiveStartingWithEndingBefore(firstOfMonth, today);
            if (passedEvents != null && !passedEvents.isEmpty()) {
                if (eventMap.get(currentMonth) == null) {
                    eventMap.put(currentMonth, new ArrayList<>());
                }
                eventMap.get(currentMonth).addAll(passedEvents);
            }

            mav.addObject("EventMap", eventMap);
            mav.addObject("Today", today);
        }
    }
}

From source file:de.appsolve.padelcampus.utils.BookingUtil.java

public LocalDateTime getLocalDateTime(LocalDate selectedDate, LocalTime startTime) {
    return new LocalDateTime(selectedDate.getYear(), selectedDate.getMonthOfYear(),
            selectedDate.getDayOfMonth(), startTime.getHourOfDay(), startTime.getMinuteOfHour());
}

From source file:de.dreier.mytargets.features.training.edit.DatePickerFragment.java

License:Open Source License

@NonNull
@Override// w w  w.j a v a2  s .  c  o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current date as the default date in the picker
    LocalDate date = (LocalDate) getArguments().getSerializable(ARG_CURRENT_DATE);
    Assert.assertNotNull(date);

    // Create a new instance of DatePickerDialog and return it
    DatePickerDialog.OnDateSetListener listener = (DatePickerDialog.OnDateSetListener) getTargetFragment();
    return new DatePickerDialog(getActivity(), listener, date.getYear(), date.getMonthOfYear() - 1,
            date.getDayOfMonth());
}

From source file:de.fraunhofer.iosb.ilt.sta.persistence.postgres.PgExpressionHandler.java

License:Open Source License

@Override
public Expression<?> visit(DateConstant node) {
    LocalDate date = node.getValue();
    Calendar instance = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    instance.set(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
    ConstantDateExpression constant = new ConstantDateExpression(new java.sql.Date(instance.getTimeInMillis()));
    return constant;
}

From source file:de.ifgi.airbase.feeder.io.sos.http.AbstractTransactionalSosClient.java

License:Open Source License

protected int getLastSundayOfOctober(int year) {
    LocalDate ld = new LocalDate(year, DateTimeConstants.OCTOBER, 1).dayOfMonth().withMaximumValue().dayOfWeek()
            .setCopy(DateTimeConstants.SUNDAY);
    if (ld.getMonthOfYear() != DateTimeConstants.OCTOBER) {
        return ld.minus(Period.days(7)).getDayOfMonth();
    } else {/*from  w w  w  .j a  v a 2 s.  co  m*/
        return ld.getDayOfMonth();
    }
}

From source file:de.javakaffee.kryoserializers.jodatime.JodaLocalDateSerializer.java

License:Apache License

@Override
public void write(final Kryo kryo, final Output output, final LocalDate localDate) {
    final int packedYearMonthDay = localDate.getYear() * 13 * 32 + localDate.getMonthOfYear() * 32
            + localDate.getDayOfMonth();
    output.writeInt(packedYearMonthDay, true);
    final String chronologyId = IdentifiableChronology.getChronologyId(localDate.getChronology());
    output.writeString(chronologyId == null ? "" : chronologyId);
}