Example usage for org.joda.time LocalDate LocalDate

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

Introduction

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

Prototype

public LocalDate(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:LocalDateTypeAdapter.java

License:Apache License

@Override
public LocalDate read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();/*from ww  w  .  j  ava2s. co m*/
        return null;
    }
    return new LocalDate(in.nextString());
}

From source file:$.MessageController.java

License:Apache License

/**
     * Creates a set of message dates, to search logs for these dates.
     * This set contains just the dates of the following timestamps:
     * <ul>/*from  ww  w  .j  a  v  a  2s  .com*/
     * <li>source system timestamp</li>
     * <li>received timestamp</li>
     * <li>start processing timestamp</li>
     * <li>last update timestamp</li>
     * </ul>
     * It's a Set, so that only distinct dates will be included.
     * It's a SortedSet, so that the dates are in their natural order.
     * The elements are LocalDate (without time),
     * so that the dates will be in the correct order
     * and the set will correctly not include duplicates.
     *
     * @param msg the message to find dates for
     * @return a set of dates
     */
    private SortedSet<LocalDate> getMsgDates(Message msg) {
        TreeSet<LocalDate> logDates = new TreeSet<LocalDate>();
        Date[] msgDates = new Date[] { msg.getMsgTimestamp(), msg.getReceiveTimestamp(),
                msg.getStartProcessTimestamp(), msg.getLastUpdateTimestamp() };
        for (Date msgDate : msgDates) {
            if (msgDate != null) {
                logDates.add(new LocalDate(msgDate));
            }
        }
        return logDates;
    }

From source file:ar.edu.utn.frre.dacs.sample.model.Cliente.java

License:Apache License

/**
 * Retorna la edad del cliente en base a la fecha de nacimiento y la 
 * fecha actual.//from   ww  w .  j  a  v  a  2  s.co m
 * @return Edad del Cliente.
 */
public int getEdad() {
    if (fechaNacimiento == null)
        return 0;

    LocalDate birthdate = new LocalDate(fechaNacimiento.getTime());
    LocalDate now = new LocalDate();
    Years age = Years.yearsBetween(birthdate, now);

    return age.getYears();
}

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

License:Open Source License

public static Date add(Date date, int field, int value) {
    if (field == Calendar.DAY_OF_MONTH)
        return new LocalDate(date).plusDays(value).toDate();

    Calendar cal = calendarFromDate(date);
    cal.add(field, value);// ww w  . j a v a 2 s .co  m
    return cal.getTime();
}

From source file:au.org.theark.study.service.StudyServiceImpl.java

License:Open Source License

private String calculatePedigreeAge(Date birthDate, Date selectDate) {
    String age = null;//from w  ww  .  ja v a2 s.  co  m
    LocalDate oldDate = null;
    LocalDate newDate = null;

    oldDate = new LocalDate(birthDate);

    if (selectDate != null) {
        newDate = new LocalDate(selectDate);
    } else {
        newDate = new LocalDate();
    }

    Period period = new Period(oldDate, newDate, PeriodType.yearMonthDay());
    int years = period.getYears();
    age = "" + (years < 1 ? "&lt;1" : years);

    return age;
}

From source file:br.com.centralit.evm.citsmartevm.util.CronExpression.java

License:Apache License

public DateTime nextTimeAfter(DateTime afterTime) {
    MutableDateTime nextTime = new MutableDateTime(afterTime);
    nextTime.setMillisOfSecond(0);//from w w w. ja  va2s .com
    nextTime.secondOfDay().add(1);

    while (true) { // day of week
        while (true) { // month
            while (true) { // day of month
                while (true) { // hour
                    while (true) { // minute
                        while (true) { // second
                            if (secondField.matches(nextTime.getSecondOfMinute())) {
                                break;
                            }
                            nextTime.secondOfDay().add(1);
                        }
                        if (minuteField.matches(nextTime.getMinuteOfHour())) {
                            break;
                        }
                        nextTime.minuteOfDay().add(1);
                        nextTime.secondOfMinute().set(0);
                    }
                    if (hourField.matches(nextTime.getHourOfDay())) {
                        break;
                    }
                    nextTime.hourOfDay().add(1);
                    nextTime.minuteOfHour().set(0);
                    nextTime.secondOfMinute().set(0);
                }
                if (dayOfMonthField.matches(new LocalDate(nextTime))) {
                    break;
                }
                nextTime.addDays(1);
                nextTime.setTime(0, 0, 0, 0);
            }
            if (monthField.matches(nextTime.getMonthOfYear())) {
                break;
            }
            nextTime.addMonths(1);
            nextTime.setDayOfMonth(1);
            nextTime.setTime(0, 0, 0, 0);
        }
        if (dayOfWeekField.matches(new LocalDate(nextTime))) {
            break;
        }
        nextTime.addDays(1);
        nextTime.setTime(0, 0, 0, 0);
    }

    return nextTime.toDateTime();
}

From source file:br.com.moonjava.flight.jdbc.ResultSetJdbcWrapper.java

License:Apache License

@Override
public LocalDate getLocalDate(String columnLabel) {
    try {//from  w ww.  ja  va2  s .c  o m
        Date date = rs.getDate(alias + "." + columnLabel);
        return new LocalDate(date);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

From source file:br.com.objectos.comuns.relational.jdbc.TypeLocalDate.java

License:Apache License

@Override
LocalDate getValue(ResultSet rs) throws SQLException {
    Date date = rs.getDate("VALUE");
    return date != null ? new LocalDate(date) : null;
}

From source file:br.edu.unirio.pm.dao.ProdutosDAO.java

public Produto buscarProdutoNoBanco(long codigoProduto) throws SQLException {
    FabricaConexao.iniciarConexao();/*from  w  w  w . ja v  a2 s  .c o m*/
    comando = FabricaConexao.criarComando(SELECT);
    comando.setLong(1, codigoProduto);
    resultado = comando.executeQuery();
    while (resultado.next()) {
        if (resultado.getLong("codigo") == codigoProduto) {
            Produto produto = new Produto();
            produto.setCodigo(resultado.getLong("codigo"));
            produto.setNome(resultado.getString("nome"));
            produto.setPreco(resultado.getDouble("preco"));
            produto.setInicioVigenciaPreco(new LocalDate(resultado.getDate("data_inicio_vigencia")));
            return produto;
        }
    }
    return null;

}

From source file:br.edu.unirio.pm.dao.VendasDAO.java

public LocalDate obterDataDaVendaMaisAtual() throws SQLException {
    try {//  ww w  . jav a 2 s.c o  m
        consulta = SELECT_MAX_DATA;
        LocalDate dataVendaMaisAtual = LocalDate.now();
        FabricaConexao.iniciarConexao();
        comando = FabricaConexao.criarComando(consulta);
        resultado = comando.executeQuery();
        while (resultado.next())
            dataVendaMaisAtual = new LocalDate(resultado.getDate(1));
        return dataVendaMaisAtual;
    } finally {
        FabricaConexao.fecharComando(comando);
        FabricaConexao.fecharConexao();
    }
}