Example usage for org.joda.time LocalDate getYear

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

Introduction

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

Prototype

public int getYear() 

Source Link

Document

Get the year field value.

Usage

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 w w.  j a v  a  2  s.  c  o  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 w  w .ja v  a 2 s  .co m*/
        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.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/*from  w  w w  . j  a va2 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.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);
}

From source file:de.jollyday.HolidayManager.java

License:Apache License

/**
 * Show if the requested date is a holiday.
 * /*from   ww w . jav a 2s  . c  o m*/
 * @param c
 *            The potential holiday.
 * @param args
 *            Hierarchy to request the holidays for. i.e. args = {'ny'} ->
 *            New York holidays
 * @return is a holiday in the state/region
 */
public boolean isHoliday(final LocalDate c, final String... args) {
    StringBuilder keyBuilder = new StringBuilder();
    keyBuilder.append(c.getYear());
    for (String arg : args) {
        keyBuilder.append("_");
        keyBuilder.append(arg);
    }
    String key = keyBuilder.toString();
    if (!holidaysPerYear.containsKey(key)) {
        Set<Holiday> holidays = getHolidays(c.getYear(), args);
        holidaysPerYear.put(key, holidays);
    }
    return calendarUtil.contains(holidaysPerYear.get(key), c);
}

From source file:de.jpaw.bonaparte.util.DayTime.java

License:Apache License

/** Converts the day portion of a LocalDate or localDateTime into a number in the format YYYYMMDD. */
static public int dayAsInt(LocalDate when) {
    return when.getDayOfMonth() + 100 * when.getMonthOfYear() + 10000 * when.getYear();
}

From source file:de.l3s.content.timex.extracting.utils.DateUtil.java

License:Apache License

/**
 * //from  w  w w .ja va  2s  .c  om
 * @param content
 * @param url
 * @param docid
 * @return
 * @throws ParseException 
 */
public LocalDate extractDate(String[] content_lines, String url, String docId) throws ParseException {
    LocalDate extractedUrlDate = null;
    LocalDate extractedDocIdDate = null;
    LocalDate extractedContentDate = null;

    // extract date from content
    extractedContentDate = extractDateFromContent(content_lines[0]);
    if (extractedContentDate == null && content_lines.length > 1)
        extractedContentDate = extractDateFromContent(content_lines[1]);
    if (extractedContentDate == null) {
        //extract date from blog url
        extractedUrlDate = extractDateFromURL(url);
        //extract date from docid
        extractedDocIdDate = LocalDate.parse(docId.substring(7, 15), dateFormat);
        if (extractedUrlDate != null && extractedUrlDate.getMonthOfYear() == extractedDocIdDate.getMonthOfYear()
                && extractedUrlDate.getYear() == extractedDocIdDate.getYear()
                && extractedUrlDate.getDayOfMonth() == 15) {
            return extractedDocIdDate;
        }
        //case url contains exact date yyyyMMdd
        else if (extractedUrlDate != null && extractedUrlDate.getDayOfMonth() != 15)
            return extractedUrlDate;
        else if (extractedUrlDate == null)
            return extractedDocIdDate;
        else
            return extractedUrlDate;

    } else {
        return extractedContentDate;
    }
}

From source file:de.sub.goobi.helper.DateUtils.java

License:Open Source License

/**
 * The function sameYear() compares two LocalDate objects in regard to the
 * question whether their two dates reside in the same year of the calendar
 * system presumed. Two dates are considered to be in the same year exactly
 * if none of them is null and their year fields are equal.
 *
 * @param current/*  ww w. ja v a  2 s.c om*/
 *            date to compare against
 * @param next
 *            date to compare, may be null
 * @return whether the two dates are in the same year
 */
public static boolean sameYear(LocalDate current, LocalDate next) {
    if (next == null) {
        return false;
    }
    return current.getYear() == next.getYear();
}