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:io.github.benas.randombeans.randomizers.jodatime.range.JodaTimeLocalDateTimeRangeRandomizer.java

License:Open Source License

@Override
public LocalDateTime getRandomValue() {
    return new LocalDateTime(getRandomDate().getTime());
}

From source file:io.personium.core.model.impl.es.doc.OEntityDocHandler.java

License:Apache License

/**
 * Creates and returns an OEntity from the Es JSON object.
 * @param entitySet entitySet//from www . j a v a2 s.c  o  m
 * @param metadata metadata
 * @param relatedEntitiesList relatedEntitiesList
 * @param selectQuery $ select query
 * @return Converted OEntity object
 */
public OEntityWrapper createOEntity(final EdmEntitySet entitySet, EdmDataServices metadata,
        Map<String, List<OEntity>> relatedEntitiesList, List<EntitySimpleProperty> selectQuery) {
    EdmEntityType eType = entitySet.getType();

    List<OProperty<?>> properties = new ArrayList<OProperty<?>>();

    HashMap<String, EntitySimpleProperty> selectMap = new HashMap<String, EntitySimpleProperty>();
    if (selectQuery != null) {
        for (EntitySimpleProperty prop : selectQuery) {
            selectMap.put(prop.getPropertyName(), prop);
        }
    }

    //Generate Declared Property according to schema
    for (EdmProperty prop : eType.getProperties()) {
        //Processing of reserved items
        if ("__published".equals(prop.getName()) && this.published != null) {
            properties.add(OProperties.datetime(prop.getName(), new LocalDateTime(this.published)));
            continue;
        } else if ("__updated".equals(prop.getName()) && this.updated != null) {
            properties.add(OProperties.datetime(prop.getName(), new LocalDateTime(this.updated)));
            continue;
        }

        //When a $ select query is specified, only the specified item or primary key information is added
        if (selectMap.size() != 0 && !selectMap.containsKey(prop.getName())
                && !eType.getKeys().contains(prop.getName())) {
            continue;
        }

        boolean isDynamic = false;
        NamespacedAnnotation<?> annotation = prop.findAnnotation(Common.P_NAMESPACE.getUri(),
                Property.P_IS_DECLARED.getName());
        if (annotation != null && !(Boolean.valueOf(annotation.getValue().toString()))) {
            isDynamic = true;
        }

        //Get value
        if (!this.staticFields.containsKey(getPropertyNameOrAlias(entitySet.getName(), prop.getName()))
                && isDynamic) {
            continue;
        }
        Object valO = this.staticFields.get(getPropertyNameOrAlias(entitySet.getName(), prop.getName()));

        EdmType edmType = prop.getType();

        CollectionKind ck = prop.getCollectionKind();
        if (edmType.isSimple()) {
            //Processing of non reserved items
            if (ck.equals(CollectionKind.List)) {
                //For array elements
                addSimpleListProperty(properties, prop, valO, edmType);
            } else {
                //In case of simple element
                addSimpleTypeProperty(properties, prop, valO, edmType);
            }
        } else {
            //For properties of type ComplexType
            if (metadata != null) {
                if (ck.equals(CollectionKind.List)) {
                    //For array elements
                    addComplexListProperty(metadata, properties, prop, valO, edmType);
                } else {
                    properties.add(createComplexTypeProperty(metadata, prop, valO));
                }
            }
        }
    }

    //Generation processing of Navigation Property
    int count = 0;
    List<OLink> links = new ArrayList<OLink>();
    //About each navigation property defined in the schema
    for (EdmNavigationProperty enp : eType.getNavigationProperties()) {
        EdmAssociationEnd ae = enp.getToRole();
        String toTypeName = ae.getType().getName();
        String npName = enp.getName();
        OLink lnk = null;
        List<OEntity> relatedEntities = null;
        if (relatedEntitiesList != null) {
            relatedEntities = relatedEntitiesList.get(npName);
        }
        if (EdmMultiplicity.MANY.equals(ae.getMultiplicity())) {
            //When the opponent's Multiplicity is MANY
            if (++count <= expandMaxNum && relatedEntities != null) {
                lnk = OLinks.relatedEntitiesInline(toTypeName, npName, npName, relatedEntities);
            } else {
                lnk = OLinks.relatedEntities(toTypeName, npName, npName);
            }
        } else {
            //When the opponent 's Multiplicity is not MANY. (ZERO or ONE)
            if (++count <= expandMaxNum && relatedEntities != null) {
                lnk = OLinks.relatedEntitiesInline(toTypeName, npName, npName, relatedEntities);
            } else {
                lnk = OLinks.relatedEntity(toTypeName, npName, npName);
            }
        }
        links.add(lnk);
    }

    //Generation of entityKey
    List<String> keys = eType.getKeys();
    List<String> kv = new ArrayList<String>();
    for (String key : keys) {
        kv.add(key);
        //I assume that the TODO key is a String. If the value of the key is other than a character string, it is necessary to deal with it.
        String v = (String) this.staticFields.get(key);
        if (v == null) {
            v = AbstractODataResource.DUMMY_KEY;
        }
        kv.add(v);
    }
    OEntityKey entityKey = OEntityKey.create(kv);

    //Generation of OEntity
    //TODO AtomPub system item is dummy
    OEntity entity = OEntities.create(entitySet, entityKey, properties, links, "title", "categoryTerm");

    //Wrap it to OEntityWrapper instead of OEntity so that ETag and hidden items can be returned.
    String etag = this.createEtag();
    OEntityWrapper oew = new OEntityWrapper(this.id, entity, etag);
    //Setting hidden items
    if (this.hiddenFields != null) {
        for (Map.Entry<String, Object> entry : this.hiddenFields.entrySet()) {
            oew.put(entry.getKey(), entry.getValue());
        }
    }
    oew.setManyToOneLinks(this.manyToOnelinkId);
    return oew;
}

