Java Code Examples for java.time.ZoneOffset#ofHoursMinutesSeconds()

The following examples show how to use java.time.ZoneOffset#ofHoursMinutesSeconds() . 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: TCKZoneOffset.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_factory_int_hours_minutes_seconds() {
    for (int i = -17; i <= 17; i++) {
        for (int j = -59; j <= 59; j++) {
            for (int k = -59; k <= 59; k++) {
                if ((i < 0 && j <= 0 && k <= 0) || (i > 0 && j >= 0 && k >= 0) ||
                        (i == 0 && ((j < 0 && k <= 0) || (j > 0 && k >= 0) || j == 0))) {
                    ZoneOffset test = ZoneOffset.ofHoursMinutesSeconds(i, j, k);
                    doTestOffset(test, i, j, k);
                }
            }
        }
    }
    ZoneOffset test1 = ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0);
    doTestOffset(test1, -18, 0, 0);
    ZoneOffset test2 = ZoneOffset.ofHoursMinutesSeconds(18, 0, 0);
    doTestOffset(test2, 18, 0, 0);
}
 
Example 2
Source File: TCKZoneOffset.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 3
Source File: TCKDateTimeFormatterBuilder.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="offsetPatterns")
public void test_appendOffset_format(String pattern, int h, int m, int s, String expected) throws Exception {
    builder.appendOffset(pattern, "Z");
    DateTimeFormatter f = builder.toFormatter();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(h, m, s);
    assertEquals(f.format(offset), expected);
}
 
Example 4
Source File: TCKZoneOffset.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getId() {
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(1, 0, 0);
    assertEquals(offset.getId(), "+01:00");
    offset = ZoneOffset.ofHoursMinutesSeconds(1, 2, 3);
    assertEquals(offset.getId(), "+01:02:03");
    offset = ZoneOffset.UTC;
    assertEquals(offset.getId(), "Z");
}
 
Example 5
Source File: TCKDateTimeFormatterBuilder.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="offsetPatterns")
public void test_appendOffset_format(String pattern, int h, int m, int s, String expected) throws Exception {
    builder.appendOffset(pattern, "Z");
    DateTimeFormatter f = builder.toFormatter();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(h, m, s);
    assertEquals(f.format(offset), expected);
}
 
Example 6
Source File: TCKZoneRules.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_Paris_preTimeZones() {
    ZoneRules test = europeParis();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, 9, 21);
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
 
Example 7
Source File: TCKZoneOffset.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_compareTo() {
    ZoneOffset offset1 = ZoneOffset.ofHoursMinutesSeconds(1, 2, 3);
    ZoneOffset offset2 = ZoneOffset.ofHoursMinutesSeconds(2, 3, 4);
    assertTrue(offset1.compareTo(offset2) > 0);
    assertTrue(offset2.compareTo(offset1) < 0);
    assertTrue(offset1.compareTo(offset1) == 0);
    assertTrue(offset2.compareTo(offset2) == 0);
}
 
Example 8
Source File: TCKZoneOffset.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_hours_minutes_seconds_minutesTooLarge() {
    ZoneOffset.ofHoursMinutesSeconds(0, 60, 0);
}
 
