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() 

Source Link

Document

Constructs an instance set to the current local time evaluated using ISO chronology in the default zone.

Usage

From source file:org.openhat.androPDI.ports.editors.DialPortDateTimeEditor.java

License:Open Source License

protected void setEventTime(int selectedPosition) {

    LocalDateTime dateTime = null;

    switch (selectedPosition) {
    /*//  w w w  . j a  v  a 2  s  .c  o m
          <item>Select&#8230;</item>
           <item>In 30 seconds</item>
            <item>In one minute</item>
            <item>In five minutes</item>
            <item>In 15 minutes</item>
            <item>In one hour</item>
            <item>In two hours</item>
            <item>In six hours</item>
            <item>In one day</item>
     */
    case 1: // 30 seconds
        dateTime = new LocalDateTime().plusSeconds(30);
        break;
    case 2: // one minute
        dateTime = new LocalDateTime().plusMinutes(1);
        break;
    case 3: // five minutes
        dateTime = new LocalDateTime().plusMinutes(5);
        break;
    case 4: // 15 minutes
        dateTime = new LocalDateTime().plusMinutes(15);
        break;
    case 5: // 30 minutes
        dateTime = new LocalDateTime().plusMinutes(30);
        break;
    case 6: // one hour
        dateTime = new LocalDateTime().plusHours(1);
        break;
    case 7: // two hours
        dateTime = new LocalDateTime().plusHours(2);
        break;
    case 8: // six hours
        dateTime = new LocalDateTime().plusHours(6);
        break;
    case 9: // one day
        dateTime = new LocalDateTime().plusDays(1);
        break;
    default:
        return;
    }

    tvDate.setText(DateTimeFormat.mediumDate().print(dateTime));
    tvTime.setText(DateTimeFormat.mediumTime().print(dateTime));

    currentDate = dateTime;
}

From source file:org.openmrs.mobile.activities.auditdata.AuditDataFragment.java

License:Open Source License

/**
 * This function  assigns values to an Observation object
 * @param observation         the observation that you want to set the values
 * @param questionConceptUuid The uuid of the Concept that the is used a question
 * @param answerConceptUuid   The uuid of the Concept that the user has selected as the answer
 *///from  w w w .ja  v a  2 s .c  o  m
private Observation setObservationFields(Observation observation, String questionConceptUuid,
        String answerConceptUuid, String display) {

    if (observation == null) {
        observation = new Observation();
    }

    //here we assign all observations current time
    LocalDateTime localDateTime = new LocalDateTime();
    String timeString = localDateTime.toString();

    Concept concept = new Concept();
    concept.setUuid(questionConceptUuid);

    Person person = new Person();
    person.setUuid(patientUuid);

    observation.setConcept(concept);
    observation.setPerson(person);
    observation.setValue(answerConceptUuid);
    observation.setObsDatetime(timeString);

    if (display != null) {
        observation.setDisplay(display);
    }

    return observation;
}

From source file:org.openmrs.mobile.activities.capturevitals.CaptureVitalsFragment.java

License:Open Source License

private Observation setObservationFields(String conceptUuid, String inputValue) {

    Observation observation = new Observation();

    LocalDateTime localDateTime = new LocalDateTime();
    String timeString = localDateTime.toString();

    Concept concept = new Concept();
    concept.setUuid(conceptUuid);/*from  ww w.ja v  a  2  s .com*/

    Person person = new Person();
    person.setUuid(patientUuid);

    observation.setConcept(concept);
    observation.setPerson(person);
    observation.setObsDatetime(timeString);
    observation.setValue(inputValue);

    return observation;
}

From source file:org.openmrs.mobile.activities.formdisplay.FormDisplayMainPresenter.java

License:Mozilla Public License

