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

The following examples show how to use java.time.OffsetTime#now() . 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: TCKOffsetTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock_allSecsInDay() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetTime test = OffsetTime.now(clock);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 8);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
 
Example 2
Source File: TCKOffsetTime.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock_allSecsInDay() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetTime test = OffsetTime.now(clock);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 8);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
 
Example 3
Source File: TCKOffsetTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock_offsets() {
    Instant base = LocalDateTime.of(1970, 1, 1, 12, 0).toInstant(ZoneOffset.UTC);
    for (int i = -9; i < 15; i++) {
        ZoneOffset offset = ZoneOffset.ofHours(i);
        Clock clock = Clock.fixed(base, offset);
        OffsetTime test = OffsetTime.now(clock);
        assertEquals(test.getHour(), (12 + i) % 24);
        assertEquals(test.getMinute(), 0);
        assertEquals(test.getSecond(), 0);
        assertEquals(test.getNano(), 0);
        assertEquals(test.getOffset(), offset);
    }
}
 
Example 4
Source File: TCKOffsetTime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock_allSecsInDay() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetTime test = OffsetTime.now(clock);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 8);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
 
Example 5
Source File: TCKOffsetTime.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock_beforeEpoch() {
    for (int i =-1; i >= -(24 * 60 * 60); i--) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetTime test = OffsetTime.now(clock);
        assertEquals(test.getHour(), ((i + 24 * 60 * 60) / (60 * 60)) % 24);
        assertEquals(test.getMinute(), ((i + 24 * 60 * 60) / 60) % 60);
        assertEquals(test.getSecond(), (i + 24 * 60 * 60) % 60);
        assertEquals(test.getNano(), 8);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
 
Example 6
Source File: TCKOffsetTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock_beforeEpoch() {
    for (int i =-1; i >= -(24 * 60 * 60); i--) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetTime test = OffsetTime.now(clock);
        assertEquals(test.getHour(), ((i + 24 * 60 * 60) / (60 * 60)) % 24);
        assertEquals(test.getMinute(), ((i + 24 * 60 * 60) / 60) % 60);
        assertEquals(test.getSecond(), (i + 24 * 60 * 60) % 60);
        assertEquals(test.getNano(), 8);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
 
Example 7
Source File: TCKOffsetTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now() {
    ZonedDateTime nowDT = ZonedDateTime.now();

    OffsetTime expected = OffsetTime.now(Clock.systemDefaultZone());
    OffsetTime test = OffsetTime.now();
    long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
    assertTrue(diff < 100000000);  // less than 0.1 secs
    assertEquals(test.getOffset(), nowDT.getOffset());
}
 
Example 8
Source File: TCKOffsetTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void now_Clock_offsets() {
    Instant base = LocalDateTime.of(1970, 1, 1, 12, 0).toInstant(ZoneOffset.UTC);
    for (int i = -9; i < 15; i++) {
        ZoneOffset offset = ZoneOffset.ofHours(i);
        Clock clock = Clock.fixed(base, offset);
        OffsetTime test = OffsetTime.now(clock);
        assertEquals(test.getHour(), (12 + i) % 24);
        assertEquals(test.getMinute(), 0);
        assertEquals(test.getSecond(), 0);
        assertEquals(test.getNano(), 0);
        assertEquals(test.getOffset(), offset);
    }
}
 
Example 9
Source File: TCKOffsetTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock_beforeEpoch() {
    for (int i =-1; i >= -(24 * 60 * 60); i--) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetTime test = OffsetTime.now(clock);
        assertEquals(test.getHour(), ((i + 24 * 60 * 60) / (60 * 60)) % 24);
        assertEquals(test.getMinute(), ((i + 24 * 60 * 60) / 60) % 60);
        assertEquals(test.getSecond(), (i + 24 * 60 * 60) % 60);
        assertEquals(test.getNano(), 8);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
 
Example 10
Source File: TCKOffsetTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void now() {
    ZonedDateTime nowDT = ZonedDateTime.now();

    OffsetTime expected = OffsetTime.now(Clock.systemDefaultZone());
    OffsetTime test = OffsetTime.now();
    long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
    assertTrue(diff < 100000000);  // less than 0.1 secs
    assertEquals(test.getOffset(), nowDT.getOffset());
}
 
Example 11
Source File: TCKOffsetTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void now_Clock_beforeEpoch() {
    for (int i =-1; i >= -(24 * 60 * 60); i--) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetTime test = OffsetTime.now(clock);
        assertEquals(test.getHour(), ((i + 24 * 60 * 60) / (60 * 60)) % 24);
        assertEquals(test.getMinute(), ((i + 24 * 60 * 60) / 60) % 60);
        assertEquals(test.getSecond(), (i + 24 * 60 * 60) % 60);
        assertEquals(test.getNano(), 8);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
 
Example 12
Source File: TCKOffsetTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullZoneId() {
    OffsetTime.now((ZoneId) null);
}
 
Example 13
Source File: TCKOffsetTime.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=NullPointerException.class)
public void now_Clock_nullClock() {
    OffsetTime.now((Clock) null);
}
 
Example 14
Source File: TCKOffsetTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullZoneId() {
    OffsetTime.now((ZoneId) null);
}
 
Example 15
Source File: TCKOffsetTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
    OffsetTime.now((Clock) null);
}
 
Example 16
Source File: TCKOffsetTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
    OffsetTime.now((Clock) null);
}
 
Example 17
Source File: TCKOffsetTime.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullZoneId() {
    OffsetTime.now((ZoneId) null);
}
 
Example 18
Source File: TCKOffsetTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullZoneId() {
    OffsetTime.now((ZoneId) null);
}
 
Example 19
Source File: TCKOffsetTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
    OffsetTime.now((Clock) null);
}
 
Example 20
Source File: TCKOffsetTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullZoneId() {
    OffsetTime.now((ZoneId) null);
}