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.IHealthBodyMassIndexDataPointMapperUnitTests.java

@Test
public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() {

    BodyMassIndex expectedBodyMassIndex = new BodyMassIndex.Builder(
            new TypedUnitValue<>(KILOGRAMS_PER_SQUARE_METER, 22.56052398681641))
                    .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T14:07:57-06:00"))
                    .setUserNotes("Weight so good, look at me now").build();

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

    testDataPointHeader(dataPoints.get(1).getHeader(), SCHEMA_ID, SELF_REPORTED,
            "b702a3a5e998f2fca268df6daaa69871", OffsetDateTime.parse("2015-09-17T20:08:00Z"));
}

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

public void testDailyCaloriesBurnedDataPoint(DataPoint<CaloriesBurned> caloriesBurnedDataPoint,
        long expectedCaloriesBurnedValue, String expectedDateString, String expectedEndDateString) {

    CaloriesBurned expectedCaloriesBurned = new CaloriesBurned.Builder(
            new KcalUnitValue(KILOCALORIE, expectedCaloriesBurnedValue))
                    .setEffectiveTimeFrame(
                            ofStartDateTimeAndEndDateTime(OffsetDateTime.parse(expectedDateString),
                                    OffsetDateTime.parse(expectedEndDateString)))
                    .build();//from w  w w .  j a  va2 s .  c om

    assertThat(caloriesBurnedDataPoint.getBody(), equalTo(expectedCaloriesBurned));
    assertThat(caloriesBurnedDataPoint.getHeader().getAcquisitionProvenance().getModality(), equalTo(SENSED));
    assertThat(caloriesBurnedDataPoint.getHeader().getAcquisitionProvenance().getSourceName(),
            equalTo(RESOURCE_API_SOURCE_NAME));
    assertThat(caloriesBurnedDataPoint.getHeader().getBodySchemaId(), equalTo(CaloriesBurned.SCHEMA_ID));

}

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

@Test
public void asDataPointsShouldReturnCorrectDataPoints() {

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

    BodyHeight expectedBodyHeight = new BodyHeight.Builder(new LengthUnitValue(METER, 1.93))
            .setEffectiveTimeFrame(OffsetDateTime.parse("2015-02-23T19:24:49Z")).build();

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

    DataPointHeader actualDataPointHeader = actualDataPoints.get(0).getHeader();
    assertThat(actualDataPointHeader.getBodySchemaId(), equalTo(SCHEMA_ID));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getModality(), equalTo(SELF_REPORTED));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getSourceName(),
            equalTo(RESOURCE_API_SOURCE_NAME));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getAdditionalProperties().get("external_id"),
            equalTo(320419189L));//from  w  w  w.  j  av a2  s. c  om
}

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

public void testIntradayCaloriesBurnedDataPoint(DataPoint<CaloriesBurned> caloriesBurnedDataPoint,
        long expectedCaloriesBurnedValue, String expectedDateString, Long expectedDuration) {

    CaloriesBurned expectedCaloriesBurned = new CaloriesBurned.Builder(
            new KcalUnitValue(KILOCALORIE, expectedCaloriesBurnedValue))
                    .setEffectiveTimeFrame(ofStartDateTimeAndDuration(OffsetDateTime.parse(expectedDateString),
                            new DurationUnitValue(SECOND, expectedDuration)))
                    .build();//  ww  w .  j  a  v a2s . c om

    assertThat(caloriesBurnedDataPoint.getBody(), equalTo(expectedCaloriesBurned));
    assertThat(caloriesBurnedDataPoint.getHeader().getAcquisitionProvenance().getModality(), equalTo(SENSED));
    assertThat(caloriesBurnedDataPoint.getHeader().getAcquisitionProvenance().getSourceName(),
            equalTo(RESOURCE_API_SOURCE_NAME));
    assertThat(caloriesBurnedDataPoint.getHeader().getBodySchemaId(), equalTo(SCHEMA_ID));
}

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

@Test
public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() {

    PhysicalActivity.Builder expectedPhysicalActivityBuilder = new PhysicalActivity.Builder("Running")
            .setEffectiveTimeFrame(TimeInterval.ofStartDateTimeAndEndDateTime(
                    OffsetDateTime.parse("2015-09-22T20:43:03+01:00"),
                    OffsetDateTime.parse("2015-09-22T21:13:03+01:00")))
            .setCaloriesBurned(new KcalUnitValue(KILOCALORIE, 202.5));

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

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

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

public TickJson(OffsetDateTime date, double open, double high, double low, double close, double volume,
        String symbol, String market, String timestamp) {
    super(DateTime.parse(date.toString(), ISODateTimeFormat.dateTimeParser()), open, high, low, close, volume);
    this.timestamp = date;
    this.symbol = symbol;
    this.market = market;
    try {/*from   ww  w.  j ava2 s . c om*/
        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);
    }
}