@Override
public void createEncounter() {
    List<InputField> inputFields = new ArrayList<>();
    List<SelectOneField> radioGroupFields = new ArrayList<>();

    mFormDisplayView.enableSubmitButton(false);

    Encountercreate encountercreate = new Encountercreate();
    encountercreate.setPatient(mPatient.getUuid());
    encountercreate.setEncounterType(mEncountertype);

    List<Obscreate> observations = new ArrayList<>();

    SparseArray<Fragment> activefrag = mPageAdapter.getRegisteredFragments();
    boolean valid = true;
    for (int i = 0; i < activefrag.size(); i++) {
        FormDisplayPageFragment formPageFragment = (FormDisplayPageFragment) activefrag.get(i);
        if (!formPageFragment.checkInputFields()) {
            valid = false;//ww  w .j a  v  a 2s .co  m
            break;
        }

        inputFields.addAll(formPageFragment.getInputFields());
        radioGroupFields.addAll(formPageFragment.getSelectOneFields());
    }

    if (valid) {
        for (InputField input : inputFields) {
            if (input.getValue() != -1.0) {
                Obscreate obscreate = new Obscreate();
                obscreate.setConcept(input.getConcept());
                obscreate.setValue(String.valueOf(input.getValue()));
                LocalDateTime localDateTime = new LocalDateTime();
                obscreate.setObsDatetime(localDateTime.toString());
                obscreate.setPerson(mPatient.getUuid());
                observations.add(obscreate);
            }
        }

        for (SelectOneField radioGroupField : radioGroupFields) {
            if (radioGroupField.getChosenAnswer() != null) {
                Obscreate obscreate = new Obscreate();
                obscreate.setConcept(radioGroupField.getConcept());
                obscreate.setValue(radioGroupField.getChosenAnswer().getConcept());
                LocalDateTime localDateTime = new LocalDateTime();
                obscreate.setObsDatetime(localDateTime.toString());
                obscreate.setPerson(mPatient.getUuid());
                observations.add(obscreate);
            }
        }

        encountercreate.setObservations(observations);
        encountercreate.setFormname(mFormname);
        encountercreate.setPatientId(mPatientID);
        encountercreate.setFormUuid(getFormResourceByName(mFormname).getUuid());
        encountercreate.setObslist();
        encountercreate.save();

        if (!mPatient.isSynced()) {
            mPatient.addEncounters(encountercreate.getId());
            new PatientDAO().updatePatient(mPatient.getId(), mPatient);
            ToastUtil.error("Patient not yet registered. Form data is saved locally "
                    + "and will sync when internet connection is restored. ");
            mFormDisplayView.enableSubmitButton(true);
        } else {
            new EncounterService().addEncounter(encountercreate, new DefaultResponseCallbackListener() {
                @Override
                public void onResponse() {
                    mFormDisplayView.enableSubmitButton(true);
                }

                @Override
                public void onErrorResponse(String errorMessage) {
                    mFormDisplayView.showToast(errorMessage);
                    mFormDisplayView.enableSubmitButton(true);
                }
            });
            mFormDisplayView.quitFormEntry();
        }
    } else {
        mFormDisplayView.enableSubmitButton(true);
    }
}

From source file:org.openmrs.mobile.activities.FormDisplayActivity.java

License:Mozilla Public License

void createEncounter() {
    Encountercreate encountercreate = new Encountercreate();
    encountercreate.setPatient(mPatient.getUuid());
    encountercreate.setEncounterType(encountertype);

    List<Obscreate> observations = new ArrayList<>();

    List<Fragment> activefrag = getActiveFragments();
    boolean valid = true;
    for (Fragment f : activefrag) {
        FormPageFragment formPageFragment = (FormPageFragment) f;
        if (!formPageFragment.checkfields()) {
            valid = false;//from  w  w w .  ja va 2 s  .co m
            break;
        }
        List<InputField> pageinputlist = formPageFragment.getInputFields();
        inputlist.addAll(pageinputlist);
    }

    if (valid) {
        for (InputField input : inputlist) {
            if (input.getValue() != -1.0) {
                Obscreate obscreate = new Obscreate();
                obscreate.setConcept(input.getConcept());
                obscreate.setValue(input.getValue());
                LocalDateTime localDateTime = new LocalDateTime();
                obscreate.setObsDatetime(localDateTime.toString());
                obscreate.setPerson(mPatient.getUuid());
                observations.add(obscreate);
            }
        }

        encountercreate.setObservations(observations);
        encountercreate.setFormname(formname);
        encountercreate.setPatientId(mPatientID);
        encountercreate.setObslist();
        encountercreate.save();

        if (!mPatient.isSynced()) {
            mPatient.addEncounters(encountercreate.getId());
            new PatientDAO().updatePatient(mPatient.getId(), mPatient);
            ToastUtil.error("Patient not yet registered. Form data is saved locally "
                    + "and will sync when internet connection is restored. ");
        } else
            new EncounterService().addEncounter(encountercreate);
        finish();
    }

}