From source file:io.personium.core.model.impl.es.doc.OEntityDocHandler.java

License:Apache License

/**
 * Add properties of type SimpleType to property array.
 * @param properties Property array//from   w  w  w .j  ava  2 s  .  c o m
 * @param prop Property to add
 * @param valO property's value
 * @param edmType type
 */
protected void addSimpleTypeProperty(List<OProperty<?>> properties, EdmProperty prop, Object valO,
        EdmType edmType) {
    if (edmType.equals(EdmSimpleType.STRING)) {
        if (valO == null) {
            properties.add(OProperties.string(prop.getName(), null));
        } else {
            properties.add(OProperties.string(prop.getName(), String.valueOf(valO)));
        }
    } else if (edmType.equals(EdmSimpleType.DATETIME)) {
        if (valO == null) {
            properties.add(OProperties.null_(prop.getName(), EdmSimpleType.DATETIME));
        } else {
            //When a value in a range that can be represented by Int type is entered in the user data, an Integer object is passed to valO
            //When Integer type is passed to the constructor of LocalDateTime, it becomes an error, so it converts it to a long type object
            Long longvalO = Long.valueOf(String.valueOf(valO));
            properties.add(OProperties.datetime(prop.getName(), new LocalDateTime(longvalO)));
        }
    } else if (edmType.equals(EdmSimpleType.SINGLE)) {
        if (valO == null) {
            properties.add(OProperties.single(prop.getName(), null));
        } else {
            properties.add(OProperties.single(prop.getName(), Float.valueOf(String.valueOf(valO))));
        }
    } else if (edmType.equals(EdmSimpleType.DOUBLE)) {
        if (valO == null) {
            properties.add(OProperties.double_(prop.getName(), null));
        } else {
            properties.add(OProperties.double_(prop.getName(), Double.valueOf(String.valueOf(valO))));
        }
    } else if (edmType.equals(EdmSimpleType.INT32)) {
        if (valO == null) {
            properties.add(OProperties.int32(prop.getName(), null));
        } else {
            properties.add(OProperties.int32(prop.getName(), Integer.valueOf(String.valueOf(valO))));
        }
    } else if (edmType.equals(EdmSimpleType.BOOLEAN)) {
        //Since Value is registered as ES in ES, it is converted to Boolean
        if (valO == null) {
            properties.add(OProperties.boolean_(prop.getName(), null));
        } else {
            properties.add(OProperties.boolean_(prop.getName(), Boolean.valueOf(String.valueOf(valO))));
        }
    }
}

