Example usage for org.joda.time LocalDate parse

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

Introduction

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

Prototype

@FromString
public static LocalDate parse(String str) 

Source Link

Document

Parses a LocalDate from the specified string.

Usage

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

License:Open Source License

@Override
protected LocalDate fromPersistedString(String string) {
    return LocalDate.parse(string);
}

From source file:br.com.moonjava.flight.dao.financeiro.OperadoraDeCartaoDAO.java

License:Apache License

@Override
public List<Cartao> readFile() {
    try {/*  ww  w  . j a va 2s.c  o  m*/
        while (input.hasNext()) {
            RequestParamWrapper request = new RequestParamWrapper();

            String titular = input.next();
            long numero = input.nextLong();
            String data = input.next();
            String cartao = input.next();
            double valor = 0;

            request.set("titular", titular);
            request.set("numero", numero);

            LocalDate validade = LocalDate.parse(data);
            request.set("validade", validade);

            Bandeira bandeira = Bandeira.valueOf(Bandeira.class, cartao);
            request.set("bandeira", bandeira);

            request.set("valor", valor);

            Cartao pojo = new CartaoCreate(request).createInstance();
            list.add(pojo);
        }
    } catch (NoSuchElementException e) {
        input.close();
    } catch (IllegalStateException e) {
        throw new RuntimeException(e);
    }
    return list;
}

From source file:br.com.moonjava.flight.util.FormatDateTime.java

License:Apache License

public static LocalDate parseToLocalDate(String value) {
    try {//  w ww . j  a  va  2s  .c om
        Date date = new SimpleDateFormat("MM/dd/yyyy").parse(value);
        String format = new SimpleDateFormat("yyyy-MM-dd").format(date);
        return LocalDate.parse(format);
    } catch (ParseException e) {
        try {
            Date date = new SimpleDateFormat("dd/MM/yyyy").parse(value);
            String format = new SimpleDateFormat("yyyy-MM-dd").format(date);
            return LocalDate.parse(format);
        } catch (ParseException e1) {
            throw new RuntimeException(e);
        }
    }
}

From source file:br.com.moonjava.flight.util.FormatDateTimeDesk.java

License:Apache License

