com.google.protobuf.Timestamp.getNanos()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(161)

本文整理了Java中com.google.protobuf.Timestamp.getNanos()方法的一些代码示例,展示了Timestamp.getNanos()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.getNanos()方法的具体详情如下:
包路径:com.google.protobuf.Timestamp
类名称:Timestamp
方法名:getNanos

Timestamp.getNanos介绍

[英]```
Non-negative fractions of a second at nanosecond resolution. Negative
second values with fractions must still have non-negative nanos values
that count forward in time. Must be from 0 to 999,999,999
inclusive.

`optional int32 nanos = 2;`
[中]```
Non-negative fractions of a second at nanosecond resolution. Negative 
second values with fractions must still have non-negative nanos values 
that count forward in time. Must be from 0 to 999,999,999 
inclusive.

optional int32 nanos = 2;

代码示例

代码示例来源:origin: googleapis/google-cloud-java

private static Long millisFromTimestamp(Timestamp timestamp) {
 return timestamp.getSeconds() * MILLIS_PER_SECOND
   + timestamp.getNanos() / NANOS_PER_MILLISECOND;
}

代码示例来源:origin: com.google.protobuf/protobuf-java

@java.lang.Override
public boolean equals(final java.lang.Object obj) {
 if (obj == this) {
  return true;
 }
 if (!(obj instanceof com.google.protobuf.Timestamp)) {
  return super.equals(obj);
 }
 com.google.protobuf.Timestamp other = (com.google.protobuf.Timestamp) obj;
 boolean result = true;
 result = result && (getSeconds()
   == other.getSeconds());
 result = result && (getNanos()
   == other.getNanos());
 result = result && unknownFields.equals(other.unknownFields);
 return result;
}

代码示例来源:origin: com.google.protobuf/protobuf-java

@java.lang.Override
public int hashCode() {
 if (memoizedHashCode != 0) {
  return memoizedHashCode;
 }
 int hash = 41;
 hash = (19 * hash) + getDescriptor().hashCode();
 hash = (37 * hash) + SECONDS_FIELD_NUMBER;
 hash = (53 * hash) + com.google.protobuf.Internal.hashLong(
   getSeconds());
 hash = (37 * hash) + NANOS_FIELD_NUMBER;
 hash = (53 * hash) + getNanos();
 hash = (29 * hash) + unknownFields.hashCode();
 memoizedHashCode = hash;
 return hash;
}

代码示例来源:origin: googleapis/google-cloud-java

/** Creates an instance of Timestamp from {@code com.google.protobuf.Timestamp}. */
public static Timestamp fromProto(com.google.protobuf.Timestamp proto) {
 return new Timestamp(proto.getSeconds(), proto.getNanos());
}

代码示例来源:origin: googleapis/google-cloud-java

private static int compareTimestamps(Value left, Value right) {
 int cmp =
   Long.compare(left.getTimestampValue().getSeconds(), right.getTimestampValue().getSeconds());
 if (cmp != 0) {
  return cmp;
 } else {
  return Integer.compare(
    left.getTimestampValue().getNanos(), right.getTimestampValue().getNanos());
 }
}

代码示例来源:origin: com.google.protobuf/protobuf-java

public Builder mergeFrom(com.google.protobuf.Timestamp other) {
 if (other == com.google.protobuf.Timestamp.getDefaultInstance()) return this;
 if (other.getSeconds() != 0L) {
  setSeconds(other.getSeconds());
 }
 if (other.getNanos() != 0) {
  setNanos(other.getNanos());
 }
 this.mergeUnknownFields(other.unknownFields);
 onChanged();
 return this;
}

代码示例来源:origin: com.google.cloud/google-cloud-logging

private static Long millisFromTimestamp(Timestamp timestamp) {
 return timestamp.getSeconds() * MILLIS_PER_SECOND
   + timestamp.getNanos() / NANOS_PER_MILLISECOND;
}

代码示例来源:origin: com.google.protobuf/protobuf-java-util

/** Throws an {@link IllegalArgumentException} if the given {@link Timestamp} is not valid. */
public static Timestamp checkValid(Timestamp timestamp) {
 long seconds = timestamp.getSeconds();
 int nanos = timestamp.getNanos();
 if (!isValid(seconds, nanos)) {
   throw new IllegalArgumentException(String.format(
     "Timestamp is not valid. See proto definition for valid values. "
     + "Seconds (%s) must be in range [-62,135,596,800, +253,402,300,799]. "
     + "Nanos (%s) must be in range [0, +999,999,999].", seconds, nanos));
 }
 return timestamp;
}

代码示例来源:origin: com.google.protobuf/protobuf-java-util

@Override
 public int compare(Timestamp t1, Timestamp t2) {
  checkValid(t1);
  checkValid(t2);
  int secDiff = Long.compare(t1.getSeconds(), t2.getSeconds());
  return (secDiff != 0) ? secDiff : Integer.compare(t1.getNanos(), t2.getNanos());
 }
};

