Java Code Examples for java.time.OffsetTime#of()

The following examples show how to use java.time.OffsetTime#of() . 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: TCKLocalDateTime.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 23, 5, 0, 0), null},
            {LocalDateTime.of(2012, Month.MARCH, 4, 0, 0), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 0, 0), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), null},
            {LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, null},
            {LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, null},

            {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZoneOffset.UTC), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, OFFSET_PONE), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), ZonedDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZONE_PARIS), ZonedDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZONE_PARIS), null},

            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalTime.of(22, 3, 0), null, DateTimeException.class},
            {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetTime.of(22, 3, 0, 0, ZoneOffset.UTC), null, DateTimeException.class},
            {LocalDateTime.of(2012, 3, 4, 23, 5), null, null, NullPointerException.class},

    };
}
 
Example 2
Source File: TCKLocalTime.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {LocalTime.of(23, 5), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 0, 0), null},
            {LocalTime.of(23, 5, 20), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 0), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), LocalTime.of(23, 59, 59, 999999999), null},
            {LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null},
            {LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), LocalTime.of(12, 0, 0), null},
            {LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null},

            {LocalTime.of(23, 5), LocalDateTime.of(2210, 2, 2, 1, 1), LocalDateTime.of(2210, 2, 2, 23, 5), null},
            {LocalTime.of(23, 5), OffsetTime.of(1, 1, 0, 0, OFFSET_PTWO), OffsetTime.of(23, 5, 0, 0, OFFSET_PTWO), null},
            {LocalTime.of(23, 5), OffsetDateTime.of(2210, 2, 2, 1, 1, 0, 0, OFFSET_PTWO), OffsetDateTime.of(2210, 2, 2, 23, 5, 0, 0, OFFSET_PTWO), null},
            {LocalTime.of(23, 5), ZonedDateTime.of(2210, 2, 2, 1, 1, 0, 0, ZONE_PARIS), ZonedDateTime.of(2210, 2, 2, 23, 5, 0, 0, ZONE_PARIS), null},

            {LocalTime.of(23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {LocalTime.of(23, 5), null, null, NullPointerException.class},

    };
}
 
Example 3
Source File: TCKOffsetTime.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_isBeforeIsAfterIsEqual_instantComparison() {
    OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PTWO);
    OffsetTime b = OffsetTime.of(10, 30, 59, 0, OFFSET_PONE);  // a is same instant as b
    assertEquals(a.isBefore(b), false);
    assertEquals(a.isEqual(b), true);
    assertEquals(a.isAfter(b), false);

    assertEquals(b.isBefore(a), false);
    assertEquals(b.isEqual(a), true);
    assertEquals(b.isAfter(a), false);

    assertEquals(a.isBefore(a), false);
    assertEquals(b.isBefore(b), false);

    assertEquals(a.isEqual(a), true);
    assertEquals(b.isEqual(b), true);

    assertEquals(a.isAfter(a), false);
    assertEquals(b.isAfter(b), false);
}
 
Example 4
Source File: TCKOffsetTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test()
@UseDataProvider("provider_sampleTimes")
public void test_equals_false_nano_differs(int h, int m, int s, int n, ZoneOffset ignored) {
    n = (n == 999999999 ? 999999998 : n);
    OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE);
    OffsetTime b = OffsetTime.of(h, m, s, n + 1, OFFSET_PONE);
    assertEquals(a.equals(b), false);
}
 
Example 5
Source File: TCKOffsetTime.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="sampleTimes")
public void test_equals_false_nano_differs(int h, int m, int s, int n, ZoneOffset ignored) {
    n = (n == 999999999 ? 999999998 : n);
    OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE);
    OffsetTime b = OffsetTime.of(h, m, s, n + 1, OFFSET_PONE);
    assertEquals(a.equals(b), false);
}
 
Example 6
Source File: TCKZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_with_adjuster_OffsetTime_validOffsetNotInOverlap() {
    // OT has valid offset for resulting time
    OffsetTime ot = OffsetTime.of(15, 50, 30, 40, OFFSET_0100);
    ZonedDateTime zdt = TEST_PARIS_OVERLAP_2008_10_26_02_30.atZone(ZONE_PARIS);
    ZonedDateTime test = zdt.with(ot);
    assertEquals(test.toLocalDateTime(), dateTime(2008, 10, 26, 15, 50, 30, 40));
    assertEquals(test.getOffset(), OFFSET_0100);
}
 
