Java Code Examples for java.time.LocalTime#ofNanoOfDay()

The following examples show how to use java.time.LocalTime#ofNanoOfDay() . 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: ChronoLocalDateTimeImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private ChronoLocalDateTimeImpl<D> plusWithOverflow(D newDate, long hours, long minutes, long seconds, long nanos) {
    // 9223372036854775808 long, 2147483648 int
    if ((hours | minutes | seconds | nanos) == 0) {
        return with(newDate, time);
    }
    long totDays = nanos / NANOS_PER_DAY +             //   max/24*60*60*1B
            seconds / SECONDS_PER_DAY +                //   max/24*60*60
            minutes / MINUTES_PER_DAY +                //   max/24*60
            hours / HOURS_PER_DAY;                     //   max/24
    long totNanos = nanos % NANOS_PER_DAY +                    //   max  86400000000000
            (seconds % SECONDS_PER_DAY) * NANOS_PER_SECOND +   //   max  86400000000000
            (minutes % MINUTES_PER_DAY) * NANOS_PER_MINUTE +   //   max  86400000000000
            (hours % HOURS_PER_DAY) * NANOS_PER_HOUR;          //   max  86400000000000
    long curNoD = time.toNanoOfDay();                          //   max  86400000000000
    totNanos = totNanos + curNoD;                              // total 432000000000000
    totDays += Math.floorDiv(totNanos, NANOS_PER_DAY);
    long newNoD = Math.floorMod(totNanos, NANOS_PER_DAY);
    LocalTime newTime = (newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD));
    return with(newDate.plus(totDays, ChronoUnit.DAYS), newTime);
}
 
Example 2
Source File: ChronoLocalDateTimeImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private ChronoLocalDateTimeImpl<D> plusWithOverflow(D newDate, long hours, long minutes, long seconds, long nanos) {
    // 9223372036854775808 long, 2147483648 int
    if ((hours | minutes | seconds | nanos) == 0) {
        return with(newDate, time);
    }
    long totDays = nanos / NANOS_PER_DAY +             //   max/24*60*60*1B
            seconds / SECONDS_PER_DAY +                //   max/24*60*60
            minutes / MINUTES_PER_DAY +                //   max/24*60
            hours / HOURS_PER_DAY;                     //   max/24
    long totNanos = nanos % NANOS_PER_DAY +                    //   max  86400000000000
            (seconds % SECONDS_PER_DAY) * NANOS_PER_SECOND +   //   max  86400000000000
            (minutes % MINUTES_PER_DAY) * NANOS_PER_MINUTE +   //   max  86400000000000
            (hours % HOURS_PER_DAY) * NANOS_PER_HOUR;          //   max  86400000000000
    long curNoD = time.toNanoOfDay();                          //   max  86400000000000
    totNanos = totNanos + curNoD;                              // total 432000000000000
    totDays += Math.floorDiv(totNanos, NANOS_PER_DAY);
    long newNoD = Math.floorMod(totNanos, NANOS_PER_DAY);
    LocalTime newTime = (newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD));
    return with(newDate.plus(totDays, ChronoUnit.DAYS), newTime);
}
 
Example 3
Source File: ChronoLocalDateTimeImpl.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
private ChronoLocalDateTimeImpl<D> plusWithOverflow(D newDate, long hours, long minutes, long seconds, long nanos) {
    // 9223372036854775808 long, 2147483648 int
    if ((hours | minutes | seconds | nanos) == 0) {
        return with(newDate, time);
    }
    long totDays = nanos / NANOS_PER_DAY +             //   max/24*60*60*1B
            seconds / SECONDS_PER_DAY +                //   max/24*60*60
            minutes / MINUTES_PER_DAY +                //   max/24*60
            hours / HOURS_PER_DAY;                     //   max/24
    long totNanos = nanos % NANOS_PER_DAY +                    //   max  86400000000000
            (seconds % SECONDS_PER_DAY) * NANOS_PER_SECOND +   //   max  86400000000000
            (minutes % MINUTES_PER_DAY) * NANOS_PER_MINUTE +   //   max  86400000000000
            (hours % HOURS_PER_DAY) * NANOS_PER_HOUR;          //   max  86400000000000
    long curNoD = time.toNanoOfDay();                          //   max  86400000000000
    totNanos = totNanos + curNoD;                              // total 432000000000000
    totDays += Math.floorDiv(totNanos, NANOS_PER_DAY);
    long newNoD = Math.floorMod(totNanos, NANOS_PER_DAY);
    LocalTime newTime = (newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD));
    return with(newDate.plus(totDays, ChronoUnit.DAYS), newTime);
}
 
Example 4
Source File: ChronoLocalDateTimeImpl.java    From j2objc with Apache License 2.0 6 votes vote down vote up
private ChronoLocalDateTimeImpl<D> plusWithOverflow(D newDate, long hours, long minutes, long seconds, long nanos) {
    // 9223372036854775808 long, 2147483648 int
    if ((hours | minutes | seconds | nanos) == 0) {
        return with(newDate, time);
    }
    long totDays = nanos / NANOS_PER_DAY +             //   max/24*60*60*1B
            seconds / SECONDS_PER_DAY +                //   max/24*60*60
            minutes / MINUTES_PER_DAY +                //   max/24*60
            hours / HOURS_PER_DAY;                     //   max/24
    long totNanos = nanos % NANOS_PER_DAY +                    //   max  86400000000000
            (seconds % SECONDS_PER_DAY) * NANOS_PER_SECOND +   //   max  86400000000000
            (minutes % MINUTES_PER_DAY) * NANOS_PER_MINUTE +   //   max  86400000000000
            (hours % HOURS_PER_DAY) * NANOS_PER_HOUR;          //   max  86400000000000
    long curNoD = time.toNanoOfDay();                          //   max  86400000000000
    totNanos = totNanos + curNoD;                              // total 432000000000000
    totDays += Math.floorDiv(totNanos, NANOS_PER_DAY);
    long newNoD = Math.floorMod(totNanos, NANOS_PER_DAY);
    LocalTime newTime = (newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD));
    return with(newDate.plus(totDays, ChronoUnit.DAYS), newTime);
}
 
