Java Code Examples for java.time.ZoneId#ofOffset()

The following examples show how to use java.time.ZoneId#ofOffset() . 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: GamaDate.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
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 {
		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;
	}
}
 
Example 2
Source File: JawboneDataPointMapper.java    From shimmer with Apache License 2.0 6 votes vote down vote up
/**
 * Translates a time zone descriptor from one of various representations (Olson, seconds offset, GMT offset) into a
 * {@link ZoneId}.
 *
 * @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));
}
 
Example 3
Source File: TCKZoneId.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prefixValid")
public void test_prefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    assertEquals(zoneId.getId(), prefix + zoff.getId(), "in correct id for : " + prefix + ", zoff: " + zoff);

}
 
Example 4
Source File: TCKZoneId.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prefixValid")
public void test_prefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    assertEquals(zoneId.getId(), prefix + zoff.getId(), "in correct id for : " + prefix + ", zoff: " + zoff);

}
 
Example 5
Source File: TCKZoneId.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prefixValid")
public void test_prefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    assertEquals(zoneId.getId(), prefix + zoff.getId(), "in correct id for : " + prefix + ", zoff: " + zoff);

}
 
Example 6
Source File: TestSolution2LocalAndZonedDateTimes.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@Tag("PASSING")
@Order(10)
@DisplayName("verify conversion of UTC date time to Indian Standard Time")
public void verifyConversionOfUTCDateTimeToIndianStandardTime() {

    ZonedDateTime allDateTimeOhFives =
            ZonedDateTime.of(5,
                    5,
                    5,
                    5,
                    5,
                    5,
                    555,
                    ZoneId.ofOffset("", ZoneOffset.UTC));

    ZoneId gmtPlusOneZoneId = ZoneId.ofOffset("", ZoneOffset.of("+0530"));

    // DONE: Replace the ZonedDateTime.now() below to display the below UTC time in GMT +0530
    //  The ZonedDateTime created in GMT. Fix the calls so a ZonedDateTime
    //  can be created with the offset of GMT +0530. Use an ofInstant from a toInstant.
    //  Check: java.time.ZonedDateTime.ofInstant(java.time.Instant, java.time.ZoneId)
    //  Check: java.time.ZonedDateTime.toInstant()
    ZonedDateTime gmtPlusOneHourTimeForAllFives =
            ZonedDateTime.ofInstant(
                    allDateTimeOhFives.toInstant(),
                    gmtPlusOneZoneId);

    assertEquals(10,
            gmtPlusOneHourTimeForAllFives.getHour(),
            "The hour should be at 10 AM when Zone Offset is GMT +0530");

    assertEquals(35,
            gmtPlusOneHourTimeForAllFives.getMinute(),
            "The minute should be 35 when Zone Offset is GMT +0530");
}
 
Example 7
Source File: PromoCodeDiscountApiController.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
private ZoneId zoneIdFromEventId(Integer eventId, Integer utcOffset) {
    if(eventId != null) {
        return eventRepository.getZoneIdByEventId(eventId);
    } else {
        return ZoneId.ofOffset("UTC", ZoneOffset.ofTotalSeconds(utcOffset != null ? utcOffset : 0));
    }
}
 
Example 8
Source File: TestKata2LocalAndZonedDateTimes.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@Tag("TODO")
@Order(10)
@DisplayName("verify conversion of UTC date time to Indian Standard Time")
public void verifyConversionOfUTCDateTimeToIndianStandardTime() {

    ZonedDateTime allDateTimeOhFives =
            ZonedDateTime.of(5,
                    5,
                    5,
                    5,
                    5,
                    5,
                    555,
                    ZoneId.ofOffset("", ZoneOffset.UTC));

    ZoneId gmtPlusOneZoneId = ZoneId.ofOffset("", ZoneOffset.of("+0530"));

    // TODO: Replace the ZonedDateTime.now() below to display the below UTC time in GMT +0530
    //  The ZonedDateTime created in GMT. Fix the calls so a ZonedDateTime
    //  can be created with the offset of GMT +0530. Use an ofInstant from a toInstant.
    //  Check: java.time.ZonedDateTime.ofInstant(java.time.Instant, java.time.ZoneId)
    //  Check: java.time.ZonedDateTime.toInstant()
    ZonedDateTime gmtPlusOneHourTimeForAllFives =
            ZonedDateTime.now();



    assertEquals(10,
            gmtPlusOneHourTimeForAllFives.getHour(),
            "The hour should be at 10 AM when Zone Offset is GMT +0530");

    assertEquals(35,
            gmtPlusOneHourTimeForAllFives.getMinute(),
            "The minute should be 35 when Zone Offset is GMT +0530");
}
 
Example 9
Source File: TCKZoneId.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prefixValid")
public void test_prefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    assertEquals(zoneId.getId(), prefix + zoff.getId(), "in correct id for : " + prefix + ", zoff: " + zoff);

}
 
Example 10
Source File: TCKZoneId.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prefixValid")
public void test_prefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    assertEquals(zoneId.getId(), prefix + zoff.getId(), "in correct id for : " + prefix + ", zoff: " + zoff);

}
 
Example 11
Source File: TCKZoneId.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="prefixInvalid", expectedExceptions=java.lang.IllegalArgumentException.class)
public void test_invalidPrefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    fail("should have thrown an exception for prefix: " + prefix);
}
 
Example 12
Source File: TCKZoneId.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_nullOffsetOfOffset() {
    ZoneId.ofOffset("GMT", null);
}
 
Example 13
Source File: TCKZoneId.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_nullPrefixOfOffset() {
    ZoneId.ofOffset(null, ZoneOffset.ofTotalSeconds(1));
}
 
Example 14
Source File: TCKZoneId.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_nullPrefixOfOffset() {
    ZoneId.ofOffset(null, ZoneOffset.ofTotalSeconds(1));
}
 
Example 15
Source File: TCKZoneId.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_nullOffsetOfOffset() {
    ZoneId.ofOffset("GMT", null);
}
 
Example 16
Source File: TCKZoneId.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_nullOffsetOfOffset() {
    ZoneId.ofOffset("GMT", null);
}
 
Example 17
Source File: TCKZoneId.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_nullPrefixOfOffset() {
    ZoneId.ofOffset(null, ZoneOffset.ofTotalSeconds(1));
}
 
Example 18
Source File: TCKZoneId.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="prefixInvalid", expectedExceptions=java.lang.IllegalArgumentException.class)
public void test_invalidPrefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    fail("should have thrown an exception for prefix: " + prefix);
}
 
Example 19
Source File: TCKZoneId.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="prefixInvalid", expectedExceptions=java.lang.IllegalArgumentException.class)
public void test_invalidPrefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    fail("should have thrown an exception for prefix: " + prefix);
}
 
Example 20
Source File: TCKZoneId.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="prefixInvalid", expectedExceptions=java.lang.IllegalArgumentException.class)
public void test_invalidPrefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    fail("should have thrown an exception for prefix: " + prefix);
}