Example usage for org.joda.time LocalDateTime LocalDateTime

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

Introduction

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

Prototype

public LocalDateTime(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:org.owasp.dependencytrack.tasks.NistDataMirrorUpdater.java

License:Open Source License

private LocalDateTime getLatestDownloadDate() {
    LocalDateTime latest = null;/* w w  w.j av  a  2 s. co  m*/
    for (URL url : downloadURLS) {
        File localFile = getLocalFileFor(url);
        if (!localFile.exists() || localFile.length() == 0) {
            return null; // if any files don't exist we need to reload em all.
        }
        latest = new LocalDateTime(localFile.lastModified());
    }
    return latest;
}

From source file:org.qi4j.runtime.types.JodaLocalDateTimeType.java

License:Open Source License

public Object fromJSON(Object json, Module module) {
    return new LocalDateTime(json);
}

From source file:org.qi4j.runtime.types.JodaLocalDateTimeType.java

License:Open Source License

@Override
public Object fromQueryParameter(String parameter, Module module) throws IllegalArgumentException {
    return new LocalDateTime(parameter);
}

From source file:org.qi4j.spi.value.ValueDeserializerAdapter.java

License:Open Source License

protected ValueDeserializerAdapter(Application application, Module module,
        Function<Application, Module> valuesModuleFinder) {

    this.application = application;
    this.module = module;
    setValuesModuleFinder(valuesModuleFinder);

    // Primitive Value types
    registerDeserializer(String.class, new Function<Object, String>() {
        @Override/*from   w  w  w . java  2 s. c  om*/
        public String map(Object input) {
            return input.toString();
        }
    });
    registerDeserializer(Character.class, new Function<Object, Character>() {
        @Override
        public Character map(Object input) {
            return input.toString().charAt(0);
        }
    });
    registerDeserializer(Boolean.class, new Function<Object, Boolean>() {
        @Override
        public Boolean map(Object input) {
            return (input instanceof String) ? Boolean.parseBoolean((String) input)
                    : ((Boolean) input).booleanValue();
        }
    });
    registerDeserializer(Integer.class, new Function<Object, Integer>() {
        @Override
        public Integer map(Object input) {
            return (input instanceof String) ? Integer.parseInt((String) input) : ((Number) input).intValue();
        }
    });
    registerDeserializer(Long.class, new Function<Object, Long>() {
        @Override
        public Long map(Object input) {
            return (input instanceof String) ? Long.parseLong((String) input) : ((Number) input).longValue();
        }
    });
    registerDeserializer(Short.class, new Function<Object, Short>() {
        @Override
        public Short map(Object input) {
            return (input instanceof String) ? Short.parseShort((String) input) : ((Number) input).shortValue();
        }
    });
    registerDeserializer(Byte.class, new Function<Object, Byte>() {
        @Override
        public Byte map(Object input) {
            return (input instanceof String) ? Byte.parseByte((String) input) : ((Number) input).byteValue();
        }
    });
    registerDeserializer(Float.class, new Function<Object, Float>() {
        @Override
        public Float map(Object input) {
            return (input instanceof String) ? Float.parseFloat((String) input) : ((Number) input).floatValue();
        }
    });
    registerDeserializer(Double.class, new Function<Object, Double>() {
        @Override
        public Double map(Object input) {
            return (input instanceof String) ? Double.parseDouble((String) input)
                    : ((Number) input).doubleValue();
        }
    });

    // Number types
    registerDeserializer(BigDecimal.class, new Function<Object, BigDecimal>() {
        @Override
        public BigDecimal map(Object input) {
            return new BigDecimal(input.toString());
        }
    });
    registerDeserializer(BigInteger.class, new Function<Object, BigInteger>() {
        @Override
        public BigInteger map(Object input) {
            return new BigInteger(input.toString());
        }
    });

    // Date types
    registerDeserializer(Date.class, new Function<Object, Date>() {
        @Override
        public Date map(Object input) {
            return Dates.fromString(input.toString());
        }
    });
    registerDeserializer(DateTime.class, new Function<Object, DateTime>() {
        @Override
        public DateTime map(Object input) {
            return new DateTime(input, DateTimeZone.UTC);
        }
    });
    registerDeserializer(LocalDateTime.class, new Function<Object, LocalDateTime>() {
        @Override
        public LocalDateTime map(Object input) {
            return new LocalDateTime(input);
        }
    });
    registerDeserializer(LocalDate.class, new Function<Object, LocalDate>() {
        @Override
        public LocalDate map(Object input) {
            return new LocalDate(input);
        }
    });

    // Other supported types
    registerDeserializer(EntityReference.class, new Function<Object, EntityReference>() {
        @Override
        public EntityReference map(Object input) {
            return EntityReference.parseEntityReference(input.toString());
        }
    });
}

From source file:org.squashtest.tm.domain.search.NotGMTDateBridge.java

License:Open Source License

@Override
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
    if (value == null) {
        return;/*from   w w w  . j ava2 s.  c o m*/
    }

    Date date = (Date) value;
    Field miliField = ReflectionUtils.findField(LocalDateTime.class, "iLocalMillis");
    try {

        miliField.setAccessible(true);
        long numericDate = (long) ReflectionUtils.getField(miliField,
                new LocalDateTime(date.getTime()).withTime(0, 0, 0, 0));
        luceneOptions.addNumericFieldToDocument(name, numericDate, document);

    } finally {
        miliField.setAccessible(false);
    }

}

