java.time.LocalTime#getNano ( )源码实例Demo

下面列出了java.time.LocalTime#getNano ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: r2dbc-mysql   文件: DateTimeCodecTestSupport.java
protected final ByteBuf toBinary(LocalDateTime dateTime) {
    ByteBuf buf = LocalDateCodecTest.encode(dateTime.toLocalDate());
    LocalTime time = dateTime.toLocalTime();

    if (LocalTime.MIDNIGHT.equals(time)) {
        return buf;
    }

    buf.writeByte(time.getHour())
        .writeByte(time.getMinute())
        .writeByte(time.getSecond());

    if (time.getNano() != 0) {
        buf.writeIntLE((int) TimeUnit.NANOSECONDS.toMicros(time.getNano()));
    }

    return buf;
}
 
源代码2 项目: r2dbc-mysql   文件: TimeCodecTestSupport.java
protected final ByteBuf toBinary(LocalTime time) {
    if (LocalTime.MIDNIGHT.equals(time)) {
        return Unpooled.buffer(0, 0);
    }

    ByteBuf buf = Unpooled.buffer().writeBoolean(false)
        .writeIntLE(0)
        .writeByte(time.getHour())
        .writeByte(time.getMinute())
        .writeByte(time.getSecond());

    if (time.getNano() != 0) {
        buf.writeIntLE((int) TimeUnit.NANOSECONDS.toMicros(time.getNano()));
    }

    return buf;
}
 
源代码3 项目: r2dbc-mysql   文件: DateTimeCodecTestSupport.java
protected final ByteBuf toBinary(LocalDateTime dateTime) {
    ByteBuf buf = LocalDateCodecTest.encode(dateTime.toLocalDate());
    LocalTime time = dateTime.toLocalTime();

    if (LocalTime.MIDNIGHT.equals(time)) {
        return buf;
    }

    buf.writeByte(time.getHour())
        .writeByte(time.getMinute())
        .writeByte(time.getSecond());

    if (time.getNano() != 0) {
        buf.writeIntLE((int) TimeUnit.NANOSECONDS.toMicros(time.getNano()));
    }

    return buf;
}
 
源代码4 项目: r2dbc-mysql   文件: TimeCodecTestSupport.java
protected final ByteBuf toBinary(LocalTime time) {
    if (LocalTime.MIDNIGHT.equals(time)) {
        return Unpooled.buffer(0, 0);
    }

    ByteBuf buf = Unpooled.buffer().writeBoolean(false)
        .writeIntLE(0)
        .writeByte(time.getHour())
        .writeByte(time.getMinute())
        .writeByte(time.getSecond());

    if (time.getNano() != 0) {
        buf.writeIntLE((int) TimeUnit.NANOSECONDS.toMicros(time.getNano()));
    }

    return buf;
}
 
private void encodeTimeNParameter(ByteBuf payload, LocalTime time, byte scale) {
  payload.writeByte(0x00);
  payload.writeByte(0x00);
  payload.writeByte(MSSQLDataTypeId.TIMENTYPE_ID);

  payload.writeByte(scale); //FIXME scale?
  if (time == null) {
    payload.writeByte(0);
  } else {
    int length;
    if (scale <= 2) {
      length = 3;
    } else if (scale <= 4) {
      length = 4;
    } else {
      length = 5;
    }
    payload.writeByte(length);
    long nanos = time.getNano();
    int seconds = time.toSecondOfDay();
    long value = (long) ((long) seconds * Math.pow(10, scale) + nanos);
    encodeInt40(payload, value);
  }
}
 
private final void _serializeAsArrayContents(LocalTime value, JsonGenerator g,
        SerializerProvider provider) throws IOException
{
    g.writeNumber(value.getHour());
    g.writeNumber(value.getMinute());
    int secs = value.getSecond();
    int nanos = value.getNano();
    if ((secs > 0) || (nanos > 0))
    {
        g.writeNumber(secs);
        if (nanos > 0) {
            if (useNanoseconds(provider)) {
                g.writeNumber(nanos);
            } else {
                g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND));
            }
        }
    }
}
 
源代码7 项目: flink   文件: JsonRowDeserializationSchema.java
private LocalTime convertToLocalTime(ObjectMapper mapper, JsonNode jsonNode) {
	// according to RFC 3339 every full-time must have a timezone;
	// until we have full timezone support, we only support UTC;
	// users can parse their time as string as a workaround

	TemporalAccessor parsedTime = RFC3339_TIME_FORMAT.parse(jsonNode.asText());

	ZoneOffset zoneOffset = parsedTime.query(TemporalQueries.offset());
	LocalTime localTime = parsedTime.query(TemporalQueries.localTime());

	if (zoneOffset != null && zoneOffset.getTotalSeconds() != 0 || localTime.getNano() != 0) {
		throw new IllegalStateException(
			"Invalid time format. Only a time in UTC timezone without milliseconds is supported yet.");
	}

	return localTime;
}
 