Example 9
Source File: TestZoneOffsetParser.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@DataProvider(name="offsets")
Object[][] provider_offsets() {
    return new Object[][] {
        {"+HH", "+00", ZoneOffset.UTC},
        {"+HH", "-00", ZoneOffset.UTC},
        {"+HH", "+01", ZoneOffset.ofHours(1)},
        {"+HH", "-01", ZoneOffset.ofHours(-1)},

        {"+HHMM", "+0000", ZoneOffset.UTC},
        {"+HHMM", "-0000", ZoneOffset.UTC},
        {"+HHMM", "+0102", ZoneOffset.ofHoursMinutes(1, 2)},
        {"+HHMM", "-0102", ZoneOffset.ofHoursMinutes(-1, -2)},

        {"+HH:MM", "+00:00", ZoneOffset.UTC},
        {"+HH:MM", "-00:00", ZoneOffset.UTC},
        {"+HH:MM", "+01:02", ZoneOffset.ofHoursMinutes(1, 2)},
        {"+HH:MM", "-01:02", ZoneOffset.ofHoursMinutes(-1, -2)},

        {"+HHMMss", "+0000", ZoneOffset.UTC},
        {"+HHMMss", "-0000", ZoneOffset.UTC},
        {"+HHMMss", "+0100", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HHMMss", "+0159", ZoneOffset.ofHoursMinutesSeconds(1, 59, 0)},
        {"+HHMMss", "+0200", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HHMMss", "+1800", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HHMMss", "+010215", ZoneOffset.ofHoursMinutesSeconds(1, 2, 15)},
        {"+HHMMss", "-0100", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HHMMss", "-0200", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HHMMss", "-1800", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HHMMss", "+000000", ZoneOffset.UTC},
        {"+HHMMss", "-000000", ZoneOffset.UTC},
        {"+HHMMss", "+010000", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HHMMss", "+010203", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HHMMss", "+015959", ZoneOffset.ofHoursMinutesSeconds(1, 59, 59)},
        {"+HHMMss", "+020000", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HHMMss", "+180000", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HHMMss", "-010000", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HHMMss", "-020000", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HHMMss", "-180000", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HH:MM:ss", "+00:00", ZoneOffset.UTC},
        {"+HH:MM:ss", "-00:00", ZoneOffset.UTC},
        {"+HH:MM:ss", "+01:00", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HH:MM:ss", "+01:02", ZoneOffset.ofHoursMinutesSeconds(1, 2, 0)},
        {"+HH:MM:ss", "+01:59", ZoneOffset.ofHoursMinutesSeconds(1, 59, 0)},
        {"+HH:MM:ss", "+02:00", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HH:MM:ss", "+18:00", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HH:MM:ss", "+01:02:15", ZoneOffset.ofHoursMinutesSeconds(1, 2, 15)},
        {"+HH:MM:ss", "-01:00", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HH:MM:ss", "-02:00", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HH:MM:ss", "-18:00", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HH:MM:ss", "+00:00:00", ZoneOffset.UTC},
        {"+HH:MM:ss", "-00:00:00", ZoneOffset.UTC},
        {"+HH:MM:ss", "+01:00:00", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HH:MM:ss", "+01:02:03", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HH:MM:ss", "+01:59:59", ZoneOffset.ofHoursMinutesSeconds(1, 59, 59)},
        {"+HH:MM:ss", "+02:00:00", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HH:MM:ss", "+18:00:00", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HH:MM:ss", "-01:00:00", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HH:MM:ss", "-02:00:00", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HH:MM:ss", "-18:00:00", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HHMMSS", "+000000", ZoneOffset.UTC},
        {"+HHMMSS", "-000000", ZoneOffset.UTC},
        {"+HHMMSS", "+010203", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HHMMSS", "-010203", ZoneOffset.ofHoursMinutesSeconds(-1, -2, -3)},

        {"+HH:MM:SS", "+00:00:00", ZoneOffset.UTC},
        {"+HH:MM:SS", "-00:00:00", ZoneOffset.UTC},
        {"+HH:MM:SS", "+01:02:03", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HH:MM:SS", "-01:02:03", ZoneOffset.ofHoursMinutesSeconds(-1, -2, -3)},
    };
}
 
Example 10
Source File: TCKZoneOffset.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_hours_minutes_seconds_minusHoursPlusMinutes() {
    ZoneOffset.ofHoursMinutesSeconds(-1, 1, 0);
}
 
Example 11
Source File: TCKZoneOffset.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_hours_minutes_seconds_minutesMinValue() {
    ZoneOffset.ofHoursMinutesSeconds(0, Integer.MIN_VALUE, -1);
}
 
Example 12
Source File: TCKZoneOffset.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_hours_minutes_seconds_hoursTooBig() {
    ZoneOffset.ofHoursMinutesSeconds(19, 0, 0);
}
 
Example 13
Source File: TCKZoneOffset.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_hours_minutes_seconds_minusHoursPlusSeconds() {
    ZoneOffset.ofHoursMinutesSeconds(-1, 0, 1);
}
 
Example 14
Source File: TestZoneOffsetPrinter.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@DataProvider(name="offsets")
Object[][] provider_offsets() {
    return new Object[][] {
        {"+HH", "NO-OFFSET", ZoneOffset.UTC},
        {"+HH", "+01", ZoneOffset.ofHours(1)},
        {"+HH", "-01", ZoneOffset.ofHours(-1)},

        {"+HHMM", "NO-OFFSET", ZoneOffset.UTC},
        {"+HHMM", "+0102", ZoneOffset.ofHoursMinutes(1, 2)},
        {"+HHMM", "-0102", ZoneOffset.ofHoursMinutes(-1, -2)},

        {"+HH:MM", "NO-OFFSET", ZoneOffset.UTC},
        {"+HH:MM", "+01:02", ZoneOffset.ofHoursMinutes(1, 2)},
        {"+HH:MM", "-01:02", ZoneOffset.ofHoursMinutes(-1, -2)},

        {"+HHMMss", "NO-OFFSET", ZoneOffset.UTC},
        {"+HHMMss", "+0100", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HHMMss", "+0102", ZoneOffset.ofHoursMinutesSeconds(1, 2, 0)},
        {"+HHMMss", "+0159", ZoneOffset.ofHoursMinutesSeconds(1, 59, 0)},
        {"+HHMMss", "+0200", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HHMMss", "+1800", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HHMMss", "+010215", ZoneOffset.ofHoursMinutesSeconds(1, 2, 15)},
        {"+HHMMss", "-0100", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HHMMss", "-0200", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HHMMss", "-1800", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HHMMss", "NO-OFFSET", ZoneOffset.UTC},
        {"+HHMMss", "+0100", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HHMMss", "+010203", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HHMMss", "+015959", ZoneOffset.ofHoursMinutesSeconds(1, 59, 59)},
        {"+HHMMss", "+0200", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HHMMss", "+1800", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HHMMss", "-0100", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HHMMss", "-0200", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HHMMss", "-1800", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HH:MM:ss", "NO-OFFSET", ZoneOffset.UTC},
        {"+HH:MM:ss", "+01:00", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HH:MM:ss", "+01:02", ZoneOffset.ofHoursMinutesSeconds(1, 2, 0)},
        {"+HH:MM:ss", "+01:59", ZoneOffset.ofHoursMinutesSeconds(1, 59, 0)},
        {"+HH:MM:ss", "+02:00", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HH:MM:ss", "+18:00", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HH:MM:ss", "+01:02:15", ZoneOffset.ofHoursMinutesSeconds(1, 2, 15)},
        {"+HH:MM:ss", "-01:00", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HH:MM:ss", "-02:00", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HH:MM:ss", "-18:00", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HH:MM:ss", "NO-OFFSET", ZoneOffset.UTC},
        {"+HH:MM:ss", "+01:00", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HH:MM:ss", "+01:02:03", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HH:MM:ss", "+01:59:59", ZoneOffset.ofHoursMinutesSeconds(1, 59, 59)},
        {"+HH:MM:ss", "+02:00", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HH:MM:ss", "+18:00", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HH:MM:ss", "-01:00", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HH:MM:ss", "-02:00", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HH:MM:ss", "-18:00", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HHMMSS", "NO-OFFSET", ZoneOffset.UTC},
        {"+HHMMSS", "+010203", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HHMMSS", "-010203", ZoneOffset.ofHoursMinutesSeconds(-1, -2, -3)},
        {"+HHMMSS", "+010200", ZoneOffset.ofHoursMinutesSeconds(1, 2, 0)},
        {"+HHMMSS", "-010200", ZoneOffset.ofHoursMinutesSeconds(-1, -2, 0)},

        {"+HH:MM:SS", "NO-OFFSET", ZoneOffset.UTC},
        {"+HH:MM:SS", "+01:02:03", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HH:MM:SS", "-01:02:03", ZoneOffset.ofHoursMinutesSeconds(-1, -2, -3)},
        {"+HH:MM:SS", "+01:02:00", ZoneOffset.ofHoursMinutesSeconds(1, 2, 0)},
        {"+HH:MM:SS", "-01:02:00", ZoneOffset.ofHoursMinutesSeconds(-1, -2, 0)},
    };
}
 
Example 15
Source File: TCKZoneOffset.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_hours_minutes_seconds_minutesTooSmall() {
    ZoneOffset.ofHoursMinutesSeconds(0, -60, 0);
}
 
Example 16
Source File: TCKZoneOffset.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_hours_minutes_seconds_minusHoursPlusSeconds() {
    ZoneOffset.ofHoursMinutesSeconds(-1, 0, 1);
}
 
Example 17
Source File: TCKZoneOffset.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_hours_minutes_seconds_secondsTooSmall() {
    ZoneOffset.ofHoursMinutesSeconds(0, 0, 60);
}
 
Example 18
Source File: TCKZoneOffset.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_hours_minutes_seconds_minutesAndSecondsMinValue() {
    ZoneOffset.ofHoursMinutesSeconds(0, Integer.MIN_VALUE, Integer.MIN_VALUE);
}
 
Example 19
Source File: TCKZoneOffset.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeException.class)
public void test_factory_int_hours_minutes_seconds_plusHoursMinusSeconds() {
    ZoneOffset.ofHoursMinutesSeconds(1, 0, -1);
}
 
Example 20
Source File: TCKZoneOffset.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected List<TemporalAccessor> samples() {
    TemporalAccessor[] array = {ZoneOffset.ofHours(1), ZoneOffset.ofHoursMinutesSeconds(-5, -6, -30) };
    return Arrays.asList(array);
}