From source file:io.personium.core.odata.PersoniumExpressionParser.java

License:Apache License

private static CommonExpression readExpressionLiteralProcess(List<Token> tokens) {

    // literals with prefixes
    if (tokens.size() == 2 && tokens.get(0).type == TokenType.WORD
            && tokens.get(1).type == TokenType.QUOTED_STRING) {
        String word = tokens.get(0).value;
        String value = unquote(tokens.get(1).value);
        if (word.equals("datetime")) {
            DateTime dt = parseUTCDateTime(value);
            return Expression.dateTime(new LocalDateTime(dt));
        } else if (word.equals("time")) {
            LocalTime t = InternalUtil.parseTime(value);
            return Expression.time(t);
        } else if (word.equals("datetimeoffset")) {
            DateTime dt = parseDateTime(value);
            return Expression.dateTimeOffset(dt);
        } else if (word.equals("guid")) {
            // odata: dddddddd-dddd-dddd-dddddddddddd
            // java: dddddddd-dd-dd-dddd-dddddddddddd
            // value = value.substring(0, 11) + "-" + value.substring(11);
            return Expression.guid(Guid.fromString(value));
        } else if (word.equals("decimal")) {
            return Expression.decimal(new BigDecimal(value));
        } else if (word.equals("X") || word.equals("binary")) {
            try {
                byte[] bValue = Hex.decodeHex(value.toCharArray());
                return Expression.binary(bValue);
            } catch (DecoderException e) {
                throw Throwables.propagate(e);
            }//from   w w  w. j  a v a 2  s  . c o m
        }
    }
    // long literal: 1234L
    if (tokens.size() == 2 && tokens.get(0).type == TokenType.NUMBER && tokens.get(1).type == TokenType.WORD
            && tokens.get(1).value.equals("L")) {
        long longValue = Long.parseLong(tokens.get(0).value);
        return Expression.int64(longValue);
    }
    // single literal: 2f
    if (tokens.size() == 2 && tokens.get(0).type == TokenType.NUMBER && tokens.get(1).type == TokenType.WORD
            && tokens.get(1).value.equals("f")) {
        float floatValue = Float.parseFloat(tokens.get(0).value);
        return Expression.single(floatValue);
    }
    // single literal: 2.0f
    if (tokens.size() == TOKEN_SIZE_4 && tokens.get(0).type == TokenType.NUMBER
            && tokens.get(1).type == TokenType.SYMBOL && tokens.get(1).value.equals(".")
            && tokens.get(2).type == TokenType.NUMBER && tokens.get(TOKEN_SIZE_3).value.equals("f")) {
        float floatValue = Float.parseFloat(tokens.get(0).value + "." + tokens.get(2).value);
        return Expression.single(floatValue);
    }
    // double literal: 2.0
    if (tokens.size() == TOKEN_SIZE_3 && tokens.get(0).type == TokenType.NUMBER
            && tokens.get(1).type == TokenType.SYMBOL && tokens.get(1).value.equals(".")
            && tokens.get(2).type == TokenType.NUMBER) {
        double doubleValue = Double.parseDouble(tokens.get(0).value + "." + tokens.get(2).value);
        return Expression.double_(doubleValue);
    }
    // double literal: 1E+10
    if (tokens.size() == TOKEN_SIZE_4 && tokens.get(0).type == TokenType.NUMBER
            && tokens.get(1).type == TokenType.WORD && tokens.get(1).value.equals("E")
            && tokens.get(2).type == TokenType.SYMBOL && tokens.get(2).value.equals("+")
            && tokens.get(TOKEN_SIZE_3).type == TokenType.NUMBER) {
        double doubleValue = Double.parseDouble(tokens.get(0).value + "E+" + tokens.get(TOKEN_SIZE_3).value);
        return Expression.double_(doubleValue);
    }
    // double literal: 1E-10
    if (tokens.size() == TOKEN_SIZE_3 && tokens.get(0).type == TokenType.NUMBER
            && tokens.get(1).type == TokenType.WORD && tokens.get(1).value.equals("E")
            && tokens.get(2).type == TokenType.NUMBER) {
        int e = Integer.parseInt(tokens.get(2).value);
        if (e < 1) {
            double doubleValue = Double.parseDouble(tokens.get(0).value + "E" + tokens.get(2).value);
            return Expression.double_(doubleValue);
        }
    }
    // double literal: 1.2E+10
    if (tokens.size() == TOKEN_SIZE_6 && tokens.get(0).type == TokenType.NUMBER
            && tokens.get(1).type == TokenType.SYMBOL && tokens.get(1).value.equals(".")
            && tokens.get(2).type == TokenType.NUMBER && tokens.get(TOKEN_SIZE_3).type == TokenType.WORD
            && tokens.get(TOKEN_SIZE_3).value.equals("E") && tokens.get(TOKEN_SIZE_4).type == TokenType.SYMBOL
            && tokens.get(TOKEN_SIZE_4).value.equals("+")
            && tokens.get(TOKEN_SIZE_5).type == TokenType.NUMBER) {
        double doubleValue = Double.parseDouble(
                tokens.get(0).value + "." + tokens.get(2).value + "E+" + tokens.get(TOKEN_SIZE_5).value);
        return Expression.double_(doubleValue);
    }
    // double literal: 1.2E-10
    if (tokens.size() == TOKEN_SIZE_5 && tokens.get(0).type == TokenType.NUMBER
            && tokens.get(1).type == TokenType.SYMBOL && tokens.get(1).value.equals(".")
            && tokens.get(2).type == TokenType.NUMBER && tokens.get(TOKEN_SIZE_3).type == TokenType.WORD
            && tokens.get(TOKEN_SIZE_3).value.equals("E")
            && tokens.get(TOKEN_SIZE_4).type == TokenType.NUMBER) {
        int e = Integer.parseInt(tokens.get(TOKEN_SIZE_4).value);
        if (e < 1) {
            double doubleValue = Double.parseDouble(
                    tokens.get(0).value + "." + tokens.get(2).value + "E" + tokens.get(TOKEN_SIZE_4).value);
            return Expression.double_(doubleValue);
        }
    }
    // decimal literal: 1234M or 1234m
    if (tokens.size() == 2 && tokens.get(0).type == TokenType.NUMBER && tokens.get(1).type == TokenType.WORD
            && tokens.get(1).value.equalsIgnoreCase("M")) {
        BigDecimal decimalValue = new BigDecimal(tokens.get(0).value);
        return Expression.decimal(decimalValue);
    }
    // decimal literal: 2.0m
    if (tokens.size() == TOKEN_SIZE_4 && tokens.get(0).type == TokenType.NUMBER
            && tokens.get(1).type == TokenType.SYMBOL && tokens.get(1).value.equals(".")
            && tokens.get(2).type == TokenType.NUMBER && tokens.get(TOKEN_SIZE_3).value.equalsIgnoreCase("m")) {
        BigDecimal decimalValue = new BigDecimal(tokens.get(0).value + "." + tokens.get(2).value);
        return Expression.decimal(decimalValue);
    }
    // TODO literals: byteLiteral, sbyteliteral

    return null;

}

