Example usage for java.time OffsetDateTime getHour

List of usage examples for java.time OffsetDateTime getHour

Introduction

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

Prototype

public int getHour() 

Source Link

Document

Gets the hour-of-day field.

Usage

From source file:Main.java

public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();

    System.out.println(o.getHour());
}

From source file:io.sqp.core.types.SqpTimestampTest.java

@Test
public void CanDecodeFromJson() throws Exception {
    String content = "[[2015, 6, 28], [[13, 52, 5, 123456],7260]]";
    ObjectMapper mapper = JacksonObjectMapperFactory.objectMapper(DataFormat.Text);

    Object timeObj = mapper.readValue(content, Object.class);
    SqpTimestamp sqpTimestamp = SqpTimestamp.fromJsonFormatValue(timeObj);

    OffsetDateTime timestamp = sqpTimestamp.asOffsetDateTime();
    assertThat(timestamp.getHour(), is(13));
    assertThat(timestamp.getMinute(), is(52));
    assertThat(timestamp.getSecond(), is(5));
    assertThat(timestamp.getNano(), is(123456));
    assertThat(timestamp.getOffset().getTotalSeconds(), is(7260));

    assertThat(timestamp.getYear(), is(2015));
    assertThat(timestamp.getMonth(), is(Month.JUNE));
    assertThat(timestamp.getDayOfMonth(), is(28));
}

From source file:org.openmhealth.data.generator.service.TimestampedValueGroupGenerationServiceImpl.java

@Override
public Iterable<TimestampedValueGroup> generateValueGroups(MeasureGenerationRequest request) {

    ExponentialDistribution interPointDurationDistribution = new ExponentialDistribution(
            request.getMeanInterPointDuration().getSeconds());

    long totalDurationInS = Duration.between(request.getStartDateTime(), request.getEndDateTime()).getSeconds();

    OffsetDateTime effectiveDateTime = request.getStartDateTime();
    List<TimestampedValueGroup> timestampedValueGroups = new ArrayList<>();

    do {//from  w w w .j  av  a  2 s . co m
        effectiveDateTime = effectiveDateTime.plus((long) interPointDurationDistribution.sample(), SECONDS);

        if (!effectiveDateTime.isBefore(request.getEndDateTime())) {
            break;
        }

        if (request.isSuppressNightTimeMeasures() != null && request.isSuppressNightTimeMeasures()
                && (effectiveDateTime.getHour() >= NIGHT_TIME_START_HOUR
                        || effectiveDateTime.getHour() < NIGHT_TIME_END_HOUR)) {
            continue;
        }

        TimestampedValueGroup valueGroup = new TimestampedValueGroup();
        valueGroup.setTimestamp(effectiveDateTime);

        double trendProgressFraction = (double) Duration.between(request.getStartDateTime(), effectiveDateTime)
                .getSeconds() / totalDurationInS;

        for (Map.Entry<String, BoundedRandomVariableTrend> trendEntry : request.getTrends().entrySet()) {

            String key = trendEntry.getKey();
            BoundedRandomVariableTrend trend = trendEntry.getValue();

            double value = trend.nextValue(trendProgressFraction);
            valueGroup.setValue(key, value);
        }

        timestampedValueGroups.add(valueGroup);
    } while (true);

    return timestampedValueGroups;
}