Example usage for java.time ZoneOffset ofHours

List of usage examples for java.time ZoneOffset ofHours

Introduction

In this page you can find the example usage for java.time ZoneOffset ofHours.

Prototype

public static ZoneOffset ofHours(int hours) 

Source Link

Document

Obtains an instance of ZoneOffset using an offset in hours.

Usage

From source file:net.bis5.slack.command.gcal.SlashCommandApi.java

private EventDateTime toDateTime(LocalDate date, LocalTime time) {
    if (time != null) {
        DateTime dateTime = new DateTime(
                Date.from(LocalDateTime.of(date, time).toInstant(ZoneOffset.ofHours(+9))));
        return new EventDateTime().setDateTime(dateTime);
    } else {/*from   w w w  .j a v  a  2s  .  com*/
        DateTime dateTime = new DateTime(true,
                Date.from(date.atStartOfDay().toInstant(ZoneOffset.UTC)).getTime(), 9);
        return new EventDateTime().setDate(dateTime);
    }
}

From source file:com.esri.geoportal.harvester.api.base.DataReferenceSerializer.java

private String formatIsoDate(Date date) {
    Instant instant = date.toInstant();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from w ww.jav a  2  s.  co  m*/
    ZoneOffset zoneOffset = ZoneOffset.ofHours(cal.getTimeZone().getRawOffset() / (1000 * 60 * 60));
    OffsetDateTime ofInstant = OffsetDateTime.ofInstant(instant, zoneOffset);
    return FORMATTER.format(ofInstant);
}

From source file:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java

public static ZoneOffset getZoneOffset(final BigDecimal hourDifference) {
    int auxValue = 0;
    if (hourDifference != null) {
        auxValue = hourDifference.intValue();
    }//from   w ww.j  a  v  a 2s  .co  m
    return ZoneOffset.ofHours(auxValue);
}

From source file:org.openmhealth.shim.runkeeper.mapper.RunkeeperDataPointMapper.java

/**
 * Sets the effective time frame property for a measure builder.
 *
 * @param itemNode an individual datapoint from the list of datapoints returned in the API response
 * @param builder the measure builder to have the effective date property set
 *//*from  w  w w.  jav  a 2  s.c om*/
protected void setEffectiveTimeFrameIfPresent(JsonNode itemNode, Measure.Builder builder) {

    Optional<LocalDateTime> localStartDateTime = asOptionalLocalDateTime(itemNode, "start_time",
            DATE_TIME_FORMATTER);

    // RunKeeper doesn't support fractional time zones
    Optional<Integer> utcOffset = asOptionalInteger(itemNode, "utc_offset");
    Optional<Double> durationInS = asOptionalDouble(itemNode, "duration");

    if (localStartDateTime.isPresent() && utcOffset.isPresent() && durationInS.isPresent()) {

        OffsetDateTime startDateTime = localStartDateTime.get().atOffset(ZoneOffset.ofHours(utcOffset.get()));
        DurationUnitValue duration = new DurationUnitValue(SECOND, durationInS.get());

        builder.setEffectiveTimeFrame(ofStartDateTimeAndDuration(startDateTime, duration));
    }
}

From source file:com.tascape.reactor.report.MySqlBaseBean.java

public static long getMillis(String time) {
    if (time == null || time.trim().isEmpty()) {
        return System.currentTimeMillis();
    } else {//from w w w.  j a  v  a2s  . co m
        LocalDateTime ldt = LocalDateTime.parse(time, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        LOG.trace("ldt {}", ldt);
        ZoneId zone = ZoneId.of("America/Los_Angeles");
        ldt.atZone(zone);
        LOG.trace("ldt {}", ldt);
        return ldt.toInstant(ZoneOffset.ofHours(-8)).toEpochMilli();
    }
}

From source file:org.primeframework.mvc.parameter.convert.converters.ZonedDateTimeConverterTest.java

@Test
public void fromStrings() {
    GlobalConverter converter = new ZonedDateTimeConverter(new MockConfiguration());
    ZonedDateTime value = (ZonedDateTime) converter.convertFromStrings(ZonedDateTime.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(value);/*from  www. ja va 2s .  c  o m*/

    value = (ZonedDateTime) converter.convertFromStrings(Locale.class,
            MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy hh:mm:ss a Z"), "testExpr",
            ArrayUtils.toArray("07-08-2008 10:13:34 AM -0800"));
    assertEquals(value.getMonthValue(), 7);
    assertEquals(value.getDayOfMonth(), 8);
    assertEquals(value.getYear(), 2008);
    assertEquals(value.getHour(), 10);
    assertEquals(value.getMinute(), 13);
    assertEquals(value.getSecond(), 34);
    assertEquals(value.getZone(), ZoneOffset.ofHours(-8));

    try {
        converter.convertFromStrings(Locale.class, MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy"), "testExpr",
                ArrayUtils.toArray("07/08/2008"));
        fail("Should have failed");
    } catch (ConversionException e) {
        // Expected
    }
}