From source file:org.powertac.common.builders.CashBuilder.java

License:Apache License

/**
 * Sets the dateCreated property in the CashBuilder to the instant in time the method was called
 * @return CashBuilder instance with updated dateCreated property
 *///from  w  w  w  .j ava2 s. com
public CashBuilder setDateCreatedToNow() {
    this.dateCreated = new LocalDateTime();
    return this;
}

From source file:org.specrunner.converters.core.ConverterLocalDateTimeCurrentTemplate.java

License:Open Source License

@Override
protected LocalDateTime instance() {
    return new LocalDateTime();
}

From source file:propel.core.collections.volatiles.KeyValueSessionStore.java

License:Open Source License

/**
 * Overloaded constructor, initializes session with a session expiration time and polling interval in milliseconds. Set to
 * CONSTANT.TIMEOUT_INFINITE to disable expiration.
 * //from  ww  w  . j  a va2 s. c o  m
 * @throws IllegalArgumentException When the values provided are out of range.
 * @throws SuperTypeTokenException When called without using anonymous class semantics.
 */
public KeyValueSessionStore(int expirationMillis, int pollingIntervalMillis) {
    setExpirationMillis(expirationMillis);
    setPollingIntervalMillis(pollingIntervalMillis);

    reEntrantLock = new ReentrantLock();
    store = new AvlHashtable<TKey, TValue>(SuperTypeToken.getClazz(this.getClass(), 0),
            SuperTypeToken.getClazz(this.getClass(), 1));
    expiries = new AvlHashtable<TKey, LocalDateTime>(store.getGenericTypeParameterKey(), LocalDateTime.class);

    // daemon timer, allows for app shutdown when no other thread exists that could use the session
    expirationTimer = new Timer(true);

    // check if expiration is enabled
    if (expirationMillis >= 0)
        expirationTimer.scheduleAtFixedRate(new ExpirationCheckingTimerTask(),
                new LocalDateTime().plusMillis(expirationMillis).toDateTime().toDate(), pollingIntervalMillis);
}

From source file:propel.core.collections.volatiles.KeyValueSessionStore.java

License:Open Source License

/**
 * Overloaded constructor, initializes session with a session expiration time and polling interval in milliseconds. Set to
 * CONSTANT.TIMEOUT_INFINITE to disable expiration.
 * //  w w w.j ava  2s .  c o m
 * @throws IllegalArgumentException When the values provided are out of range.
 * @throws NullPointerException When a generic type parameter class is null.
 */
public KeyValueSessionStore(int expirationMillis, int pollingIntervalMillis, Class<?> genericTypeParameterKey,
        Class<?> genericTypeParameterValue) {
    setExpirationMillis(expirationMillis);
    setPollingIntervalMillis(pollingIntervalMillis);

    reEntrantLock = new ReentrantLock();
    store = new AvlHashtable<TKey, TValue>(genericTypeParameterKey, genericTypeParameterValue);
    expiries = new AvlHashtable<TKey, LocalDateTime>(genericTypeParameterKey, LocalDateTime.class);

    // daemon timer, allows for app shutdown when no other thread exists that could use the session
    expirationTimer = new Timer(true);

    // check if expiration is enabled
    if (expirationMillis >= 0)
        expirationTimer.scheduleAtFixedRate(new ExpirationCheckingTimerTask(),
                new LocalDateTime().plusMillis(expirationMillis).toDateTime().toDate(), pollingIntervalMillis);
}

From source file:propel.core.collections.volatiles.KeyValueSessionStore.java

License:Open Source License

/**
 * Adds an item to the collection Returns true if successful. This is an O(log2(n)) operation.
 * //  w w  w. ja  v a2  s .  c  o m
 * @throws NullPointerException Key is null
 */
@Override
public boolean add(TKey key, TValue value) {
    if (key == null)
        throw new NullPointerException("key");

    lock();
    try {
        // attempt to add value
        if (store.add(key, value)) {
            // set expiry
            expiries.add(key, new LocalDateTime().plusMillis(expirationMillis));
            return true;
        }

        return false;
    } finally {
        unlock();
    }
}