Java Code Examples for org.threeten.bp.LocalTime#ofNanoOfDay()

The following examples show how to use org.threeten.bp.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 threetenbp with BSD 3-Clause "New" or "Revised" License 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 += Jdk8Methods.floorDiv(totNanos, NANOS_PER_DAY);
    long newNoD = Jdk8Methods.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: TemporalQueries.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 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 3
Source File: DateTimeBuilder.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void resolveMakeChanges(TemporalField targetField, LocalTime time) {
    long nanOfDay = time.toNanoOfDay();
    Long old = fieldValues.put(ChronoField.NANO_OF_DAY, nanOfDay);
    if (old != null && old.longValue() != nanOfDay) {
        throw new DateTimeException("Conflict found: " + LocalTime.ofNanoOfDay(old) +
                " differs from " + time +
                " while resolving  " + targetField);
    }
}