@datadog/mobile-react-native
Version:
A client-side React Native module to interact with Datadog
38 lines (35 loc) • 1.2 kB
JavaScript
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/
/**
* A Timestamp structure holding the
*/
/**
* Simple class providing timestamps in milliseconds.
* If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
*/
export class TimeProvider {
/** Keeps an average offset between the unix time and the provided timestamp. */
constructor() {
const timestamp = this.getTimestamp();
if (timestamp.reactNative == null) {
this.baseOffset = 0;
} else {
this.baseOffset = timestamp.unix - timestamp.reactNative;
}
}
now() {
const timestamp = this.getTimestamp();
if (timestamp.reactNative != null && this.baseOffset === 0) {
this.baseOffset = timestamp.unix - timestamp.reactNative;
}
if (timestamp.reactNative == null || this.baseOffset === 0) {
return timestamp.unix;
} else {
return this.baseOffset + timestamp.reactNative;
}
}
}
//# sourceMappingURL=TimeProvider.js.map