Example usage for java.time ZoneId ofOffset

List of usage examples for java.time ZoneId ofOffset

Introduction

In this page you can find the example usage for java.time ZoneId ofOffset.

Prototype

public static ZoneId ofOffset(String prefix, ZoneOffset offset) 

Source Link

Document

Obtains an instance of ZoneId wrapping an offset.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZoneId z = ZoneId.ofOffset("UTC", ZoneOffset.UTC);

    System.out.println(z);
}

From source file:Main.java

public static void main(String[] args) {
    ZoneId offsetOfSixHours = ZoneId.ofOffset("UTC", ZoneOffset.ofHours(-6));
    System.out.println(ZonedDateTime.now().withZoneSameInstant(offsetOfSixHours));

}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime nowInAthens = ZonedDateTime.now(ZoneId.of("Europe/Athens"));

    System.out.println(nowInAthens.withZoneSameInstant(ZoneId.ofOffset("UTC", ZoneOffset.ofHours(3))));
}

From source file:com.intuit.wasabi.api.pagination.filters.FilterUtil.java

/**
 * Formats a date as it is shown in the UI to allow for matching searches on date fields.
 * Needs the requesting user's timezone offset to UTC for correct matches.
 *
 * @param date           the date/*from ww w.  j a va  2  s  . com*/
 * @param timeZoneOffset the timezone offset to UTC
 * @return a timezone offset adjusted string of the UI pattern {@code MMM d, YYYY HH:mm:ss a}.
 */
/*test*/
static String formatDateTimeAsUI(OffsetDateTime date, String timeZoneOffset) {
    try {
        return date.format(DateTimeFormatter.ofPattern("MMM d, YYYY HH:mm:ss a")
                .withZone(ZoneId.ofOffset("UTC", ZoneOffset.of(timeZoneOffset))));
    } catch (DateTimeException dateTimeException) {
        throw new PaginationException(ErrorCode.FILTER_KEY_UNPROCESSABLE,
                "Wrong format: Can not parse timezone '" + timeZoneOffset + "' or date " + date.toString()
                        + " properly.",
                dateTimeException);
    }
}

From source file:msi.gama.util.GamaDate.java

public GamaDate(final IScope scope, final Temporal d) {
    final ZoneId zone;
    if (d instanceof ChronoZonedDateTime) {
        zone = ZonedDateTime.from(d).getZone();
    } else if (d.isSupported(ChronoField.OFFSET_SECONDS)) {
        zone = ZoneId.ofOffset("", ZoneOffset.ofTotalSeconds(d.get(ChronoField.OFFSET_SECONDS)));
    } else {/*from w  ww. ja  v a2 s .c  o m*/
        zone = GamaDateType.DEFAULT_ZONE;
    }
    if (!d.isSupported(MINUTE_OF_HOUR)) {
        internal = ZonedDateTime.of(LocalDate.from(d), LocalTime.of(0, 0), zone);
    } else if (!d.isSupported(DAY_OF_MONTH)) {
        internal = ZonedDateTime.of(LocalDate.from(
                scope == null ? Dates.DATES_STARTING_DATE.getValue() : scope.getSimulation().getStartingDate()),
                LocalTime.from(d), zone);
    } else {
        internal = d;
    }
}

From source file:org.openmhealth.shim.jawbone.mapper.JawboneDataPointMapper.java

/**
 * Translates a time zone descriptor from one of various representations (Olson, seconds offset, GMT offset) into a
 * {@link ZoneId}./*from w  ww . j  a  v a2s  .c o  m*/
 *
 * @param timeZoneValueNode the value associated with a timezone property
 */
static ZoneId parseZone(JsonNode timeZoneValueNode) {

    // default to UTC if timezone is not present
    if (timeZoneValueNode.isNull()) {
        return ZoneOffset.UTC;
    }

    // "-25200"
    if (timeZoneValueNode.asInt() != 0) {
        ZoneOffset zoneOffset = ZoneOffset.ofTotalSeconds(timeZoneValueNode.asInt());

        // TODO confirm if this is even necessary, since ZoneOffset is a ZoneId
        return ZoneId.ofOffset("GMT", zoneOffset);
    }

    // e.g., "GMT-0700" or "America/Los_Angeles"
    if (timeZoneValueNode.isTextual()) {
        return ZoneId.of(timeZoneValueNode.textValue());
    }

    throw new IllegalArgumentException(format("The time zone node '%s' can't be parsed.", timeZoneValueNode));
}

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.// ww w . jav  a2  s .  c  om
 */
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));
}