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.withings.mapper.WithingsBloodPressureDataPointMapperUnitTests.java

@Test
public void asDataPointsShouldReturnCorrectDataPoints() {

    List<DataPoint<BloodPressure>> actualDataPoints = mapper.asDataPoints(singletonList(responseNode));

    BloodPressure expectedBloodPressure = new BloodPressure.Builder(
            new SystolicBloodPressure(MM_OF_MERCURY, 104.0), new DiastolicBloodPressure(MM_OF_MERCURY, 68.0))
                    .setEffectiveTimeFrame(OffsetDateTime.parse("2015-05-31T06:06:23Z")).build();

    assertThat(actualDataPoints.get(0).getBody(), equalTo(expectedBloodPressure));

    DataPointHeader actualDataPointHeader = actualDataPoints.get(0).getHeader();
    assertThat(actualDataPointHeader.getBodySchemaId(), equalTo(SCHEMA_ID));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getModality(), equalTo(SENSED));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getSourceName(),
            equalTo(RESOURCE_API_SOURCE_NAME));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getAdditionalProperties().get("external_id"),
            equalTo(366956482L));//from   ww  w .j  a v  a 2  s .  co  m
}

From source file:org.openmhealth.shim.withings.mapper.WithingsSleepDurationDataPointMapperUnitTests.java

@Test
public void asDataPointsShouldReturnCorrectDataPoints() {

    List<DataPoint<SleepDuration>> dataPoints = mapper.asDataPoints(responseNode);

    SleepDuration expectedSleepDuration = new SleepDuration.Builder(new DurationUnitValue(SECOND, 37460))
            .setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime(OffsetDateTime.parse("2014-09-12T11:34:19Z"),
                    OffsetDateTime.parse("2014-09-12T17:22:57Z")))
            .build();//from  w ww . ja  v a2 s .c  o  m

    expectedSleepDuration.setAdditionalProperty("wakeup_count", 3);
    expectedSleepDuration.setAdditionalProperty("light_sleep_duration", new DurationUnitValue(SECOND, 18540));
    expectedSleepDuration.setAdditionalProperty("deep_sleep_duration", new DurationUnitValue(SECOND, 8460));
    expectedSleepDuration.setAdditionalProperty("rem_sleep_duration", new DurationUnitValue(SECOND, 10460));
    expectedSleepDuration.setAdditionalProperty("duration_to_sleep", new DurationUnitValue(SECOND, 420));

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

    assertThat(dataPoints.get(0).getBody().getAdditionalProperties(),
            equalTo(expectedSleepDuration.getAdditionalProperties()));

    DataPointAcquisitionProvenance acquisitionProvenance = dataPoints.get(0).getHeader()
            .getAcquisitionProvenance();

    assertThat(acquisitionProvenance.getSourceName(),
            equalTo(WithingsDataPointMapper.RESOURCE_API_SOURCE_NAME));
    assertThat(acquisitionProvenance.getModality(), equalTo(SENSED));
    assertThat(acquisitionProvenance.getAdditionalProperties().get("external_id"), equalTo(16616514L));
    assertThat(acquisitionProvenance.getAdditionalProperties().get("device_name"), equalTo("Aura"));
    assertThat(dataPoints.get(0).getHeader().getBodySchemaId(), equalTo(SCHEMA_ID));
}

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

@Test
public void asDataPointsShouldReturnCorrectSensedDataPoints() {

    PhysicalActivity.Builder expectedPhysicalActivityBuilder = new PhysicalActivity.Builder(
            "Swimming, breaststroke")
                    .setEffectiveTimeFrame(TimeInterval.ofStartDateTimeAndEndDateTime(
                            OffsetDateTime.parse("2015-09-17T20:02:28-08:00"),
                            OffsetDateTime.parse("2015-09-17T20:32:28-08:00")))
                    .setCaloriesBurned(new KcalUnitValue(KILOCALORIE, 221.5));

    assertThat(dataPoints.get(0).getBody(), equalTo(expectedPhysicalActivityBuilder.build()));

    testDataPointHeader(dataPoints.get(0).getHeader(), SCHEMA_ID, SENSED, "3f8770f51cc84957a57d20f4fee1f34b",
            OffsetDateTime.parse("2015-09-17T20:02:57Z"));
}

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

@Test
public void asDataPointsShouldReturnCorrectSensedDataPoints() {

    BodyMassIndex expectedBodyMassIndex = new BodyMassIndex.Builder(
            new TypedUnitValue<>(KILOGRAMS_PER_SQUARE_METER, 22.56052563257619))
                    .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T12:04:09-08:00")).build();

    assertThat(dataPoints.get(0).getBody(), equalTo(expectedBodyMassIndex));

    testDataPointHeader(dataPoints.get(0).getHeader(), SCHEMA_ID, SENSED, "5fe5893c418b48cd8da7954f8b6c2f36",
            OffsetDateTime.parse("2015-09-17T20:04:17Z"));
}

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

@Test
public void asDataPointsShouldReturnCorrectDataPointsWhenSensed() {

    SleepDuration expectedSleepDuration = new SleepDuration.Builder(new DurationUnitValue(MINUTE, 345))
            .setEffectiveTimeFrame(/*from  w  ww .  j  a  v  a2 s.  c  o  m*/
                    ofStartDateTimeAndEndDateTime(OffsetDateTime.parse("2015-11-15T01:51:00-07:00"),
                            OffsetDateTime.parse("2015-11-15T09:16:00-07:00")))
            .build();

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

    testDataPointHeader(dataPoints.get(0).getHeader(), SCHEMA_ID, SENSED, "7eb7292b90d710ae7b7f61b75f9425cf",
            OffsetDateTime.parse("2015-11-15T16:19:10Z"));
}

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

public Entity(OffsetDateTime date, double close, String symbol, String market, String name, String timestamp) {
    this.timestamp = date;
    this.close = close;
    this.symbol = symbol;
    this.market = market;
    this.name = name;
    try {//from www .j a  v a 2  s .co  m
        this.date = date.toInstant().toEpochMilli();
    } catch (Exception e) {
        logger.warn("Could not parse date: {}", date.toString());
    }
    try {
        this.timestamp = OffsetDateTime.parse(timestamp);
    } catch (Exception e) {
        logger.warn("Could not parse timestamp: {}", timestamp);
    }

}

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

@Test
public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() {

    HeartRate expectedHeartRate = new HeartRate.Builder(65)
            .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-24T15:03:00-06:00"))
            .setUserNotes("Satch on satch ").build();

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

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

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

@Test
public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() {

    HeartRate expectedHeartRate = new HeartRate.Builder(75)
            .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T14:07:45-06:00"))
            .setUserNotes("BP on the up and up.").build();

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