Example 5
Source File: ChronoLocalDateTimeImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private ChronoLocalDateTimeImpl<D> plusWithOverflow(D newDate, long hours, long minutes, long seconds, long nanos) {
    // 9223372036854775808 long, 2147483648 int
    if ((hours | minutes | seconds | nanos) == 0) {
        return with(newDate, time);
    }
    long totDays = nanos / NANOS_PER_DAY +             //   max/24*60*60*1B
            seconds / SECONDS_PER_DAY +                //   max/24*60*60
            minutes / MINUTES_PER_DAY +                //   max/24*60
            hours / HOURS_PER_DAY;                     //   max/24
    long totNanos = nanos % NANOS_PER_DAY +                    //   max  86400000000000
            (seconds % SECONDS_PER_DAY) * NANOS_PER_SECOND +   //   max  86400000000000
            (minutes % MINUTES_PER_DAY) * NANOS_PER_MINUTE +   //   max  86400000000000
            (hours % HOURS_PER_DAY) * NANOS_PER_HOUR;          //   max  86400000000000
    long curNoD = time.toNanoOfDay();                          //   max  86400000000000
    totNanos = totNanos + curNoD;                              // total 432000000000000
    totDays += Math.floorDiv(totNanos, NANOS_PER_DAY);
    long newNoD = Math.floorMod(totNanos, NANOS_PER_DAY);
    LocalTime newTime = (newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD));
    return with(newDate.plus(totDays, ChronoUnit.DAYS), newTime);
}
 
Example 6
Source File: TemporalQueries.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LocalTime queryFrom(TemporalAccessor temporal) {
    if (temporal.isSupported(NANO_OF_DAY)) {
        return LocalTime.ofNanoOfDay(temporal.getLong(NANO_OF_DAY));
    }
    return null;
}
 
Example 7
Source File: TestLocalTime.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void factory_ofNanoOfDay_singletons() {
    for (int i = 0; i < 24; i++) {
        LocalTime test1 = LocalTime.ofNanoOfDay(i * 1000000000L * 60L * 60L);
        LocalTime test2 = LocalTime.of(i, 0);
        assertSame(test1, test2);
    }
}
 
Example 8
Source File: TestLocalTime.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void factory_ofNanoOfDay_singletons() {
    for (int i = 0; i < 24; i++) {
        LocalTime test1 = LocalTime.ofNanoOfDay(i * 1000000000L * 60L * 60L);
        LocalTime test2 = LocalTime.of(i, 0);
        assertSame(test1, test2);
    }
}
 
Example 9
Source File: TemporalQueries.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTime queryFrom(TemporalAccessor temporal) {
    if (temporal.isSupported(NANO_OF_DAY)) {
        return LocalTime.ofNanoOfDay(temporal.getLong(NANO_OF_DAY));
    }
    return null;
}
 
Example 10
Source File: TCKLocalTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_ofNanoOfDay() {
    LocalTime localTime = LocalTime.ofNanoOfDay(60 * 60 * 1000000000L + 17);
    check(localTime, 1, 0, 0, 17);
}
 
Example 11
Source File: TCKLocalTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofNanoOfDay_tooHigh() {
    LocalTime.ofNanoOfDay(24 * 60 * 60 * 1000000000L);
}
 
Example 12
Source File: TCKLocalTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofNanoOfDay_tooLow() {
    LocalTime.ofNanoOfDay(-1);
}
 
Example 13
Source File: TCKLocalTime.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_ofNanoOfDay() {
    LocalTime localTime = LocalTime.ofNanoOfDay(60 * 60 * 1000000000L + 17);
    check(localTime, 1, 0, 0, 17);
}
 
Example 14
Source File: LocalTimeSerializer.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
protected LocalTime readValue(final Buffer buffer, final GraphBinaryReader context) throws IOException {
    return LocalTime.ofNanoOfDay(buffer.readLong());
}
 
Example 15
Source File: TCKLocalTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofNanoOfDay_tooLow() {
    LocalTime.ofNanoOfDay(-1);
}
 
Example 16
Source File: TCKLocalTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_ofNanoOfDay() {
    LocalTime localTime = LocalTime.ofNanoOfDay(60 * 60 * 1000000000L + 17);
    check(localTime, 1, 0, 0, 17);
}
 
Example 17
Source File: LocalTimeCodec.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
private static LocalTime negativeCircle(long hour, long minute, long second, long nano) {
    long total = -(hour * NANOS_OF_HOUR + minute * NANOS_OF_MINUTE +
        second * NANOS_OF_SECOND + nano);

    return LocalTime.ofNanoOfDay(((total % NANOS_OF_DAY) + NANOS_OF_DAY) % NANOS_OF_DAY);
}
 
Example 18
Source File: TCKLocalTime.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_ofNanoOfDay() {
    LocalTime localTime = LocalTime.ofNanoOfDay(60 * 60 * 1000000000L + 17);
    check(localTime, 1, 0, 0, 17);
}
 
Example 19
Source File: TimeAttributeDescription.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
public Object getObject(final int id) {
    return data[id] == DEFAULT_VALUE ? null
            : LocalTime.ofNanoOfDay(((long) data[id])
                    * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
}
 
Example 20
Source File: TCKLocalTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofNanoOfDay_tooHigh() {
    LocalTime.ofNanoOfDay(24 * 60 * 60 * 1000000000L);
}