Example usage for java.time OffsetDateTime getOffset

List of usage examples for java.time OffsetDateTime getOffset

Introduction

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

Prototype

public ZoneOffset getOffset() 

Source Link

Document

Gets the zone offset, such as '+01:00'.

Usage

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.schema.serializer.Rfc3339OffsetDateTimeSerializer.java

@Override
public void serialize(OffsetDateTime instant, JsonGenerator generator, SerializerProvider provider)
        throws IOException {

    StringBuilder builder = new StringBuilder();

    builder.append(instant.toLocalDateTime().toString());

    if (instant.getSecond() == 0 && instant.getNano() == 0) {
        builder.append(":00");
    }//from  ww w  .  j  a va 2s. co m

    builder.append(instant.getOffset().toString());

    generator.writeString(builder.toString());
}

From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java

/**
 * Checks if scheduler's time data satisfies existing time parameters.
 *
 * @param dto           scheduler job data.
 * @param dateTime      existing time data.
 * @param desiredStatus target exploratory status which has influence for time/date checking ('running' status
 *                      requires for checking start time, 'stopped' - for end time, 'terminated' - for
 *                      'terminatedDateTime').
 * @return true/false.//from  w  w  w  .  java 2 s  . c o m
 */
private boolean isSchedulerJobDtoSatisfyCondition(SchedulerJobDTO dto, OffsetDateTime dateTime,
        UserInstanceStatus desiredStatus) {
    ZoneOffset zOffset = dto.getTimeZoneOffset();
    OffsetDateTime roundedDateTime = OffsetDateTime.of(dateTime.toLocalDate(),
            LocalTime.of(dateTime.toLocalTime().getHour(), dateTime.toLocalTime().getMinute()),
            dateTime.getOffset());

    LocalDateTime convertedDateTime = ZonedDateTime
            .ofInstant(roundedDateTime.toInstant(), ZoneId.ofOffset(TIMEZONE_PREFIX, zOffset))
            .toLocalDateTime();

    return desiredStatus == TERMINATED
            ? Objects.nonNull(dto.getTerminateDateTime())
                    && convertedDateTime.toLocalDate().equals(dto.getTerminateDateTime().toLocalDate())
                    && convertedDateTime.toLocalTime().equals(getDesiredTime(dto, desiredStatus))
            : !convertedDateTime.toLocalDate().isBefore(dto.getBeginDate())
                    && isFinishDateMatchesCondition(dto, convertedDateTime)
                    && getDaysRepeat(dto, desiredStatus)
                            .contains(convertedDateTime.toLocalDate().getDayOfWeek())
                    && convertedDateTime.toLocalTime().equals(getDesiredTime(dto, desiredStatus));
}

From source file:fi.hsl.parkandride.itest.PredictionITest.java

@Test
public void prediction_JSON_structure() {
    Utilization u = makeDummyPredictions();

    JsonPath json = when().get(UrlSchema.FACILITY_PREDICTION, facilityId).jsonPath();
    long facilityId = json.getLong("[0].facilityId");
    String capacityType = json.getString("[0].capacityType");
    String usage = json.getString("[0].usage");
    OffsetDateTime timestamp = OffsetDateTime.parse(json.getString("[0].timestamp"),
            DateTimeFormatter.ISO_OFFSET_DATE_TIME);
    int spacesAvailable = json.getInt("[0].spacesAvailable");

    assertThat(facilityId).as("facilityId").isEqualTo(u.facilityId);
    assertThat(capacityType).as("capacityType").isEqualTo(u.capacityType.name());
    assertThat(usage).as("usage").isEqualTo(u.usage.name());
    assertThat(timestamp.getOffset()).as("time should be in local timezone")
            .isEqualTo(ZoneOffset.systemDefault().getRules().getOffset(timestamp.toInstant()));
    assertThat(spacesAvailable).as("spacesAvailable").isEqualTo(u.spacesAvailable);
}