Example usage for java.time OffsetDateTime parse

List of usage examples for java.time OffsetDateTime parse

Introduction

In this page you can find the example usage for java.time OffsetDateTime parse.

Prototype

public static OffsetDateTime parse(CharSequence text) 

Source Link

Document

Obtains an instance of OffsetDateTime from a text string such as 2007-12-03T10:15:30+01:00 .

Usage

From source file:org.openmhealth.shim.ihealth.mapper.IHealthStepCountDataPointMapperUnitTests.java

@Test
public void asDataPointsShouldReturnDataPointWithUserNoteWhenNoteIsPresent() {

    StepCount expectedStepCount = new StepCount.Builder(4398)
            .setEffectiveTimeFrame(TimeInterval.ofStartDateTimeAndDuration(
                    OffsetDateTime.parse("2015-11-18T00:00:00Z"), new DurationUnitValue(DAY, 1)))
            .setUserNotes("Great steps").build();

    assertThat(dataPoints.get(1).getBody(), Matchers.equalTo(expectedStepCount));

    assertThat(dataPoints.get(0).getBody().getUserNotes(), nullValue());
    assertThat(dataPoints.get(1).getBody().getUserNotes(), equalTo("Great steps"));
}

From source file:org.openmhealth.shim.ihealth.mapper.IHealthDatapointMapperDateTimeUnitTests.java

@Test
public void getDateTimeAtStartOfDayWithCorrectOffsetShouldReturnCorrectDateTimeWhenTimeIsAtStartOfDay() {

    long startOfDayEpochSecond = OffsetDateTime.parse("2015-11-12T00:00:00Z").toEpochSecond();

    OffsetDateTime dateTimeAtStartOfDay = getDateTimeAtStartOfDayWithCorrectOffset(startOfDayEpochSecond,
            "-0100");

    assertThat(dateTimeAtStartOfDay, equalTo(OffsetDateTime.parse("2015-11-12T00:00:00-01:00")));
}

From source file:org.openmhealth.shim.ihealth.mapper.IHealthSleepDurationDataPointMapperUnitTests.java

@Test
public void asDataPointsShouldReturnDataPointWithUserNoteWhenNoteIsPresent() {

    SleepDuration expectedSleepDuration = new SleepDuration.Builder(new DurationUnitValue(MINUTE, 195))
            .setEffectiveTimeFrame(//from  w w w. j  a  v  a 2s  .co m
                    ofStartDateTimeAndEndDateTime(OffsetDateTime.parse("2015-11-15T13:51:00+01:00"),
                            OffsetDateTime.parse("2015-11-15T17:16:00+01:00")))
            .setUserNotes("Best sleep ever").build();

    assertThat(dataPoints.get(1).getBody(), equalTo(expectedSleepDuration));

    assertThat(dataPoints.get(0).getBody().getUserNotes(), nullValue());
    assertThat(dataPoints.get(1).getBody().getUserNotes(), equalTo("Best sleep ever"));
}

From source file:org.openmhealth.shim.ihealth.mapper.IHealthBloodGlucoseDataPointMapperUnitTests.java

@Test
public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() {

    BloodGlucose expectedBloodGlucose = new BloodGlucose.Builder(
            new TypedUnitValue<>(MILLIGRAMS_PER_DECILITER, 70)).setTemporalRelationshipToMeal(AFTER_BREAKFAST)
                    .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-24T14:44:40-06:00")).build();

    assertThat(dataPoints.get(1).getBody(), equalTo(expectedBloodGlucose));

    assertThat(dataPoints.get(1).getBody().getAdditionalProperty("temporal_relationship_to_medication").get(),
            equalTo("After_taking_pills"));

    assertThat(dataPoints.get(1).getHeader().getAcquisitionProvenance().getModality(), equalTo(SELF_REPORTED));
}

From source file:org.openmhealth.shim.ihealth.mapper.IHealthDatapointMapperDateTimeUnitTests.java

@Test
public void getDateTimeAtStartOfDayWithCorrectOffsetShouldReturnCorrectDateTimeWhenTimeIsAtEndOfDay() {

    long startOfDayEpochSecond = OffsetDateTime.parse("2015-11-12T23:59:59Z").toEpochSecond();

    OffsetDateTime dateTimeAtStartOfDay = getDateTimeAtStartOfDayWithCorrectOffset(startOfDayEpochSecond,
            "+0100");

    assertThat(dateTimeAtStartOfDay, equalTo(OffsetDateTime.parse("2015-11-12T00:00:00+01:00")));
}

From source file:org.openmhealth.shim.ihealth.mapper.IHealthDatapointMapperDateTimeUnitTests.java

public void testTimeFrameWhenItShouldBeSetCorrectly(String timezoneString, String expectedDateTime)
        throws IOException {

    JsonNode timeInfoNode = createResponseNodeWithTimeZone(timezoneString);
    Optional<TimeFrame> effectiveTimeFrameAsDateTime = getEffectiveTimeFrameAsDateTime(timeInfoNode);

    assertThat(effectiveTimeFrameAsDateTime.isPresent(), is(true));
    assertThat(effectiveTimeFrameAsDateTime.get().getDateTime(),
            equalTo(OffsetDateTime.parse(expectedDateTime)));
}

From source file:org.silverpeas.core.webapi.calendar.CalendarEventRecurrenceEntity.java

/**
 * Get the model representation of a recurrence with the entity data.
 * @param event the event on which the recurrence must be set.
 * @param occurrencePeriod the occurrence period in the case of an occurrence entity get.
 * @return a {@link CalendarEvent} instance.
 *//* w w  w .j a  va 2s  .c  o  m*/
@XmlTransient
Recurrence applyOn(CalendarEvent event, Period occurrencePeriod) {
    Recurrence recurrence = event.getRecurrence();
    if (event.getRecurrence() != null) {
        recurrence.withFrequency(getFrequency().getModel());
    } else {
        recurrence = event.recur(Recurrence.from(getFrequency().getModel())).getRecurrence();
    }
    if (count > 0) {
        recurrence.until(count);
    } else if (isDefined(endDate)) {
        final boolean onAllDay = occurrencePeriod == null ? event.isOnAllDay() : occurrencePeriod.isInDays();
        if (onAllDay) {
            recurrence.until(LocalDate.parse(endDate));
        } else {
            recurrence.until(OffsetDateTime.parse(endDate));
        }
    } else {
        recurrence.endless();
    }
    if (!daysOfWeek.isEmpty()) {
        recurrence
                .on(daysOfWeek.stream().map(DayOfWeekOccurrenceEntity::getModel).collect(Collectors.toList()));
    } else {
        recurrence.onNoSpecificDay();
    }
    return recurrence;
}

From source file:org.jimsey.projects.turbine.fuel.domain.TickJson.java

@Deprecated
public String toStringWithoutJson() {
    // {"date": 1401174943825, "open": 99.52, "high": 99.58, "low": 98.99, "close": 99.08, "volume": 100},

    OffsetDateTime date = OffsetDateTime.parse(getEndTime().toString());

    return String.format(
            "{\"date\": %tQ, \"open\": %.2f, \"high\": %.2f, \"low\": %.2f, \"close\": %.2f, \"volume\": %.0f},",
            date, getOpenPrice().toDouble(), getMaxPrice().toDouble(), getMinPrice().toDouble(),
            getClosePrice().toDouble(), getVolume().toDouble());
}