@datadog/mobile-react-native
Version:
A client-side React Native module to interact with Datadog
45 lines (41 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TimeProvider = void 0;
/*
* 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.
*/
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;
}
}
}
exports.TimeProvider = TimeProvider;
//# sourceMappingURL=TimeProvider.js.map