Java Code Examples for java.time.OffsetDateTime#getHour()

The following examples show how to use java.time.OffsetDateTime#getHour() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PNGMetadata.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
void initImageCreationTime(OffsetDateTime offsetDateTime) {
    // Check for incoming arguments
    if (offsetDateTime != null) {
        // set values that make up Standard/Document/ImageCreationTime
        creation_time_present = true;
        creation_time_year    = offsetDateTime.getYear();
        creation_time_month   = offsetDateTime.getMonthValue();
        creation_time_day     = offsetDateTime.getDayOfMonth();
        creation_time_hour    = offsetDateTime.getHour();
        creation_time_minute  = offsetDateTime.getMinute();
        creation_time_second  = offsetDateTime.getSecond();
        creation_time_offset  = offsetDateTime.getOffset();
    }
}
 
Example 2
Source File: ASN1Type.java    From xipki with Apache License 2.0 5 votes vote down vote up
public static int writeGeneralizedTime(Date time, byte[] out, int offset) {
  OffsetDateTime offsetTime = time.toInstant().atOffset(ZoneOffset.UTC);
  int idx = offset;
  out[idx++] = 0x18;
  out[idx++] = 15;
  // yyyyMMddhhmmssZ
  // year
  int year = offsetTime.getYear();
  out[idx++] = (byte) (0x30 + year / 1000);
  out[idx++] = (byte) (0x30 + year / 100 % 10);
  out[idx++] = (byte) (0x30 + year / 10 % 10);
  out[idx++] = (byte) (0x30 + year % 10);
  // month
  int month = offsetTime.getMonthValue();
  out[idx++] = (byte) (0x30 + month / 10);
  out[idx++] = (byte) (0x30 + month % 10);
  // day
  int day = offsetTime.getDayOfMonth();
  out[idx++] = (byte) (0x30 + day / 10);
  out[idx++] = (byte) (0x30 + day % 10);
  // hour
  int hour = offsetTime.getHour();
  out[idx++] = (byte) (0x30 + hour / 10);
  out[idx++] = (byte) (0x30 + hour % 10);
  // minute
  int minute = offsetTime.getMinute();
  out[idx++] = (byte) (0x30 + minute / 10);
  out[idx++] = (byte) (0x30 + minute % 10);
  // second
  int second = offsetTime.getSecond();
  out[idx++] = (byte) (0x30 + second / 10);
  out[idx++] = (byte) (0x30 + second % 10);
  out[idx++] = 'Z';
  return idx - offset;
}
 
Example 3
Source File: Time.java    From java-timeseries with MIT License 4 votes vote down vote up
private boolean timeEmpty(OffsetDateTime dateTime) {
  return dateTime.getHour() == 0
      && dateTime.getMinute() == 0
      && dateTime.getSecond() == 0
      && dateTime.getNano() == 0;
}
 
Example 4
Source File: TimestampedValueGroupGenerationServiceImpl.java    From sample-data-generator with Apache License 2.0 4 votes vote down vote up
@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 {
        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;
}