public static LocalDate parseToLocalDate(String value, String country) {
    try {//from   w w w. j av  a  2  s.c  o m
        Date date = null;
        if (country.equals("US")) {
            date = new SimpleDateFormat("MM/dd/yyyy").parse(value);
        } else {
            date = new SimpleDateFormat("dd/MM/yyyy").parse(value);
        }
        String format = new SimpleDateFormat("yyyy-MM-dd").format(date);
        return LocalDate.parse(format);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}

From source file:br.com.tecsinapse.datasources.DataParser.java

License:LGPL

public DataParser(String date, String dateTime, String decimal, Integer integer, String string, String empty,
        String time) {/*from w  w  w. ja v a  2  s.  co m*/
    this.date = LocalDate.parse(date);
    this.dateTime = LocalDateTime.parse(dateTime);
    this.decimal = decimal != null ? new BigDecimal(decimal) : null;
    this.integer = integer;
    this.string = string;
    this.empty = empty;
    this.time = LocalTime.parse(time);
}

From source file:cherry.foundation.validator.JodaTimeMaxValidator.java

License:Apache License

@Override
public boolean isValid(ReadablePartial value, ConstraintValidatorContext context) {
    if (value == null) {
        return true;
    } else if (value instanceof LocalDate) {
        LocalDate max = LocalDate.parse(maxValue);
        if (inclusive) {
            return max.compareTo(value) >= 0;
        } else {//from w ww .  j a va  2s.c  om
            return max.compareTo(value) > 0;
        }
    } else if (value instanceof LocalDateTime) {
        LocalDateTime max = LocalDateTime.parse(maxValue);
        if (inclusive) {
            return max.compareTo(value) >= 0;
        } else {
            return max.compareTo(value) > 0;
        }
    } else {
        return true;
    }
}

From source file:cherry.foundation.validator.JodaTimeMinValidator.java

License:Apache License

@Override
public boolean isValid(ReadablePartial value, ConstraintValidatorContext context) {
    if (value == null) {
        return true;
    } else if (value instanceof LocalDate) {
        LocalDate min = LocalDate.parse(minValue);
        if (inclusive) {
            return min.compareTo(value) <= 0;
        } else {/*from  www.ja v  a  2s  .c om*/
            return min.compareTo(value) < 0;
        }
    } else if (value instanceof LocalDateTime) {
        LocalDateTime min = LocalDateTime.parse(minValue);
        if (inclusive) {
            return min.compareTo(value) <= 0;
        } else {
            return min.compareTo(value) < 0;
        }
    } else {
        return true;
    }
}

From source file:com.arangodb.velocypack.module.joda.internal.util.JodaTimeUtil.java

License:Apache License

public static LocalDate parseLocalDate(final String source) {
    return LocalDate.parse(source);
}

From source file:com.github.cassandra.jdbc.CassandraDataTypeConverters.java

License:Apache License

protected void init() {
    // use "null" instead of empty string to avoid "InvalidQueryException: Key may not be empty"
    addMapping(String.class, "null", new Function<Object, String>() {
        public String apply(Object input) {
            String result;/* ww w .j ava2 s. com*/
            if (input instanceof Readable) {
                try {
                    result = CharStreams.toString(((Readable) input));
                } catch (IOException e) {
                    throw new IllegalArgumentException("Failed to read from Readable " + input, e);
                }
            } else {
                result = String.valueOf(input);
            }

            return result;
        }
    });
    addMapping(java.util.UUID.class, java.util.UUID.randomUUID(), new Function<Object, UUID>() {
        public UUID apply(Object input) {
            return java.util.UUID.fromString(String.valueOf(input));
        }
    });

    InetAddress defaultAddress = null;
    try {
        defaultAddress = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        Logger.warn(e, "Failed to get local host");
    }
    addMapping(InetAddress.class, defaultAddress, new Function<Object, InetAddress>() {
        public InetAddress apply(Object input) {
            try {
                return InetAddress.getByName(String.valueOf(input));
            } catch (UnknownHostException e) {
                throw CassandraErrors.unexpectedException(e);
            }
        }
    });
    addMapping(Blob.class, new CassandraBlob(new byte[0]), new Function<Object, Blob>() {
        public Blob apply(Object input) {
            CassandraBlob blob;

            if (input instanceof ByteBuffer) {
                blob = new CassandraBlob((ByteBuffer) input);
            } else if (input instanceof byte[]) {
                blob = new CassandraBlob((byte[]) input);
            } else if (input instanceof InputStream) {
                try {
                    blob = new CassandraBlob(ByteStreams.toByteArray((InputStream) input));
                } catch (IOException e) {
                    throw new IllegalArgumentException("Failed to read from input stream " + input, e);
                }
            } else {
                blob = new CassandraBlob(String.valueOf(input).getBytes());
            }

            return blob;
        }
    });
    addMapping(byte[].class, emptyByteArray, new Function<Object, byte[]>() {
        public byte[] apply(Object input) {
            byte[] result;

            if (input instanceof ByteBuffer) {
                result = ((ByteBuffer) input).array();
            } else {
                result = String.valueOf(input).getBytes();
            }

            return result;
        }
    });
    /*
    addMapping(ByteBuffer.class, ByteBuffer.wrap(new byte[0]), new Function<Object, ByteBuffer>() {
    public ByteBuffer apply(Object input) {
        return ByteBuffer.wrap(input instanceof byte[] ? (byte[]) input : String.valueOf(input).getBytes());
    }
    });
    */
    addMapping(Boolean.class, Boolean.FALSE, new Function<Object, Boolean>() {
        public Boolean apply(Object input) {
            return Boolean.valueOf(String.valueOf(input));
        }
    });
    addMapping(Byte.class, (byte) 0, new Function<Object, Byte>() {
        public Byte apply(Object input) {
            return input instanceof Number ? ((Number) input).byteValue()
                    : Ints.tryParse(String.valueOf(input)).byteValue();
        }
    });
    addMapping(Short.class, (short) 0, new Function<Object, Short>() {
        public Short apply(Object input) {
            return input instanceof Number ? ((Number) input).shortValue()
                    : Ints.tryParse(String.valueOf(input)).shortValue();
        }
    });
    addMapping(Integer.class, 0, new Function<Object, Integer>() {
        public Integer apply(Object input) {
            return input instanceof Number ? ((Number) input).intValue() : Ints.tryParse(String.valueOf(input));
        }
    });
    addMapping(Long.class, 0L, new Function<Object, Long>() {
        public Long apply(Object input) {
            return input instanceof Number ? ((Number) input).longValue()
                    : Long.parseLong(String.valueOf(input));
        }
    });
    addMapping(Float.class, 0.0F, new Function<Object, Float>() {
        public Float apply(Object input) {
            return input instanceof Number ? ((Number) input).floatValue()
                    : Doubles.tryParse(String.valueOf(input)).floatValue();
        }
    });
    addMapping(Double.class, 0.0D, new Function<Object, Double>() {
        public Double apply(Object input) {
            return input instanceof Number ? ((Number) input).doubleValue()
                    : Doubles.tryParse(String.valueOf(input));
        }
    });
    addMapping(BigDecimal.class, BigDecimal.ZERO, new Function<Object, BigDecimal>() {
        public BigDecimal apply(Object input) {
            return new BigDecimal(String.valueOf(input));
        }
    });
    addMapping(BigInteger.class, BigInteger.ZERO, new Function<Object, BigInteger>() {
        public BigInteger apply(Object input) {
            return new BigInteger(String.valueOf(input));
        }
    });

    addMapping(Date.class, new Date(System.currentTimeMillis()), new Function<Object, Date>() {
        public Date apply(Object input) {
            Date result;
            if (input instanceof LocalDate) {
                result = new Date(((LocalDate) input).toDate().getTime());
            } else if (input instanceof java.util.Date) {
                result = new Date(((java.util.Date) input).getTime());
            } else {
                result = new Date(LocalDate.parse(String.valueOf(input)).toDate().getTime());
            }
            return result;
        }
    });
    addMapping(Time.class, new Time(System.currentTimeMillis()), new Function<Object, Time>() {
        public Time apply(Object input) {
            Time result;
            if (input instanceof LocalTime) {
                result = new Time(((LocalTime) input).toDateTimeToday().getMillis());
            } else if (input instanceof java.util.Date) {
                result = new Time(((java.util.Date) input).getTime());
            } else {
                result = new Time(LocalTime.parse(String.valueOf(input)).toDateTimeToday().getMillis());
            }
            return result;
        }
    });
    addMapping(Timestamp.class, new Timestamp(System.currentTimeMillis()), new Function<Object, Timestamp>() {
        public Timestamp apply(Object input) {
            Timestamp result;
            if (input instanceof Instant) {
                result = new Timestamp(((Instant) input).toDate().getTime());
            } else if (input instanceof java.util.Date) {
                result = new Timestamp(((java.util.Date) input).getTime());
            } else if (input instanceof Number) {
                result = new Timestamp(((Number) input).longValue());
            } else {
                String dateTime = String.valueOf(input);
                if (dateTime.indexOf(' ') == 10 && dateTime.indexOf('Z') < 0) {
                    StringBuilder builder = new StringBuilder(dateTime).append('Z');
                    builder.setCharAt(10, 'T');
                    dateTime = builder.toString();
                }

                result = new Timestamp(Instant.parse(dateTime).toDate().getTime());
            }
            return result;
        }
    });

    // now collections
    addMapping(List.class, emptyList, new Function<Object, List>() {
        public List apply(Object input) {
            List result;
            if (input instanceof Iterable) {
                result = Lists.newArrayList((Iterable) input);
            } else if (input instanceof Object[]) {
                result = Lists.newArrayList((Object[]) input);
            } else {
                result = valueSplitter.splitToList(String.valueOf(input));
            }

            return result;
        }
    });
    addMapping(Set.class, emptySet, new Function<Object, Set>() {
        public Set apply(Object input) {
            Set result;
            if (input instanceof Iterable) {
                result = Sets.newTreeSet((Iterable) input);
            } else if (input instanceof Object[]) {
                result = Sets.newHashSet((Object[]) input);
            } else {
                result = Sets.newTreeSet(valueSplitter.splitToList(String.valueOf(input)));
            }

            return result;
        }
    });
    addMapping(Set.class, emptyMap, new Function<Object, Map>() {
        public Map apply(Object input) {
            return Map.class.cast(input);
        }
    });
}

From source file:com.github.cassandra.jdbc.provider.datastax.codecs.StringDateCodec.java

License:Apache License

@Override
public ByteBuffer serialize(String value, ProtocolVersion protocolVersion) {
    if (value == null)
        return null;
    Days days = daysBetween(EPOCH, LocalDate.parse(value));
    int unsigned = fromSignedToUnsignedInt(days.getDays());
    return cint().serializeNoBoxing(unsigned, protocolVersion);
}