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

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

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

Timestamp.getSeconds介绍

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

代码示例

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

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

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

  1. private static Date toDate(Timestamp timestamp) {
  2. return Date.from(
  3. Instant.ofEpochMilli(
  4. timestamp.getSeconds() * MILLIS_PER_SECOND
  5. + timestamp.getNanos() / NANOS_PER_MILLISECOND));
  6. }

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

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

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

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

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

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

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

  1. /**
  2. * Returns a {@link Duration} calculated as: {@code this - timestamp}.
  3. *
  4. * @param timestamp the {@code Timestamp} to subtract.
  5. * @return the calculated {@code Duration}. For invalid inputs, a {@code Duration} of zero is
  6. * returned.
  7. * @since 0.5
  8. */
  9. public Duration subtractTimestamp(Timestamp timestamp) {
  10. long durationSeconds = getSeconds() - timestamp.getSeconds();
  11. int durationNanos = getNanos() - timestamp.getNanos();
  12. if (durationSeconds < 0 && durationNanos > 0) {
  13. durationSeconds += 1;
  14. durationNanos = (int) (durationNanos - NANOS_PER_SECOND);
  15. } else if (durationSeconds > 0 && durationNanos < 0) {
  16. durationSeconds -= 1;
  17. durationNanos = (int) (durationNanos + NANOS_PER_SECOND);
  18. }
  19. return Duration.create(durationSeconds, durationNanos);
  20. }

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

  1. /**
  2. * Returns a {@link Duration} calculated as: {@code this - timestamp}.
  3. *
  4. * @param timestamp the {@code Timestamp} to subtract.
  5. * @return the calculated {@code Duration}. For invalid inputs, a {@code Duration} of zero is
  6. * returned.
  7. */
  8. public Duration subtractTimestamp(Timestamp timestamp) {
  9. long durationSeconds = getSeconds() - timestamp.getSeconds();
  10. int durationNanos = getNanos() - timestamp.getNanos();
  11. if (durationSeconds < 0 && durationNanos > 0) {
  12. durationSeconds += 1;
  13. durationNanos = (int) (durationNanos - NANOS_PER_SECOND);
  14. } else if (durationSeconds > 0 && durationNanos < 0) {
  15. durationSeconds -= 1;
  16. durationNanos = (int) (durationNanos + NANOS_PER_SECOND);
  17. }
  18. return Duration.create(durationSeconds, durationNanos);
  19. }

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

  1. /**
  2. * Compares this {@code Timestamp} to the specified {@code Timestamp}.
  3. *
  4. * @param otherTimestamp the other {@code Timestamp} to compare to, not {@code null}.
  5. * @return the comparator value: zero if equal, negative if this timestamp happens before
  6. * otherTimestamp, positive if after.
  7. * @throws NullPointerException if otherTimestamp is {@code null}.
  8. */
  9. @Override
  10. public int compareTo(Timestamp otherTimestamp) {
  11. int cmp = Longs.compare(getSeconds(), otherTimestamp.getSeconds());
  12. if (cmp != 0) {
  13. return cmp;
  14. }
  15. return Longs.compare(getNanos(), otherTimestamp.getNanos());
  16. }

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

  1. /**
  2. * Compares this {@code Timestamp} to the specified {@code Timestamp}.
  3. *
  4. * @param otherTimestamp the other {@code Timestamp} to compare to, not {@code null}.
  5. * @return the comparator value: zero if equal, negative if this timestamp happens before
  6. * otherTimestamp, positive if after.
  7. * @throws NullPointerException if otherTimestamp is {@code null}.
  8. */
  9. @Override
  10. public int compareTo(Timestamp otherTimestamp) {
  11. int cmp = TimeUtils.compareLongs(getSeconds(), otherTimestamp.getSeconds());
  12. if (cmp != 0) {
  13. return cmp;
  14. }
  15. return TimeUtils.compareLongs(getNanos(), otherTimestamp.getNanos());
  16. }

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

  1. @VisibleForTesting
  2. static Timestamp convertTimestamp(io.opencensus.common.Timestamp censusTimestamp) {
  3. if (censusTimestamp.getSeconds() < 0) {
  4. // StackDriver doesn't handle negative timestamps.
  5. return Timestamp.newBuilder().build();
  6. }
  7. return Timestamp.newBuilder()
  8. .setSeconds(censusTimestamp.getSeconds())
  9. .setNanos(censusTimestamp.getNanos())
  10. .build();
  11. }

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

  1. private static long getNanos(Timestamp time) {
  2. return LongMath.checkedAdd(
  3. LongMath.checkedMultiply(time.getSeconds(), NUM_NANOS_PER_SECOND), time.getNanos());
  4. }
  5. }

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

  1. private static long getNanos(Timestamp time) {
  2. return LongMath.checkedAdd(
  3. LongMath.checkedMultiply(time.getSeconds(), NUM_NANOS_PER_SECOND), time.getNanos());
  4. }
  5. }

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

  1. private Timestamp plus(long secondsToAdd, long nanosToAdd) {
  2. if ((secondsToAdd | nanosToAdd) == 0) {
  3. return this;
  4. }
  5. long epochSec = LongMath.checkedAdd(getSeconds(), secondsToAdd);
  6. epochSec = LongMath.checkedAdd(epochSec, nanosToAdd / NANOS_PER_SECOND);
  7. nanosToAdd = nanosToAdd % NANOS_PER_SECOND;
  8. long nanoAdjustment = getNanos() + nanosToAdd; // safe int + NANOS_PER_SECOND
  9. return ofEpochSecond(epochSec, nanoAdjustment);
  10. }

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

  1. private Timestamp plus(long secondsToAdd, long nanosToAdd) {
  2. if ((secondsToAdd | nanosToAdd) == 0) {
  3. return this;
  4. }
  5. long epochSec = TimeUtils.checkedAdd(getSeconds(), secondsToAdd);
  6. epochSec = TimeUtils.checkedAdd(epochSec, nanosToAdd / NANOS_PER_SECOND);
  7. nanosToAdd = nanosToAdd % NANOS_PER_SECOND;
  8. long nanoAdjustment = getNanos() + nanosToAdd; // safe int + NANOS_PER_SECOND
  9. return ofEpochSecond(epochSec, nanoAdjustment);
  10. }

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

  1. private static com.google.protobuf.Timestamp toTimestampProto(Timestamp timestamp) {
  2. return com.google.protobuf.Timestamp.newBuilder()
  3. .setSeconds(timestamp.getSeconds())
  4. .setNanos(timestamp.getNanos())
  5. .build();
  6. }

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

  1. static com.google.protobuf.Timestamp toTimestampProto(Timestamp timestamp) {
  2. return com.google.protobuf.Timestamp.newBuilder()
  3. .setSeconds(timestamp.getSeconds())
  4. .setNanos(timestamp.getNanos())
  5. .build();
  6. }

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

  1. static com.google.protobuf.Timestamp toTimestampProto(Timestamp timestamp) {
  2. return com.google.protobuf.Timestamp.newBuilder()
  3. .setSeconds(timestamp.getSeconds())
  4. .setNanos(timestamp.getNanos())
  5. .build();
  6. }

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

  1. private static com.google.protobuf.Timestamp toTimestampProto(Timestamp timestamp) {
  2. return com.google.protobuf.Timestamp.newBuilder()
  3. .setSeconds(timestamp.getSeconds())
  4. .setNanos(timestamp.getNanos())
  5. .build();
  6. }

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

  1. @Test
  2. public void timestampCreate() {
  3. assertThat(Timestamp.create(24, 42).getSeconds()).isEqualTo(24);
  4. assertThat(Timestamp.create(24, 42).getNanos()).isEqualTo(42);
  5. assertThat(Timestamp.create(-24, 42).getSeconds()).isEqualTo(-24);
  6. assertThat(Timestamp.create(-24, 42).getNanos()).isEqualTo(42);
  7. assertThat(Timestamp.create(315576000000L, 999999999).getSeconds()).isEqualTo(315576000000L);
  8. assertThat(Timestamp.create(315576000000L, 999999999).getNanos()).isEqualTo(999999999);
  9. assertThat(Timestamp.create(-315576000000L, 999999999).getSeconds()).isEqualTo(-315576000000L);
  10. assertThat(Timestamp.create(-315576000000L, 999999999).getNanos()).isEqualTo(999999999);
  11. }

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

  1. @SuppressWarnings("deprecation")
  2. private static void emitSingleSpan(Formatter formatter, SpanData span) {
  3. Calendar calendar = Calendar.getInstance();
  4. calendar.setTimeInMillis(TimeUnit.SECONDS.toMillis(span.getStartTimestamp().getSeconds()));
  5. long microsField = TimeUnit.NANOSECONDS.toMicros(span.getStartTimestamp().getNanos());
  6. String elapsedSecondsStr =
  7. TimeUnit.SECONDS.toMillis(event.getTimestamp().getSeconds())
  8. + TimeUnit.NANOSECONDS.toMillis(event.getTimestamp().getNanos()));
  9. microsField = TimeUnit.NANOSECONDS.toMicros(event.getTimestamp().getNanos());

相关文章