Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/debug/relativetimeprovider.js
2868 views
1
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/**
16
* @fileoverview Definition the goog.debug.RelativeTimeProvider class.
17
*
18
*/
19
20
goog.provide('goog.debug.RelativeTimeProvider');
21
22
23
24
/**
25
* A simple object to keep track of a timestamp considered the start of
26
* something. The main use is for the logger system to maintain a start time
27
* that is occasionally reset. For example, in Gmail, we reset this relative
28
* time at the start of a user action so that timings are offset from the
29
* beginning of the action. This class also provides a singleton as the default
30
* behavior for most use cases is to share the same start time.
31
*
32
* @constructor
33
* @final
34
*/
35
goog.debug.RelativeTimeProvider = function() {
36
/**
37
* The start time.
38
* @type {number}
39
* @private
40
*/
41
this.relativeTimeStart_ = goog.now();
42
};
43
44
45
/**
46
* Default instance.
47
* @type {goog.debug.RelativeTimeProvider}
48
* @private
49
*/
50
goog.debug.RelativeTimeProvider.defaultInstance_ =
51
new goog.debug.RelativeTimeProvider();
52
53
54
/**
55
* Sets the start time to the specified time.
56
* @param {number} timeStamp The start time.
57
*/
58
goog.debug.RelativeTimeProvider.prototype.set = function(timeStamp) {
59
this.relativeTimeStart_ = timeStamp;
60
};
61
62
63
/**
64
* Resets the start time to now.
65
*/
66
goog.debug.RelativeTimeProvider.prototype.reset = function() {
67
this.set(goog.now());
68
};
69
70
71
/**
72
* @return {number} The start time.
73
*/
74
goog.debug.RelativeTimeProvider.prototype.get = function() {
75
return this.relativeTimeStart_;
76
};
77
78
79
/**
80
* @return {goog.debug.RelativeTimeProvider} The default instance.
81
*/
82
goog.debug.RelativeTimeProvider.getDefaultInstance = function() {
83
return goog.debug.RelativeTimeProvider.defaultInstance_;
84
};
85
86