io.opencensus.common.Timestamp.getNanos()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(118)

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

Timestamp.getNanos介绍

[英]Returns the number of nanoseconds after the number of seconds since the Unix Epoch represented by this timestamp.
[中]返回自此时间戳表示的Unix历元起的秒数之后的纳秒数。

代码示例

代码示例来源:origin: census-instrumentation/opencensus-java

private static long timestampToMicros(final @Nullable Timestamp timestamp) {
 return (timestamp == null)
   ? 0L
   : SECONDS.toMicros(timestamp.getSeconds()) + NANOSECONDS.toMicros(timestamp.getNanos());
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static Date toDate(Timestamp timestamp) {
 return Date.from(
   Instant.ofEpochMilli(
     timestamp.getSeconds() * MILLIS_PER_SECOND
       + timestamp.getNanos() / NANOS_PER_MILLISECOND));
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static long toEpochMicros(Timestamp timestamp) {
 return SECONDS.toMicros(timestamp.getSeconds()) + NANOSECONDS.toMicros(timestamp.getNanos());
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static long timestampToNanos(final Timestamp timestamp) {
 return TimeUnit.SECONDS.toNanos(timestamp.getSeconds()) + timestamp.getNanos();
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static long toMillis(Timestamp timestamp) {
 return SECONDS.toMillis(timestamp.getSeconds()) + NANOSECONDS.toMillis(timestamp.getNanos());
}

代码示例来源:origin: census-instrumentation/opencensus-java

/**
 * Returns a {@link Duration} calculated as: {@code this - timestamp}.
 *
 * @param timestamp the {@code Timestamp} to subtract.
 * @return the calculated {@code Duration}. For invalid inputs, a {@code Duration} of zero is
 *     returned.
 * @since 0.5
 */
public Duration subtractTimestamp(Timestamp timestamp) {
 long durationSeconds = getSeconds() - timestamp.getSeconds();
 int durationNanos = getNanos() - timestamp.getNanos();
 if (durationSeconds < 0 && durationNanos > 0) {
  durationSeconds += 1;
  durationNanos = (int) (durationNanos - NANOS_PER_SECOND);
 } else if (durationSeconds > 0 && durationNanos < 0) {
  durationSeconds -= 1;
  durationNanos = (int) (durationNanos + NANOS_PER_SECOND);
 }
 return Duration.create(durationSeconds, durationNanos);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Returns a {@link Duration} calculated as: {@code this - timestamp}.
 *
 * @param timestamp the {@code Timestamp} to subtract.
 * @return the calculated {@code Duration}. For invalid inputs, a {@code Duration} of zero is
 *     returned.
 */
public Duration subtractTimestamp(Timestamp timestamp) {
 long durationSeconds = getSeconds() - timestamp.getSeconds();
 int durationNanos = getNanos() - timestamp.getNanos();
 if (durationSeconds < 0 && durationNanos > 0) {
  durationSeconds += 1;
  durationNanos = (int) (durationNanos - NANOS_PER_SECOND);
 } else if (durationSeconds > 0 && durationNanos < 0) {
  durationSeconds -= 1;
  durationNanos = (int) (durationNanos + NANOS_PER_SECOND);
 }
 return Duration.create(durationSeconds, durationNanos);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Compares this {@code Timestamp} to the specified {@code Timestamp}.
 *
 * @param otherTimestamp the other {@code Timestamp} to compare to, not {@code null}.
 * @return the comparator value: zero if equal, negative if this timestamp happens before
 *     otherTimestamp, positive if after.
 * @throws NullPointerException if otherTimestamp is {@code null}.
 */
@Override
public int compareTo(Timestamp otherTimestamp) {
 int cmp = Longs.compare(getSeconds(), otherTimestamp.getSeconds());
 if (cmp != 0) {
  return cmp;
 }
 return Longs.compare(getNanos(), otherTimestamp.getNanos());
}

代码示例来源:origin: census-instrumentation/opencensus-java

/**
 * Compares this {@code Timestamp} to the specified {@code Timestamp}.
 *
 * @param otherTimestamp the other {@code Timestamp} to compare to, not {@code null}.
 * @return the comparator value: zero if equal, negative if this timestamp happens before
 *     otherTimestamp, positive if after.
 * @throws NullPointerException if otherTimestamp is {@code null}.
 */
@Override
public int compareTo(Timestamp otherTimestamp) {
 int cmp = TimeUtils.compareLongs(getSeconds(), otherTimestamp.getSeconds());
 if (cmp != 0) {
  return cmp;
 }
 return TimeUtils.compareLongs(getNanos(), otherTimestamp.getNanos());
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static long getNanos(Timestamp time) {
  return LongMath.checkedAdd(
    LongMath.checkedMultiply(time.getSeconds(), NUM_NANOS_PER_SECOND), time.getNanos());
 }
}

代码示例来源:origin: io.opencensus/opencensus-testing

private static long getNanos(Timestamp time) {
  return LongMath.checkedAdd(
    LongMath.checkedMultiply(time.getSeconds(), NUM_NANOS_PER_SECOND), time.getNanos());
 }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

private Timestamp plus(long secondsToAdd, long nanosToAdd) {
 if ((secondsToAdd | nanosToAdd) == 0) {
  return this;
 }
 long epochSec = LongMath.checkedAdd(getSeconds(), secondsToAdd);
 epochSec = LongMath.checkedAdd(epochSec, nanosToAdd / NANOS_PER_SECOND);
 nanosToAdd = nanosToAdd % NANOS_PER_SECOND;
 long nanoAdjustment = getNanos() + nanosToAdd; // safe int + NANOS_PER_SECOND
 return ofEpochSecond(epochSec, nanoAdjustment);
}

代码示例来源:origin: census-instrumentation/opencensus-java

private Timestamp plus(long secondsToAdd, long nanosToAdd) {
 if ((secondsToAdd | nanosToAdd) == 0) {
  return this;
 }
 long epochSec = TimeUtils.checkedAdd(getSeconds(), secondsToAdd);
 epochSec = TimeUtils.checkedAdd(epochSec, nanosToAdd / NANOS_PER_SECOND);
 nanosToAdd = nanosToAdd % NANOS_PER_SECOND;
 long nanoAdjustment = getNanos() + nanosToAdd; // safe int + NANOS_PER_SECOND
 return ofEpochSecond(epochSec, nanoAdjustment);
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static com.google.protobuf.Timestamp toTimestampProto(Timestamp timestamp) {
 return com.google.protobuf.Timestamp.newBuilder()
   .setSeconds(timestamp.getSeconds())
   .setNanos(timestamp.getNanos())
   .build();
}

代码示例来源:origin: census-instrumentation/opencensus-java

static com.google.protobuf.Timestamp toTimestampProto(Timestamp timestamp) {
 return com.google.protobuf.Timestamp.newBuilder()
   .setSeconds(timestamp.getSeconds())
   .setNanos(timestamp.getNanos())
   .build();
}

代码示例来源:origin: census-instrumentation/opencensus-java

static com.google.protobuf.Timestamp toTimestampProto(Timestamp timestamp) {
 return com.google.protobuf.Timestamp.newBuilder()
   .setSeconds(timestamp.getSeconds())
   .setNanos(timestamp.getNanos())
   .build();
}

代码示例来源:origin: io.opencensus/opencensus-exporter-trace-stackdriver

private static com.google.protobuf.Timestamp toTimestampProto(Timestamp timestamp) {
 return com.google.protobuf.Timestamp.newBuilder()
   .setSeconds(timestamp.getSeconds())
   .setNanos(timestamp.getNanos())
   .build();
}

代码示例来源:origin: census-instrumentation/opencensus-java

@VisibleForTesting
static Timestamp convertTimestamp(io.opencensus.common.Timestamp censusTimestamp) {
 if (censusTimestamp.getSeconds() < 0) {
  // StackDriver doesn't handle negative timestamps.
  return Timestamp.newBuilder().build();
 }
 return Timestamp.newBuilder()
   .setSeconds(censusTimestamp.getSeconds())
   .setNanos(censusTimestamp.getNanos())
   .build();
}

代码示例来源:origin: census-instrumentation/opencensus-java

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(TimeUnit.SECONDS.toMillis(span.getStartTimestamp().getSeconds()));
long microsField = TimeUnit.NANOSECONDS.toMicros(span.getStartTimestamp().getNanos());
String elapsedSecondsStr =
  span.getEndTimestamp() != null
     + TimeUnit.NANOSECONDS.toMillis(event.getTimestamp().getNanos()));
 microsField = TimeUnit.NANOSECONDS.toMicros(event.getTimestamp().getNanos());

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void timestampCreate() {
 assertThat(Timestamp.create(24, 42).getSeconds()).isEqualTo(24);
 assertThat(Timestamp.create(24, 42).getNanos()).isEqualTo(42);
 assertThat(Timestamp.create(-24, 42).getSeconds()).isEqualTo(-24);
 assertThat(Timestamp.create(-24, 42).getNanos()).isEqualTo(42);
 assertThat(Timestamp.create(315576000000L, 999999999).getSeconds()).isEqualTo(315576000000L);
 assertThat(Timestamp.create(315576000000L, 999999999).getNanos()).isEqualTo(999999999);
 assertThat(Timestamp.create(-315576000000L, 999999999).getSeconds()).isEqualTo(-315576000000L);
 assertThat(Timestamp.create(-315576000000L, 999999999).getNanos()).isEqualTo(999999999);
}

相关文章