源代码8 项目: r2dbc-mysql   文件: LocalDateTimeCodec.java
static ByteBuf encodeBinary(ByteBufAllocator alloc, LocalDateTime value) {
    LocalTime time = value.toLocalTime();

    if (LocalTime.MIDNIGHT.equals(time)) {
        return LocalDateCodec.encodeDate(alloc, value.toLocalDate());
    }

    int nano = time.getNano();
    int bytes = nano > 0 ? DateTimes.MICRO_DATETIME_SIZE : DateTimes.DATETIME_SIZE;
    ByteBuf buf = alloc.buffer(Byte.BYTES + bytes);

    try {
        buf.writeByte(bytes)
            .writeShortLE(value.getYear())
            .writeByte(value.getMonthValue())
            .writeByte(value.getDayOfMonth())
            .writeByte(time.getHour())
            .writeByte(time.getMinute())
            .writeByte(time.getSecond());

        if (nano > 0) {
            return buf.writeIntLE(nano / DateTimes.NANOS_OF_MICRO);
        }

        return buf;
    } catch (Throwable e) {
        buf.release();
        throw e;
    }
}
 
源代码9 项目: r2dbc-mysql   文件: LocalTimeCodec.java
static ByteBuf encodeBinary(ByteBufAllocator alloc, LocalTime time) {
    if (LocalTime.MIDNIGHT.equals(time)) {
        // It is zero of var int, not terminal.
        return alloc.buffer(Byte.BYTES).writeByte(0);
    }

    int nanos = time.getNano();
    int size = nanos > 0 ? MICRO_TIME_SIZE : TIME_SIZE;

    ByteBuf buf = alloc.buffer(Byte.BYTES + size);

    try {
        buf.writeByte(size)
            .writeBoolean(false)
            .writeIntLE(0)
            .writeByte(time.getHour())
            .writeByte(time.getMinute())
            .writeByte(time.getSecond());

        if (nanos > 0) {
            return buf.writeIntLE(nanos / NANOS_OF_MICRO);
        }

        return buf;
    } catch (Throwable e) {
        buf.release();
        throw e;
    }
}
 