代码示例来源:origin: com.google.protobuf/protobuf-java-util

/**
 * Returns true if the given {@link Timestamp} is valid. The {@code seconds} value must be in the
 * range [-62,135,596,800, +253,402,300,799] (i.e., between 0001-01-01T00:00:00Z and
 * 9999-12-31T23:59:59Z). The {@code nanos} value must be in the range [0, +999,999,999].
 *
 * <p><b>Note:</b> Negative second values with fractional seconds must still have non-negative
 * nanos values that count forward in time.
 */
public static boolean isValid(Timestamp timestamp) {
 return isValid(timestamp.getSeconds(), timestamp.getNanos());
}

代码示例来源:origin: gojektech/feast

public static Timestamp maxTimestamp(Timestamp a, Timestamp b) {
 if (a.getSeconds() != b.getSeconds()) {
  return a.getSeconds() < b.getSeconds() ? b : a;
 } else {
  return a.getNanos() < b.getNanos() ? b : a;
 }
}

代码示例来源:origin: com.google.cloud/google-cloud-core

/** Creates an instance of Timestamp from {@code com.google.protobuf.Timestamp}. */
public static Timestamp fromProto(com.google.protobuf.Timestamp proto) {
 return new Timestamp(proto.getSeconds(), proto.getNanos());
}

代码示例来源:origin: com.google.cloud/google-cloud-firestore

private static int compareTimestamps(Value left, Value right) {
 int cmp =
   Long.compare(left.getTimestampValue().getSeconds(), right.getTimestampValue().getSeconds());
 if (cmp != 0) {
  return cmp;
 } else {
  return Integer.compare(
    left.getTimestampValue().getNanos(), right.getTimestampValue().getNanos());
 }
}

代码示例来源:origin: com.google.protobuf/protobuf-java-util

/** Calculate the difference between two timestamps. */
public static Duration between(Timestamp from, Timestamp to) {
 checkValid(from);
 checkValid(to);
 return Durations.normalizedDuration(
   checkedSubtract(to.getSeconds(), from.getSeconds()),
   checkedSubtract(to.getNanos(), from.getNanos()));
}

代码示例来源:origin: com.google.protobuf/protobuf-java-util

/**
 * Convert a Timestamp to the number of microseconds elapsed from the epoch.
 *
 * <p>The result will be rounded down to the nearest microsecond. E.g., if the timestamp
 * represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 microsecond.
 */
public static long toMicros(Timestamp timestamp) {
 checkValid(timestamp);
 return checkedAdd(
   checkedMultiply(timestamp.getSeconds(), MICROS_PER_SECOND),
   timestamp.getNanos() / NANOS_PER_MICROSECOND);
}

代码示例来源:origin: com.google.protobuf/protobuf-java-util

/**
 * Convert a Timestamp to the number of milliseconds elapsed from the epoch.
 *
 * <p>The result will be rounded down to the nearest millisecond. E.g., if the timestamp
 * represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 millisecond.
 */
public static long toMillis(Timestamp timestamp) {
 checkValid(timestamp);
 return checkedAdd(
   checkedMultiply(timestamp.getSeconds(), MILLIS_PER_SECOND),
   timestamp.getNanos() / NANOS_PER_MILLISECOND);
}

代码示例来源:origin: com.google.protobuf/protobuf-java-util

/** Convert a Timestamp to the number of nanoseconds elapsed from the epoch. */
public static long toNanos(Timestamp timestamp) {
 checkValid(timestamp);
 return checkedAdd(
   checkedMultiply(timestamp.getSeconds(), NANOS_PER_SECOND), timestamp.getNanos());
}

代码示例来源:origin: hyperledger/fabric-chaincode-java

KeyModificationImpl(KvQueryResult.KeyModification km) {
  this.txId = km.getTxId();
  this.value = km.getValue();
  this.timestamp = Instant.ofEpochSecond(km.getTimestamp().getSeconds(), km.getTimestamp().getNanos());
  this.deleted = km.getIsDelete();
}

代码示例来源:origin: com.google.protobuf/protobuf-java-util

/** Subtract a duration from a timestamp. */
public static Timestamp subtract(Timestamp start, Duration length) {
 checkValid(start);
 Durations.checkValid(length);
 return normalizedTimestamp(
   checkedSubtract(start.getSeconds(), length.getSeconds()),
   checkedSubtract(start.getNanos(), length.getNanos()));
}

代码示例来源:origin: com.google.protobuf/protobuf-java-util

/** Add a duration to a timestamp. */
public static Timestamp add(Timestamp start, Duration length) {
 checkValid(start);
 Durations.checkValid(length);
 return normalizedTimestamp(
   checkedAdd(start.getSeconds(), length.getSeconds()),
   checkedAdd(start.getNanos(), length.getNanos()));
}

相关文章