Path: blob/trunk/third_party/closure/goog/debug/relativetimeprovider.js
2868 views
// Copyright 2007 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Definition the goog.debug.RelativeTimeProvider class.16*17*/1819goog.provide('goog.debug.RelativeTimeProvider');20212223/**24* A simple object to keep track of a timestamp considered the start of25* something. The main use is for the logger system to maintain a start time26* that is occasionally reset. For example, in Gmail, we reset this relative27* time at the start of a user action so that timings are offset from the28* beginning of the action. This class also provides a singleton as the default29* behavior for most use cases is to share the same start time.30*31* @constructor32* @final33*/34goog.debug.RelativeTimeProvider = function() {35/**36* The start time.37* @type {number}38* @private39*/40this.relativeTimeStart_ = goog.now();41};424344/**45* Default instance.46* @type {goog.debug.RelativeTimeProvider}47* @private48*/49goog.debug.RelativeTimeProvider.defaultInstance_ =50new goog.debug.RelativeTimeProvider();515253/**54* Sets the start time to the specified time.55* @param {number} timeStamp The start time.56*/57goog.debug.RelativeTimeProvider.prototype.set = function(timeStamp) {58this.relativeTimeStart_ = timeStamp;59};606162/**63* Resets the start time to now.64*/65goog.debug.RelativeTimeProvider.prototype.reset = function() {66this.set(goog.now());67};686970/**71* @return {number} The start time.72*/73goog.debug.RelativeTimeProvider.prototype.get = function() {74return this.relativeTimeStart_;75};767778/**79* @return {goog.debug.RelativeTimeProvider} The default instance.80*/81goog.debug.RelativeTimeProvider.getDefaultInstance = function() {82return goog.debug.RelativeTimeProvider.defaultInstance_;83};848586