Example 7
Source File: OffsetTimeDeserTest.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeserializationWithTypeInfo03() throws Exception
{
    OffsetTime time = OffsetTime.of(22, 31, 5, 829837, ZoneOffset.of("+1100"));

    final ObjectMapper mapper = newMapperBuilder()
            .addMixIn(Temporal.class, MockObjectConfiguration.class)
            .build();
    Temporal value = mapper.readValue(
            "[\"" + OffsetTime.class.getName() + "\",\"" + time.toString() + "\"]", Temporal.class
            );
    assertTrue("The value should be a OffsetTime.", value instanceof OffsetTime);
    assertEquals("The value is not correct.", time, value);
}
 
Example 8
Source File: TCKOffsetTime.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=NullPointerException.class)
public void test_isAfter_null() {
    OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
    a.isAfter(null);
}
 
Example 9
Source File: TCKDateTimeFormatter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@DataProvider(name="formatWithZoneWithChronology")
Object[][] data_format_withZone_withChronology() {
    YearMonth ym = YearMonth.of(2008, 6);
    LocalDate ld = LocalDate.of(2008, 6, 30);
    LocalTime lt = LocalTime.of(11, 30);
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 11, 30);
    OffsetTime ot = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE);
    OffsetDateTime odt = OffsetDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PONE);
    ZonedDateTime zdt = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), ZONE_PARIS);
    ChronoZonedDateTime<ThaiBuddhistDate> thaiZdt = ThaiBuddhistChronology.INSTANCE.zonedDateTime(zdt);
    Instant instant = Instant.ofEpochSecond(3600);
    return new Object[][] {
            {null, null, DayOfWeek.MONDAY, "::::"},
            {null, null, ym, "2008::::ISO"},
            {null, null, ld, "2008::::ISO"},
            {null, null, lt, ":11:::"},
            {null, null, ldt, "2008:11:::ISO"},
            {null, null, ot, ":11:+01:00::"},
            {null, null, odt, "2008:11:+01:00::ISO"},
            {null, null, zdt, "2008:11:+02:00:Europe/Paris:ISO"},
            {null, null, instant, "::::"},

            {IsoChronology.INSTANCE, null, DayOfWeek.MONDAY, "::::ISO"},
            {IsoChronology.INSTANCE, null, ym, "2008::::ISO"},
            {IsoChronology.INSTANCE, null, ld, "2008::::ISO"},
            {IsoChronology.INSTANCE, null, lt, ":11:::ISO"},
            {IsoChronology.INSTANCE, null, ldt, "2008:11:::ISO"},
            {IsoChronology.INSTANCE, null, ot, ":11:+01:00::ISO"},
            {IsoChronology.INSTANCE, null, odt, "2008:11:+01:00::ISO"},
            {IsoChronology.INSTANCE, null, zdt, "2008:11:+02:00:Europe/Paris:ISO"},
            {IsoChronology.INSTANCE, null, instant, "::::ISO"},

            {null, ZONE_PARIS, DayOfWeek.MONDAY, ":::Europe/Paris:"},
            {null, ZONE_PARIS, ym, "2008:::Europe/Paris:ISO"},
            {null, ZONE_PARIS, ld, "2008:::Europe/Paris:ISO"},
            {null, ZONE_PARIS, lt, ":11::Europe/Paris:"},
            {null, ZONE_PARIS, ldt, "2008:11::Europe/Paris:ISO"},
            {null, ZONE_PARIS, ot, ":11:+01:00:Europe/Paris:"},
            {null, ZONE_PARIS, odt, "2008:12:+02:00:Europe/Paris:ISO"},
            {null, ZONE_PARIS, zdt, "2008:11:+02:00:Europe/Paris:ISO"},
            {null, ZONE_PARIS, instant, "1970:02:+01:00:Europe/Paris:ISO"},

            {null, OFFSET_PTHREE, DayOfWeek.MONDAY, ":::+03:00:"},
            {null, OFFSET_PTHREE, ym, "2008:::+03:00:ISO"},
            {null, OFFSET_PTHREE, ld, "2008:::+03:00:ISO"},
            {null, OFFSET_PTHREE, lt, ":11::+03:00:"},
            {null, OFFSET_PTHREE, ldt, "2008:11::+03:00:ISO"},
            {null, OFFSET_PTHREE, ot, null},  // offset and zone clash
            {null, OFFSET_PTHREE, odt, "2008:13:+03:00:+03:00:ISO"},
            {null, OFFSET_PTHREE, zdt, "2008:12:+03:00:+03:00:ISO"},
            {null, OFFSET_PTHREE, instant, "1970:04:+03:00:+03:00:ISO"},

            {ThaiBuddhistChronology.INSTANCE, null, DayOfWeek.MONDAY, null},  // not a complete date
            {ThaiBuddhistChronology.INSTANCE, null, ym, null},  // not a complete date
            {ThaiBuddhistChronology.INSTANCE, null, ld, "2551::::ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, null, lt, ":11:::ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, null, ldt, "2551:11:::ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, null, ot, ":11:+01:00::ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, null, odt, "2551:11:+01:00::ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, null, zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, null, instant, "::::ThaiBuddhist"},

            {ThaiBuddhistChronology.INSTANCE, null, DayOfWeek.MONDAY, null},  // not a complete date
            {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ym, null},  // not a complete date
            {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ld, "2551:::Europe/Paris:ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, lt, ":11::Europe/Paris:ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ldt, "2551:11::Europe/Paris:ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ot, ":11:+01:00:Europe/Paris:ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, odt, "2551:12:+02:00:Europe/Paris:ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, instant, "2513:02:+01:00:Europe/Paris:ThaiBuddhist"},

            {null, ZONE_PARIS, thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"},
            {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"},
            {IsoChronology.INSTANCE, ZONE_PARIS, thaiZdt, "2008:11:+02:00:Europe/Paris:ISO"},
    };
}
 
Example 10
Source File: TCKOffsetTime.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withHour_noChange() {
    OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
    OffsetTime test = base.withHour(11);
    assertEquals(test, base);
}
 
Example 11
Source File: TCKOffsetTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_withOffsetSameInstant_null() {
    OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
    base.withOffsetSameInstant(null);
}
 
Example 12
Source File: TCKOffsetTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_noChange() {
    OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
    OffsetTime test = base.withMinute(30);
    assertEquals(test, base);
}
 
Example 13
Source File: TCKOffsetTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_plusSeconds_zero() {
    OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
    OffsetTime test = base.plusSeconds(0);
    assertEquals(test, base);
}
 
Example 14
Source File: TCKOffsetTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withHour_normal() {
    OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
    OffsetTime test = base.withHour(15);
    assertEquals(test, OffsetTime.of(15, 30, 59, 0, OFFSET_PONE));
}
 
Example 15
Source File: ResourceParameterTests.java    From smallrye-open-api with Apache License 2.0 4 votes vote down vote up
@Path("utc")
@POST
public OffsetTime toUTC(@QueryParam("local") LocalTime local, @QueryParam("offsetId") String offsetId) {
    return OffsetTime.of(local, ZoneOffset.of(offsetId));
}
 
Example 16
Source File: TCKOffsetTime.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test
public void factory_intsHMSN() {
    OffsetTime test = OffsetTime.of(11, 30, 10, 500, OFFSET_PONE);
    check(test, 11, 30, 10, 500, OFFSET_PONE);
}
 
Example 17
Source File: TCKOffsetTime.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withOffsetSameLocal_noChange() {
    OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
    OffsetTime test = base.withOffsetSameLocal(OFFSET_PONE);
    assertEquals(test, base);
}
 
Example 18
Source File: TCKOffsetTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_minusMinutes() {
    OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
    OffsetTime test = base.minusMinutes(50);
    assertEquals(test, OffsetTime.of(10, 40, 59, 0, OFFSET_PONE));
}
 
Example 19
Source File: TCKOffsetTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_until_convertedType() {
    OffsetTime offsetTime = OffsetTime.of(1, 1, 1, 0, OFFSET_PONE);
    OffsetDateTime offsetDateTime = offsetTime.plusSeconds(3).atDate(LocalDate.of(1980, 2, 10));
    assertEquals(offsetTime.until(offsetDateTime, SECONDS), 3);
}
 
Example 20
Source File: TCKOffsetTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_minusSeconds() {
    OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
    OffsetTime test = base.minusSeconds(60);
    assertEquals(test, OffsetTime.of(11, 29, 59, 0, OFFSET_PONE));
}