From source file:it.cineca.pst.huborcid.web.propertyeditors.LocaleDateTimeEditor.java

License:Open Source License

/**
 * Format the YearMonthDay as String, using the specified format.
 *
 * @return DateTime formatted string//w  w  w  . j  a va2  s  . c  o m
 */
@Override
public String getAsText() {
    Date value = (Date) getValue();
    return value != null ? new LocalDateTime(value).toString(formatter) : "";
}

From source file:it.cineca.pst.huborcid.web.propertyeditors.LocaleDateTimeEditor.java

License:Open Source License

/**
 * Parse the value from the given text, using the specified format.
 *
 * @param text the text to format//from   w  w w .  j  a  v a  2  s  . c o m
 * @throws IllegalArgumentException
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    if (allowEmpty && !StringUtils.hasText(text)) {
        // Treat empty String as null value.
        setValue(null);
    } else {
        setValue(new LocalDateTime(formatter.parseDateTime(text)));
    }
}

From source file:it.smartcommunitylab.climb.domain.model.gamification.PointConcept.java

License:Apache License

/**
 * The method returns the PeriodInstance relative to the index.
 * /* w  w w  . java 2  s.co m*/
 * @param periodIdentifier
 *            identifier of period
 * @param instanceIndex
 *            index of instance
 * @return PeriodInstance bound to the index or null if there is not
 *         PeriodInstance at that index
 */