From source file:org.teiid.translator.odata.ODataExecutionFactory.java

License:Open Source License

public void convertToODataInput(Literal obj, StringBuilder sb) {
    if (obj.getValue() == null) {
        sb.append(NULL);//from www . java 2  s  . com
    } else {
        Class<?> type = obj.getType();
        Object val = obj.getValue();
        if (Number.class.isAssignableFrom(type)) {
            sb.append(val);
        } else if (type.equals(DataTypeManager.DefaultDataClasses.BOOLEAN)) {
            sb.append(obj.getValue().equals(Boolean.TRUE) ? true : false);
        } else if (type.equals(DataTypeManager.DefaultDataClasses.TIMESTAMP)) {
            LocalDateTime date = new LocalDateTime(val);
            sb.append("datetime'") //$NON-NLS-1$
                    .append(InternalUtil.formatDateTimeForXml(date)).append("'"); //$NON-NLS-1$
        } else if (type.equals(DataTypeManager.DefaultDataClasses.TIME)) {
            LocalTime time = new LocalTime(((java.sql.Time) val).getTime());
            sb.append("time'") //$NON-NLS-1$
                    .append(InternalUtil.formatTimeForXml(time)).append("'"); //$NON-NLS-1$
        } else if (type.equals(DataTypeManager.DefaultDataClasses.DATE)) {
            sb.append("date'") //$NON-NLS-1$
                    .append(val).append("'"); //$NON-NLS-1$
        } else if (type.equals(DataTypeManager.DefaultDataClasses.VARBINARY)) {
            sb.append("X'") //$NON-NLS-1$
                    .append(val).append("'"); //$NON-NLS-1$
        } else {
            sb.append(Tokens.QUOTE).append(escapeString(val.toString(), Tokens.QUOTE)).append(Tokens.QUOTE);
        }
    }
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

public static IDataTypeParser dateTime() {
    if (dateTimeDataTypeParser == null) {
        dateTimeDataTypeParser = new AbstractISO8601DataTypeParser(dateTimeFormatter()) {
            protected Object parseWithTimeZone(DateTimeParserBucket bucket) {
                DateTimeZone zone = DateTimeZone.forOffsetMillis(bucket.getOffset());
                return new DateTime(bucket.computeMillis(), validate(zone));
            }/*w w  w .j  av  a  2  s. c  o  m*/

            protected Object parseWithoutTimeZone(DateTimeParserBucket bucket) {
                return new LocalDateTime(bucket.computeMillis());
            }
        };
    }
    return dateTimeDataTypeParser;
}

From source file:propel.core.utils.ConversionUtils.java

License:Open Source License

private static Object changeTypeFromNumber(Object value, Class<?> targetType) {
    Number number = (Number) value;

    // dispatch to appropriate constructor method
    if (targetType.equals(Byte.class))
        return new Byte(number.byteValue());
    if (targetType.equals(Boolean.class))
        return number.longValue() == 0 ? new Boolean(false) : new Boolean(true);
    if (targetType.equals(Short.class))
        return new Short(number.shortValue());
    if (targetType.equals(Integer.class))
        return new Integer(number.intValue());
    if (targetType.equals(Long.class))
        return new Long(number.longValue());
    if (targetType.equals(Float.class))
        return new Float(number.floatValue());
    if (targetType.equals(Double.class))
        return new Double(number.doubleValue());
    if (targetType.equals(Character.class))
        return new Character((char) number.shortValue());

    if (targetType.equals(byte.class))
        return number.byteValue();
    if (targetType.equals(boolean.class))
        return number.longValue() == 0 ? false : true;
    if (targetType.equals(char.class))
        return (char) number.shortValue();
    if (targetType.equals(short.class))
        return number.shortValue();
    if (targetType.equals(int.class))
        return number.intValue();
    if (targetType.equals(long.class))
        return number.longValue();
    if (targetType.equals(float.class))
        return number.floatValue();
    if (targetType.equals(double.class))
        return number.doubleValue();
    if (targetType.equals(LocalDateTime.class))
        return new LocalDateTime(number.longValue());
    if (targetType.equals(DateTime.class))
        return new DateTime(number.longValue());
    if (targetType.equals(BigDecimal.class))
        return new BigDecimal(number.toString());
    if (targetType.equals(Duration.class))
        return new Duration(number.longValue());
    if (targetType.equals(Period.class))
        return new Period(number.longValue());
    if (targetType.equals(Int128.class))
        return new Int128(number.toString());
    if (targetType.equals(UnsignedByte.class))
        return new UnsignedByte((short) (number.byteValue() & 0xFF));
    if (targetType.equals(UnsignedShort.class))
        return new UnsignedShort((int) (number.shortValue() & 0xFFFF));
    if (targetType.equals(UnsignedInteger.class))
        return new UnsignedInteger((long) (number.intValue() & 0xFFFFFFFF));
    if (targetType.equals(UnsignedLong.class)) {
        // perform similar operation as above to get rid of the negative values
        long ln = new BigInteger(number.toString()).longValue();
        return new UnsignedLong(new BigInteger("0" + toBinary(ln)));
    }//from w w  w  . j ava  2  s. c  om
    if (targetType.equals(SignedByte.class))
        return new SignedByte(number.byteValue());
    if (targetType.equals(BigInteger.class))
        return new BigInteger(number.toString());
    if (targetType.equals(propel.core.userTypes.BigInteger.class)) {
        propel.core.userTypes.BigInteger bi = new propel.core.userTypes.BigInteger();
        bi.setCurrentValue(number.toString());
        return bi;
    }

    throw new IllegalArgumentException("The provided Number could not be converted to type '"
            + targetType.getSimpleName() + "': " + value);
}

From source file:propel.core.utils.ConversionUtils.java

License:Open Source License

private static Object changeTypeFromCharacter(Object value, Class<?> targetType) {
    char ch = ((Character) value).charValue();

    // dispatch to appropriate construction method
    if (targetType.equals(Byte.class))
        return new Byte((byte) ch);
    if (targetType.equals(Boolean.class))
        return ch == 0 ? new Boolean(false) : new Boolean(true);
    if (targetType.equals(Short.class))
        return new Short((short) ch);
    if (targetType.equals(Integer.class))
        return new Integer(ch);
    if (targetType.equals(Long.class))
        return new Long(ch);
    if (targetType.equals(Float.class))
        return new Float(ch);
    if (targetType.equals(Double.class))
        return new Double(ch);

    if (targetType.equals(byte.class))
        return (byte) ch;
    if (targetType.equals(boolean.class))
        return ch == 0 ? false : true;
    if (targetType.equals(char.class))
        return ch;
    if (targetType.equals(short.class))
        return (short) ch;
    if (targetType.equals(int.class))
        return (int) ch;
    if (targetType.equals(long.class))
        return (long) ch;
    if (targetType.equals(float.class))
        return (float) ch;
    if (targetType.equals(double.class))
        return (double) ch;

    if (targetType.equals(LocalDateTime.class))
        return new LocalDateTime((long) ch);
    if (targetType.equals(DateTime.class))
        return new DateTime((long) ch);
    if (targetType.equals(BigDecimal.class))
        return new BigDecimal(ch);
    if (targetType.equals(Duration.class))
        return new Duration((long) ch);
    if (targetType.equals(Period.class))
        return new Period((long) ch);
    if (targetType.equals(Int128.class))
        return new Int128(Integer.valueOf(ch).toString());
    if (targetType.equals(UnsignedByte.class))
        return new UnsignedByte((byte) ch);
    if (targetType.equals(UnsignedShort.class))
        return new UnsignedShort(ch);
    if (targetType.equals(UnsignedInteger.class))
        return new UnsignedInteger(ch);
    if (targetType.equals(UnsignedLong.class))
        return new UnsignedLong(new Integer(ch).toString());
    if (targetType.equals(SignedByte.class))
        return new SignedByte((byte) ch);
    if (targetType.equals(BigInteger.class))
        return new BigInteger(Integer.valueOf(ch).toString());
    if (targetType.equals(propel.core.userTypes.BigInteger.class)) {
        propel.core.userTypes.BigInteger bi = new propel.core.userTypes.BigInteger();
        bi.setCurrentValue(Integer.valueOf(ch).toString());
        return bi;
    }//w ww  .j a  v  a 2 s. c  o m

    throw new IllegalArgumentException("The provided Character could not be converted to type '"
            + targetType.getSimpleName() + "': " + value);
}

From source file:propel.core.utils.ConversionUtils.java

License:Open Source License

private static Object changeTypeFromBoolean(Object value, Class<?> targetType) {
    boolean bool = ((Boolean) value).booleanValue();

    // dispatch to appropriate construction method
    if (targetType.equals(Byte.class))
        return bool ? new Byte((byte) 1) : new Byte((byte) 0);
    if (targetType.equals(Character.class))
        return bool ? new Character((char) 0) : new Character((char) 1);
    if (targetType.equals(Short.class))
        return bool ? new Short((short) 1) : new Short((short) 0);
    if (targetType.equals(Integer.class))
        return bool ? new Integer(1) : new Integer(0);
    if (targetType.equals(Long.class))
        return bool ? new Long(1) : new Long(0);
    if (targetType.equals(Float.class))
        return bool ? new Float(1) : new Float(0);
    if (targetType.equals(Double.class))
        return bool ? new Double(1) : new Double(0);

    if (targetType.equals(byte.class))
        return bool ? (byte) 1 : (byte) 0;
    if (targetType.equals(boolean.class))
        return bool;
    if (targetType.equals(char.class))
        return bool ? (char) 1 : (char) 0;
    if (targetType.equals(short.class))
        return bool ? (short) 1 : (short) 0;
    if (targetType.equals(int.class))
        return bool ? (int) 1 : (int) 0;
    if (targetType.equals(long.class))
        return bool ? (long) 1 : (long) 0;
    if (targetType.equals(float.class))
        return bool ? (float) 1.0 : (float) 0.0;
    if (targetType.equals(double.class))
        return bool ? (double) 1.0 : (double) 0.0;

    if (targetType.equals(LocalDateTime.class))
        return bool ? new LocalDateTime(1) : new LocalDateTime(0);
    if (targetType.equals(DateTime.class))
        return bool ? new DateTime(1) : new DateTime(0);
    if (targetType.equals(BigDecimal.class))
        return bool ? new BigDecimal(1) : new BigDecimal(0);
    if (targetType.equals(Duration.class))
        return bool ? new Duration(1) : new Duration(0);
    if (targetType.equals(Period.class))
        return bool ? new Period(1) : new Period(0);
    if (targetType.equals(Int128.class))
        return bool ? new Int128("1") : new Int128("0");
    if (targetType.equals(UnsignedByte.class))
        return bool ? new UnsignedByte((byte) 1) : new UnsignedByte((byte) 0);
    if (targetType.equals(UnsignedShort.class))
        return bool ? new UnsignedShort(1) : new UnsignedShort(0);
    if (targetType.equals(UnsignedInteger.class))
        return bool ? new UnsignedInteger(1) : new UnsignedInteger(0);
    if (targetType.equals(UnsignedLong.class))
        return bool ? new UnsignedLong("1") : new UnsignedLong("0");
    if (targetType.equals(SignedByte.class))
        return bool ? new SignedByte("1") : new SignedByte("0");
    if (targetType.equals(BigInteger.class))
        return bool ? new BigInteger("1") : new BigInteger("0");
    if (targetType.equals(propel.core.userTypes.BigInteger.class)) {
        propel.core.userTypes.BigInteger bi = new propel.core.userTypes.BigInteger();
        bi.setCurrentValue(bool ? "1" : "0");
        return bi;
    }//from  w  w  w  .j av  a 2  s . c  om

    throw new IllegalArgumentException("The provided Boolean could not be converted to type '"
            + targetType.getSimpleName() + "': " + value);
}