Path: blob/trunk/third_party/closure/goog/debug/relativetimeprovider.js
4523 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview Definition the goog.debug.RelativeTimeProvider class.8*/910goog.provide('goog.debug.RelativeTimeProvider');11121314/**15* A simple object to keep track of a timestamp considered the start of16* something. The main use is for the logger system to maintain a start time17* that is occasionally reset. For example, in Gmail, we reset this relative18* time at the start of a user action so that timings are offset from the19* beginning of the action. This class also provides a singleton as the default20* behavior for most use cases is to share the same start time.21*22* @constructor23* @final24*/25goog.debug.RelativeTimeProvider = function() {26'use strict';27/**28* The start time.29* @type {number}30* @private31*/32this.relativeTimeStart_ = goog.now();33};343536/**37* Default instance.38* @type {?goog.debug.RelativeTimeProvider}39* @private40*/41goog.debug.RelativeTimeProvider.defaultInstance_ = null;424344/**45* Sets the start time to the specified time.46* @param {number} timeStamp The start time.47*/48goog.debug.RelativeTimeProvider.prototype.set = function(timeStamp) {49'use strict';50this.relativeTimeStart_ = timeStamp;51};525354/**55* Resets the start time to now.56*/57goog.debug.RelativeTimeProvider.prototype.reset = function() {58'use strict';59this.set(goog.now());60};616263/**64* @return {number} The start time.65*/66goog.debug.RelativeTimeProvider.prototype.get = function() {67'use strict';68return this.relativeTimeStart_;69};707172/**73* @return {!goog.debug.RelativeTimeProvider} The default instance.74*/75goog.debug.RelativeTimeProvider.getDefaultInstance = function() {76'use strict';77if (!goog.debug.RelativeTimeProvider.defaultInstance_) {78goog.debug.RelativeTimeProvider.defaultInstance_ =79new goog.debug.RelativeTimeProvider();80}81return goog.debug.RelativeTimeProvider.defaultInstance_;82};838485