public PeriodInstance getPeriodInstance(String periodIdentifier, int instanceIndex) {
    PeriodInstance result = null;
    PeriodInternal p = periods.get(periodIdentifier);
    if (p != null) {
        LocalDateTime dateCursor = new LocalDateTime(p.start);
        dateCursor = dateCursor.withPeriodAdded(new org.joda.time.Period(p.period), instanceIndex);
        result = getPeriodInstance(periodIdentifier, dateCursor.toDate().getTime());
    }

    return result;
}

From source file:it.webappcommon.lib.DateUtils.java

License:Open Source License

public static LocalDateTime mergeLocalDateTime(Date date, Date time) {
    // return new LocalDateTime(mergeDateTime(date, time));
    return new LocalDateTime(mergeDateTime2(date, time));
}

From source file:it.webappcommon.lib.DateUtils.java

License:Open Source License

/**
 * // ww w  .  java2  s  .  c om
 * @param date
 * @param time
 * @return
 */
public static DateTime mergeDateTimeUTC(Date date, Date time) {
    // return new Date(date.getYear(), date.getMonth(), date.getDate(),
    // time.getHours(), time.getMinutes(), time.getSeconds());

    LocalDateTime a1 = new LocalDateTime(mergeDateTime(date, time).getTime());
    // LocalDateTime b1 = new LocalDateTime(mergeDateTime(_toDate,
    // _toTime).getTime());

    // Duration d = new Duration(a, b);
    // Duration d1 = new Duration(a1.toDateTime(DateTimeZone.UTC),
    // b1.toDateTime(DateTimeZone.UTC));

    // Calendar calDate =
    // GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
    // Calendar calTime =
    // GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
    //
    // calDate.setTime(date);
    // calTime.setTime(time);
    // calDate.set(Calendar.HOUR_OF_DAY, calTime.get(Calendar.HOUR_OF_DAY));
    // calDate.set(Calendar.MINUTE, calTime.get(Calendar.MINUTE));
    // calDate.set(Calendar.SECOND, calTime.get(Calendar.SECOND));
    // calDate.set(Calendar.MILLISECOND, calTime.get(Calendar.MILLISECOND));
    //
    //
    // return calDate.getTime();

    return a1.toDateTime(DateTimeZone.UTC);
}

From source file:me.vertretungsplan.parser.CSVParser.java

License:Mozilla Public License

@Override
public SubstitutionSchedule getSubstitutionSchedule()
        throws IOException, JSONException, CredentialInvalidException {
    String url = data.getString(PARAM_URL);
    SubstitutionSchedule schedule = SubstitutionSchedule.fromData(scheduleData);

    if (url.startsWith("webdav")) {
        UserPasswordCredential credential = (UserPasswordCredential) this.credential;
        try {// w w  w.  j av  a  2s .c om
            Sardine client = getWebdavClient(credential);
            String httpUrl = url.replaceFirst("webdav", "http");
            List<DavResource> files = client.list(httpUrl);
            for (DavResource file : files) {
                if (!file.isDirectory() && !file.getName().startsWith(".")) {
                    LocalDateTime modified = new LocalDateTime(file.getModified());
                    if (schedule.getLastChange() == null || schedule.getLastChange().isBefore(modified)) {
                        schedule.setLastChange(modified);
                    }
                    InputStream stream = client.get(new URI(httpUrl).resolve(file.getHref()).toString());
                    parseCSV(IOUtils.toString(stream, "UTF-8"), schedule);
                }
            }
            return schedule;
        } catch (GeneralSecurityException | URISyntaxException e) {
            throw new IOException(e);
        }
    } else {
        new LoginHandler(scheduleData, credential, cookieProvider).handleLogin(executor, cookieStore);
        String response = httpGet(url);
        return parseCSV(response, schedule);
    }
}