Java Code Examples for org.joda.time.DateTime#toDateTime()

The following examples show how to use org.joda.time.DateTime#toDateTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateWidget.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private void setAnswer() {
    if (getCurrentAnswer() != null) {

        //The incoming date is in Java Format, parsed from an ISO-8601 date.
        DateTime isoAnchoredDate =
                new DateTime(((Date)getCurrentAnswer().getValue()).getTime());

        //The java date we loaded doesn't know how to communicate its timezone offsets to
        //Joda if the offset for the datetime represented differs from what it is currently.
        //This is the case, for instance, in historical dates where timezones offsets were
        //different. This method identifies what offset the Java date actually was using.
        DateTimeZone correctedAbsoluteOffset =
                DateTimeZone.forOffsetMillis(-isoAnchoredDate.toDate().getTimezoneOffset() * 60 * 1000);

        //Then manually loads it back into a Joda datetime for manipulation
        DateTime adjustedDate = isoAnchoredDate.toDateTime(correctedAbsoluteOffset);


        mDatePicker.init(adjustedDate.getYear(), adjustedDate.getMonthOfYear() - 1, adjustedDate.getDayOfMonth(),
                mDateListener);
    } else {
        // create date widget with current time as of right now
        clearAnswer();
    }
}
 
Example 2
Source File: DeploymentServiceModel.java    From remote-monitoring-services-java with MIT License 5 votes vote down vote up
private String formatDateTimeToUTC(String originalTime) {
    DateTime dateTime = DateTime.parse(originalTime);

    // TODO: Remove workaround for Java SDK bug not returning time in UTC.
    try {
        dateTime = dateTime.toDateTime(DateTimeZone.UTC);
    } catch(Exception ex) {
        // Swallow exception and use date as-is.
    }

    return dateTime.toString(DATE_FORMAT_STRING);
}
 
Example 3
Source File: OnlineUtils.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public static DateTime toCetDate(DateTime date) {
    DateTimeZone cet = DateTimeZone.forID("CET");
    if (!date.getZone().equals(cet)) {
        return date.toDateTime(cet);
    }
    return date;
}
 
Example 4
Source File: EntsoeCaseRepository.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
private static DateTime toCetDate(DateTime date) {
    DateTimeZone cet = DateTimeZone.forID("CET");
    if (!date.getZone().equals(cet)) {
        return date.toDateTime(cet);
    }
    return date;
}
 
Example 5
Source File: ClockSetRequestMessage.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
public ClockSetRequestMessage(String MAC, DateTime stamp) {
    super(MAC, "");
    type = MessageType.CLOCK_SET_REQUEST;

    // Circles expect clock info to be in the UTC timezone
    this.stamp = stamp.toDateTime(DateTimeZone.UTC);
}
 
Example 6
Source File: UVFEncoder.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
private DateTime checkTimeZone(DateTime time) {
    if (timeZone != null) {
        return time.toDateTime(timeZone);
    }
    return time;
}
 
Example 7
Source File: EventQueryNode.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings) throws QueryEvaluationException {
    final List<BindingSet> list = new ArrayList<>();
    try {
        final Collection<Event> searchEvents;
        final String subj;
        //if the provided binding set has the subject already, set it to the constant subject.
        if(!subjectConstant.isPresent() && bindings.hasBinding(subjectVar.get())) {
            subjectConstant = Optional.of(bindings.getValue(subjectVar.get()).stringValue());
        } else if(bindings.size() != 0) {
            list.add(bindings);
        }

        // If the subject needs to be filled in, check if the subject variable is in the binding set.
        if(subjectConstant.isPresent()) {
            // if it is, fetch that value and then fetch the entity for the subject.
            subj = subjectConstant.get();
            searchEvents = eventStore.search(Optional.of(new RyaIRI(subj)), Optional.of(geoFilters), Optional.of(temporalFilters));
        } else {
            searchEvents = eventStore.search(Optional.empty(), Optional.of(geoFilters), Optional.of(temporalFilters));
        }

        for(final Event event : searchEvents) {
            final MapBindingSet resultSet = new MapBindingSet();
            if(event.getGeometry().isPresent()) {
                final Geometry geo = event.getGeometry().get();
                final Value geoValue = VF.createLiteral(geo.toText());
                final Var geoObj = geoPattern.getObjectVar();
                resultSet.addBinding(geoObj.getName(), geoValue);
            }

            final Value temporalValue;
            if(event.isInstant() && event.getInstant().isPresent()) {
                final Optional<TemporalInstant> opt = event.getInstant();
                DateTime dt = opt.get().getAsDateTime();
                dt = dt.toDateTime(DateTimeZone.UTC);
                final String str = dt.toString(TemporalInstantRfc3339.FORMATTER);
                temporalValue = VF.createLiteral(str);
            } else if(event.getInterval().isPresent()) {
                temporalValue = VF.createLiteral(event.getInterval().get().getAsPair());
            } else {
                temporalValue = null;
            }

            if(temporalValue != null) {
                final Var temporalObj = temporalPattern.getObjectVar();
                resultSet.addBinding(temporalObj.getName(), temporalValue);
            }
            list.add(resultSet);
        }
    } catch (final ObjectStorageException e) {
        throw new QueryEvaluationException("Failed to evaluate the binding set", e);
    }
    return new CollectionIteration<>(list);
}