Package io.sentry

Class SentryNanotimeDate

java.lang.Object
io.sentry.SentryDate
io.sentry.SentryNanotimeDate
All Implemented Interfaces:
Comparable<SentryDate>

public final class SentryNanotimeDate extends SentryDate
Uses Date in cominbation with System.nanoTime().

A single date only offers millisecond precision but diff can be calculated with up to nanosecond precision. This increased precision can also be used to calculate a new end date for a transaction where start date is sent with ms precision and end date is added to it with ns precision leading to an end timestamp with ns precision that can be used to gain ns precision transaction durations.

This is a workaround for older versions of Java (before 9) and Android API (lower than 26) that allows for higher precision than Date alone would.

  • Constructor Details

    • SentryNanotimeDate

      public SentryNanotimeDate()
    • SentryNanotimeDate

      public SentryNanotimeDate(@NotNull @NotNull Date date, long nanos)
  • Method Details

    • diff

      public long diff(@NotNull @NotNull SentryDate otherDate)
      Description copied from class: SentryDate
      Difference between two dates in nanoseconds.
      Overrides:
      diff in class SentryDate
      Parameters:
      otherDate - another SentryDate
      Returns:
      difference in nanoseconds
    • nanoTimestamp

      public long nanoTimestamp()
      Description copied from class: SentryDate
      Returns the date in nanoseconds as long.
      Specified by:
      nanoTimestamp in class SentryDate
    • laterDateNanosTimestampByDiff

      public long laterDateNanosTimestampByDiff(@Nullable @Nullable SentryDate otherDate)
      Description copied from class: SentryDate
      Calculates a date by using another date.

      This is a workaround for limited precision offered in some cases (e.g. when using SentryNanotimeDate). This makes it possible to have high precision duration by using nanoseconds for the finish timestamp where normally the start and finish timestamps would only offer millisecond precision.

      Overrides:
      laterDateNanosTimestampByDiff in class SentryDate
      Parameters:
      otherDate - another SentryDate
      Returns:
      date in seconds as long
    • compareTo

      public int compareTo(@NotNull @NotNull SentryDate otherDate)
      Specified by:
      compareTo in interface Comparable<SentryDate>
      Overrides:
      compareTo in class SentryDate