Class SentryNanotimeDate
- All Implemented Interfaces:
Comparable<SentryDate>
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(@NotNull SentryDate otherDate) long
diff
(@NotNull SentryDate otherDate) Difference between two dates in nanoseconds.long
laterDateNanosTimestampByDiff
(@Nullable SentryDate otherDate) Calculates a date by using another date.long
Returns the date in nanoseconds as long.Methods inherited from class io.sentry.SentryDate
isAfter, isBefore
-
Constructor Details
-
SentryNanotimeDate
public SentryNanotimeDate() -
SentryNanotimeDate
-
-
Method Details
-
diff
Description copied from class:SentryDate
Difference between two dates in nanoseconds.- Overrides:
diff
in classSentryDate
- Parameters:
otherDate
- anotherSentryDate
- Returns:
- difference in nanoseconds
-
nanoTimestamp
public long nanoTimestamp()Description copied from class:SentryDate
Returns the date in nanoseconds as long.- Specified by:
nanoTimestamp
in classSentryDate
-
laterDateNanosTimestampByDiff
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 classSentryDate
- Parameters:
otherDate
- anotherSentryDate
- Returns:
- date in seconds as long
-
compareTo
- Specified by:
compareTo
in interfaceComparable<SentryDate>
- Overrides:
compareTo
in classSentryDate
-