Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/debug/relativetimeprovider.js
4523 views
1
/**
2
* @license
3
* Copyright The Closure Library Authors.
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
/**
8
* @fileoverview Definition the goog.debug.RelativeTimeProvider class.
9
*/
10
11
goog.provide('goog.debug.RelativeTimeProvider');
12
13
14
15
/**
16
* A simple object to keep track of a timestamp considered the start of
17
* something. The main use is for the logger system to maintain a start time
18
* that is occasionally reset. For example, in Gmail, we reset this relative
19
* time at the start of a user action so that timings are offset from the
20
* beginning of the action. This class also provides a singleton as the default
21
* behavior for most use cases is to share the same start time.
22
*
23
* @constructor
24
* @final
25
*/
26
goog.debug.RelativeTimeProvider = function() {
27
'use strict';
28
/**
29
* The start time.
30
* @type {number}
31
* @private
32
*/
33
this.relativeTimeStart_ = goog.now();
34
};
35
36
37
/**
38
* Default instance.
39
* @type {?goog.debug.RelativeTimeProvider}
40
* @private
41
*/
42
goog.debug.RelativeTimeProvider.defaultInstance_ = null;
43
44
45
/**
46
* Sets the start time to the specified time.
47
* @param {number} timeStamp The start time.
48
*/
49
goog.debug.RelativeTimeProvider.prototype.set = function(timeStamp) {
50
'use strict';
51
this.relativeTimeStart_ = timeStamp;
52
};
53
54
55
/**
56
* Resets the start time to now.
57
*/
58
goog.debug.RelativeTimeProvider.prototype.reset = function() {
59
'use strict';
60
this.set(goog.now());
61
};
62
63
64
/**
65
* @return {number} The start time.
66
*/
67
goog.debug.RelativeTimeProvider.prototype.get = function() {
68
'use strict';
69
return this.relativeTimeStart_;
70
};
71
72
73
/**
74
* @return {!goog.debug.RelativeTimeProvider} The default instance.
75
*/
76
goog.debug.RelativeTimeProvider.getDefaultInstance = function() {
77
'use strict';
78
if (!goog.debug.RelativeTimeProvider.defaultInstance_) {
79
goog.debug.RelativeTimeProvider.defaultInstance_ =
80
new goog.debug.RelativeTimeProvider();
81
}
82
return goog.debug.RelativeTimeProvider.defaultInstance_;
83
};
84
85