List of usage examples for org.joda.time LocalDateTime toDateTime
public DateTime toDateTime()
From source file:energy.usef.dso.model.ConnectionMeterEvent.java
License:Apache License
public void setDateTime(LocalDateTime dateTime) { if (dateTime == null) { this.dateTime = null; } else {/*ww w . j ava2s. c o m*/ this.dateTime = dateTime.toDateTime().toDate(); } }
From source file:eu.smartenit.unada.sa.SocialAnalyzer.java
License:Apache License
/** * Calculates the age of a video in weeks. * * @param publishDate Point in time at which the video was published. * @param feedDate Point in time at which the video was posted on the users wall. * @return The age of the video in weeks or -1 if it could not be calculated. *///from w w w . jav a2 s .co m private double calculateAge(Date publishDate, Date feedDate) { if (publishDate == null || feedDate == null) { return -1; } else { LocalDateTime feedPublished = new LocalDateTime(feedDate); LocalDateTime videoPublished = new LocalDateTime(publishDate); double ageInMilliseconds = feedPublished.toDateTime().getMillis() - videoPublished.toDateTime().getMillis(); return ageInMilliseconds / 1000 / 60 / 60 / 24 / 7; } }
From source file:eu.trentorise.game.managers.QuartzTaskManager.java
License:Apache License
private Date calculateStartDate(Date initialStart, long period) { if (period <= 0) { return initialStart; }/* ww w .ja v a 2 s . c o m*/ LocalDateTime start = new LocalDateTime(initialStart); while (start.toDateTime().isBeforeNow()) { start = start.plusMillis((int) period); } return start.toDate(); }
From source file:graphene.util.time.JodaTimeUtil.java
License:Apache License
public static java.util.Date toJavaDate(final LocalDateTime ldt) { // TODO - confirm this conversion always works, esp. across timezones final java.util.Date d = (ldt == null ? null : new java.util.Date(ldt.toDateTime().getMillis())); return d;/*from w w w . j a v a 2 s. co m*/ }
From source file:graphene.util.time.JodaTimeUtil.java
License:Apache License
public static java.sql.Timestamp toSQLTimestamp(final LocalDateTime ldt) { // TODO - confirm this conversion always works, esp. across timezones final java.sql.Timestamp ts = (ldt == null ? null : new java.sql.Timestamp(ldt.toDateTime().getMillis())); return ts;// ww w .j av a 2s . co m }
From source file:io.personium.core.model.Box.java
License:Apache License
/** * Constructor./*from w w w . ja v a2 s . c om*/ * @param cell cell object * @param entity OEntity object */ public Box(final Cell cell, final OEntity entity) { this.cell = cell; if (entity == null) { // Process for the MAIN BOX this.name = Box.DEFAULT_BOX_NAME; // Schema URL of MAIN BOX is the URL of its own cell this.schema = cell.getUrl(); // Internal ID of MAIN BOX will be together with the ID of the cell. this.id = cell.getId(); return; } this.name = (String) entity.getProperty(Common.P_NAME.getName()).getValue(); this.schema = (String) entity.getProperty(P_SCHEMA.getName()).getValue(); if (entity instanceof OEntityWrapper) { OEntityWrapper oew = (OEntityWrapper) entity; this.id = oew.getUuid(); } LocalDateTime dateTime = (LocalDateTime) entity.getProperty(Common.P_PUBLISHED.getName()).getValue(); this.published = dateTime.toDateTime().getMillis(); }
From source file:io.personium.core.model.impl.es.doc.OEntityDocHandler.java
License:Apache License
/** * Create a DocHandler without ID from OEntityWrapper. * @param typeName ES type name//from w ww .j av a 2 s . c o m * @param oEntityWrapper OEntityWrapper * @param metadata schema information */ @SuppressWarnings("unchecked") protected void initInstance(String typeName, OEntityWrapper oEntityWrapper, EdmDataServices metadata) { this.type = typeName; //Set the specified uuid as ES ID this.id = oEntityWrapper.getUuid(); //When OEntity Wrapper is used, add Version, hidden field this.hiddenFields = oEntityWrapper.getMetadata(); //Set UnitUser name only when accessing Cell resolveUnitUserName(); String etag = oEntityWrapper.getEtag(); if (etag != null && etag.length() > 1) { this.version = Long.valueOf(etag.substring(0, etag.indexOf("-"))); } //Retrieve schema information EdmEntitySet entitySet = oEntityWrapper.getEntitySet(); EdmEntityType eType = entitySet.getType(); //Get the NavProp defined in the schema List<EdmNavigationProperty> navProps = eType.getDeclaredNavigationProperties().toList(); for (EdmNavigationProperty np : navProps) { //About each NavProp EdmMultiplicity mf = np.getFromRole().getMultiplicity(); EdmMultiplicity mt = np.getToRole().getMultiplicity(); //As Association's Multiplicity, when this side is MANY and the opponent is ONE, //From the value (URL) of NavigationProperty, the item of l is determined and packed if (EdmMultiplicity.ONE.equals(mt) && EdmMultiplicity.MANY.equals(mf)) { //TODO not implemented yet log.debug("many to one"); } } //For all properties that came up, for (OProperty<?> prop : oEntityWrapper.getProperties()) { //Checks whether it is defined in the schema, and switches processing between Dynamic Property and Declared Property String propName = prop.getName(); EdmProperty edmProperty = eType.findProperty(propName); //Branch processing by predefined Property or DynamicProperty if (edmProperty != null) { //Schema-defined properties //TODO It is unknown whether to do here, but check whether data corresponding to the type defined in the schema is coming //You should do it earlier. //Refill the values for each type. Object value = prop.getValue(); if ("__published".equals(propName)) { OProperty<LocalDateTime> propD = (OProperty<LocalDateTime>) prop; LocalDateTime ldt = propD.getValue(); this.published = ldt.toDateTime().getMillis(); } else if ("__updated".equals(propName)) { OProperty<LocalDateTime> propD = (OProperty<LocalDateTime>) prop; LocalDateTime ldt = propD.getValue(); this.updated = ldt.toDateTime().getMillis(); } else { CollectionKind ck = edmProperty.getCollectionKind(); if (edmProperty.getType().isSimple()) { if (ck.equals(CollectionKind.List)) { //Error if invalid type if (value == null || value instanceof OCollection<?>) { this.staticFields.put(prop.getName(), getSimpleList(edmProperty.getType(), (OCollection<OObject>) value)); } else { throw PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR .params(prop.getName()); } } else { value = getSimpleValue(prop, edmProperty.getType()); //If Property is Simple type, add it as defined item as it is this.staticFields.put(prop.getName(), value); } } else { String complexTypeName = edmProperty.getType().getFullyQualifiedTypeName(); if (ck.equals(CollectionKind.List)) { //If CollectionKind is List, add by array this.staticFields.put(prop.getName(), getComplexList( (OCollection<OComplexObject>) prop.getValue(), metadata, complexTypeName)); } else { //If Property is Complex type, read and add ComplexType property recursively this.staticFields.put(prop.getName(), getComplexType(prop, metadata, complexTypeName)); } } } } else { //Dynamic property receives String, Integer, Float, Boolean Object propValue = prop.getValue(); if ("Edm.DateTime".equals(prop.getType().getFullyQualifiedTypeName())) { OProperty<LocalDateTime> propD = (OProperty<LocalDateTime>) prop; LocalDateTime ldt = propD.getValue(); if (ldt != null) { propValue = "\\/Date(" + ldt.toDateTime().toDate().getTime() + ")\\/"; } } this.dynamicFields.put(prop.getName(), propValue); } } }
From source file:io.personium.core.model.impl.es.doc.UserDataDocHandler.java
License:Apache License
/** * Return a property value object converted to an appropriate type according to the property definition of the schema. * In the case of user data, convert the Boolean type property value to a character string. * @param prop property object//from w w w.jav a 2 s. co m * Property definition for @param edmType schema * @return Property value object converted to appropriate type */ @Override @SuppressWarnings("unchecked") protected Object getSimpleValue(OProperty<?> prop, EdmType edmType) { if (edmType.equals(EdmSimpleType.DATETIME)) { OProperty<LocalDateTime> propD = (OProperty<LocalDateTime>) prop; LocalDateTime ldt = propD.getValue(); if (ldt != null) { return ldt.toDateTime().getMillis(); } } //Convert Boolean / Double property values to string if (prop.getValue() != null && (edmType.equals(EdmSimpleType.BOOLEAN) || edmType.equals(EdmSimpleType.DOUBLE))) { return String.valueOf(prop.getValue()); } return prop.getValue(); }
From source file:me.vertretungsplan.parser.ParserUtils.java
License:Mozilla Public License
static LocalDateTime parseDateTime(String string) { if (string == null) return null; reinitIfNeeded();//from ww w. ja va2 s . c o m string = string.replace("Stand:", "").replace("Import:", "").trim(); int i = 0; for (DateTimeFormatter f : dateTimeFormatters) { try { LocalDateTime dt = f.parseLocalDateTime(string); if (dateTimeFormats[i].contains("yyyy")) { return dt; } else { Duration currentYearDifference = abs(new Duration(DateTime.now(), dt.toDateTime())); Duration lastYearDifference = abs(new Duration(DateTime.now(), dt.minusYears(1).toDateTime())); Duration nextYearDifference = abs(new Duration(DateTime.now(), dt.plusYears(1).toDateTime())); if (lastYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateTimeFormats[i]).withLocale(Locale.GERMAN) .withDefaultYear(f.getDefaultYear() - 1).parseLocalDateTime(string); } else if (nextYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateTimeFormats[i]).withLocale(Locale.GERMAN) .withDefaultYear(f.getDefaultYear() + 1).parseLocalDateTime(string); } else { return dt; } } } catch (IllegalArgumentException e) { // Does not match this format, try the next one } i++; } // Does not match any known format :( return null; }
From source file:org.apache.cayenne.joda.access.types.LocalDateTimeType.java
License:Apache License
@Override public void setJdbcObject(PreparedStatement statement, LocalDateTime value, int pos, int type, int scale) throws Exception { if (value == null) { statement.setNull(pos, type);/*ww w . jav a2 s. c o m*/ } else { Timestamp ts = new Timestamp(value.toDateTime().getMillis()); statement.setTimestamp(pos, ts); } }