源代码10 项目: flink   文件: LocalTimeComparator.java
public static void putNormalizedKeyLocalTime(LocalTime record, MemorySegment target, int offset, int numBytes) {
	int hour = record.getHour();
	if (numBytes > 0) {
		target.put(offset, (byte) (hour & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int minute = record.getMinute();
	if (numBytes > 0) {
		target.put(offset, (byte) (minute & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int second = record.getSecond();
	if (numBytes > 0) {
		target.put(offset, (byte) (second & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int nano = record.getNano();
	int unsignedNano = nano - Integer.MIN_VALUE;
	if (numBytes >= 4) {
		target.putIntBigEndian(offset, unsignedNano);
		numBytes -= 4;
		offset += 4;
	} else if (numBytes > 0) {
		for (int i = 0; numBytes > 0; numBytes--, i++) {
			target.put(offset + i, (byte) (unsignedNano >>> ((3 - i) << 3)));
		}
		return;
	}

	for (int i = 0; i < numBytes; i++) {
		target.put(offset + i, (byte) 0);
	}
}
 
源代码11 项目: flink   文件: LocalTimeComparator.java
public static void putNormalizedKeyLocalTime(LocalTime record, MemorySegment target, int offset, int numBytes) {
	int hour = record.getHour();
	if (numBytes > 0) {
		target.put(offset, (byte) (hour & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int minute = record.getMinute();
	if (numBytes > 0) {
		target.put(offset, (byte) (minute & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int second = record.getSecond();
	if (numBytes > 0) {
		target.put(offset, (byte) (second & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int nano = record.getNano();
	int unsignedNano = nano - Integer.MIN_VALUE;
	if (numBytes >= 4) {
		target.putIntBigEndian(offset, unsignedNano);
		numBytes -= 4;
		offset += 4;
	} else if (numBytes > 0) {
		for (int i = 0; numBytes > 0; numBytes--, i++) {
			target.put(offset + i, (byte) (unsignedNano >>> ((3 - i) << 3)));
		}
		return;
	}

	for (int i = 0; i < numBytes; i++) {
		target.put(offset + i, (byte) 0);
	}
}
 
源代码12 项目: joyrpc   文件: LocalTimeHandle.java
@Override
public void wrap(final LocalTime localTime) {
    this.hour = localTime.getHour();
    this.minute = localTime.getMinute();
    this.second = localTime.getSecond();
    this.nano = localTime.getNano();

}
 
源代码13 项目: r2dbc-mysql   文件: LocalDateTimeCodec.java
static ByteBuf encodeBinary(ByteBufAllocator alloc, LocalDateTime value) {
    LocalTime time = value.toLocalTime();

    if (LocalTime.MIDNIGHT.equals(time)) {
        return LocalDateCodec.encodeDate(alloc, value.toLocalDate());
    }

    int nano = time.getNano();
    int bytes = nano > 0 ? DateTimes.MICRO_DATETIME_SIZE : DateTimes.DATETIME_SIZE;
    ByteBuf buf = alloc.buffer(Byte.BYTES + bytes);

    try {
        buf.writeByte(bytes)
            .writeShortLE(value.getYear())
            .writeByte(value.getMonthValue())
            .writeByte(value.getDayOfMonth())
            .writeByte(time.getHour())
            .writeByte(time.getMinute())
            .writeByte(time.getSecond());

        if (nano > 0) {
            return buf.writeIntLE(nano / DateTimes.NANOS_OF_MICRO);
        }

        return buf;
    } catch (Throwable e) {
        buf.release();
        throw e;
    }
}
 
源代码14 项目: r2dbc-mysql   文件: LocalTimeCodec.java
static ByteBuf encodeBinary(ByteBufAllocator alloc, LocalTime time) {
    if (LocalTime.MIDNIGHT.equals(time)) {
        // It is zero of var int, not terminal.
        return alloc.buffer(Byte.BYTES).writeByte(0);
    }

    int nanos = time.getNano();
    int size = nanos > 0 ? MICRO_TIME_SIZE : TIME_SIZE;

    ByteBuf buf = alloc.buffer(Byte.BYTES + size);

    try {
        buf.writeByte(size)
            .writeBoolean(false)
            .writeIntLE(0)
            .writeByte(time.getHour())
            .writeByte(time.getMinute())
            .writeByte(time.getSecond());

        if (nanos > 0) {
            return buf.writeIntLE(nanos / NANOS_OF_MICRO);
        }

        return buf;
    } catch (Throwable e) {
        buf.release();
        throw e;
    }
}
 
源代码15 项目: vertx-sql-client   文件: DataTypeCodec.java
private static void binaryEncodeTime(LocalTime value, ByteBuf buffer) {
  int hour = value.getHour();
  int minute = value.getMinute();
  int second = value.getSecond();
  int nano = value.getNano();
  if (nano == 0) {
    if (hour == 0 && minute == 0 && second == 0) {
      buffer.writeByte(0);
    } else {
      buffer.writeByte(8);
      buffer.writeByte(0);
      buffer.writeIntLE(0);
      buffer.writeByte(hour);
      buffer.writeByte(minute);
      buffer.writeByte(second);
    }
  } else {
    int microSecond = nano / 1000;
    buffer.writeByte(12);
    buffer.writeByte(0);
    buffer.writeIntLE(0);
    buffer.writeByte(hour);
    buffer.writeByte(minute);
    buffer.writeByte(second);
    buffer.writeIntLE(microSecond);
  }
}
 
源代码16 项目: Bytecoder   文件: ZoneOffsetTransitionRule.java
/**
 * Obtains an instance defining the yearly rule to create transitions between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param month  the month of the month-day of the first day of the cutover week, not null
 * @param dayOfMonthIndicator  the day of the month-day of the cutover week, positive if the week is that
 *  day or later, negative if the week is that day or earlier, counting from the last day of the month,
 *  from -28 to 31 excluding 0
 * @param dayOfWeek  the required day-of-week, null if the month-day should not be changed
 * @param time  the cutover time in the 'before' offset, not null
 * @param timeEndOfDay  whether the time is midnight at the end of day
 * @param timeDefnition  how to interpret the cutover
 * @param standardOffset  the standard offset in force at the cutover, not null
 * @param offsetBefore  the offset before the cutover, not null
 * @param offsetAfter  the offset after the cutover, not null
 * @return the rule, not null
 * @throws IllegalArgumentException if the day of month indicator is invalid
 * @throws IllegalArgumentException if the end of day flag is true when the time is not midnight
 * @throws IllegalArgumentException if {@code time.getNano()} returns non-zero value
 */
public static ZoneOffsetTransitionRule of(
        Month month,
        int dayOfMonthIndicator,
        DayOfWeek dayOfWeek,
        LocalTime time,
        boolean timeEndOfDay,
        TimeDefinition timeDefnition,
        ZoneOffset standardOffset,
        ZoneOffset offsetBefore,
        ZoneOffset offsetAfter) {
    Objects.requireNonNull(month, "month");
    Objects.requireNonNull(time, "time");
    Objects.requireNonNull(timeDefnition, "timeDefnition");
    Objects.requireNonNull(standardOffset, "standardOffset");
    Objects.requireNonNull(offsetBefore, "offsetBefore");
    Objects.requireNonNull(offsetAfter, "offsetAfter");
    if (dayOfMonthIndicator < -28 || dayOfMonthIndicator > 31 || dayOfMonthIndicator == 0) {
        throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero");
    }
    if (timeEndOfDay && time.equals(LocalTime.MIDNIGHT) == false) {
        throw new IllegalArgumentException("Time must be midnight when end of day flag is true");
    }
    if (time.getNano() != 0) {
        throw new IllegalArgumentException("Time's nano-of-second must be zero");
    }
    return new ZoneOffsetTransitionRule(month, dayOfMonthIndicator, dayOfWeek, time, timeEndOfDay, timeDefnition, standardOffset, offsetBefore, offsetAfter);
}
 
源代码17 项目: openjdk-jdk9   文件: ZoneOffsetTransitionRule.java
/**
 * Obtains an instance defining the yearly rule to create transitions between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param month  the month of the month-day of the first day of the cutover week, not null
 * @param dayOfMonthIndicator  the day of the month-day of the cutover week, positive if the week is that
 *  day or later, negative if the week is that day or earlier, counting from the last day of the month,
 *  from -28 to 31 excluding 0
 * @param dayOfWeek  the required day-of-week, null if the month-day should not be changed
 * @param time  the cutover time in the 'before' offset, not null
 * @param timeEndOfDay  whether the time is midnight at the end of day
 * @param timeDefnition  how to interpret the cutover
 * @param standardOffset  the standard offset in force at the cutover, not null
 * @param offsetBefore  the offset before the cutover, not null
 * @param offsetAfter  the offset after the cutover, not null
 * @return the rule, not null
 * @throws IllegalArgumentException if the day of month indicator is invalid
 * @throws IllegalArgumentException if the end of day flag is true when the time is not midnight
 * @throws IllegalArgumentException if {@code time.getNano()} returns non-zero value
 */
public static ZoneOffsetTransitionRule of(
        Month month,
        int dayOfMonthIndicator,
        DayOfWeek dayOfWeek,
        LocalTime time,
        boolean timeEndOfDay,
        TimeDefinition timeDefnition,
        ZoneOffset standardOffset,
        ZoneOffset offsetBefore,
        ZoneOffset offsetAfter) {
    Objects.requireNonNull(month, "month");
    Objects.requireNonNull(time, "time");
    Objects.requireNonNull(timeDefnition, "timeDefnition");
    Objects.requireNonNull(standardOffset, "standardOffset");
    Objects.requireNonNull(offsetBefore, "offsetBefore");
    Objects.requireNonNull(offsetAfter, "offsetAfter");
    if (dayOfMonthIndicator < -28 || dayOfMonthIndicator > 31 || dayOfMonthIndicator == 0) {
        throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero");
    }
    if (timeEndOfDay && time.equals(LocalTime.MIDNIGHT) == false) {
        throw new IllegalArgumentException("Time must be midnight when end of day flag is true");
    }
    if (time.getNano() != 0) {
        throw new IllegalArgumentException("Time's nano-of-second must be zero");
    }
    return new ZoneOffsetTransitionRule(month, dayOfMonthIndicator, dayOfWeek, time, timeEndOfDay, timeDefnition, standardOffset, offsetBefore, offsetAfter);
}
 
源代码18 项目: r2dbc-mysql   文件: LocalTimeCodec.java
static void encodeTime(ParameterWriter writer, LocalTime time) {
    int micros = time.getNano() / NANOS_OF_MICRO;
    DurationCodec.encodeTime(writer, false, time.getHour(), time.getMinute(), time.getSecond(), micros);
}
 
源代码19 项目: alibaba-rsocket-broker   文件: LocalTimeHandle.java
public LocalTimeHandle(LocalTime o) {
    this.hour = o.getHour();
    this.minute = o.getMinute();
    this.second = o.getSecond();
    this.nano = o.getNano();
}
 
源代码20 项目: r2dbc-mysql   文件: LocalTimeCodec.java
static void encodeTime(ParameterWriter writer, LocalTime time) {
    int micros = time.getNano() / NANOS_OF_MICRO;
    DurationCodec.encodeTime(writer, false, time.getHour(), time.getMinute(), time.getSecond(), micros);
}