Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 7f0beec

Browse files
luanamartinssantossilva-fabio
authored andcommitted
refactor: apply code guidelines rules to clock.ts file
1 parent 528be79 commit 7f0beec

1 file changed

Lines changed: 45 additions & 54 deletions

File tree

  • packages/opencensus-core/src/internal

packages/opencensus-core/src/internal/clock.ts

Lines changed: 45 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,67 +15,58 @@
1515
*/
1616

1717
export class Clock {
18-
private _ended: boolean;
19-
private _startTime: Date;
20-
private _hrtime: [number, number];
21-
private diff: [number,number];
18+
private endedLocal: boolean;
19+
private startTimeLocal: Date;
20+
private hrtimeLocal: [number, number];
21+
private diff: [number, number];
2222

23-
constructor() {
24-
this._ended = false
25-
this._startTime = new Date()
26-
this._hrtime = process.hrtime()
27-
this.diff = null
28-
}
23+
constructor() {
24+
this.endedLocal = false;
25+
this.startTimeLocal = new Date();
26+
this.hrtimeLocal = process.hrtime();
27+
this.diff = null;
28+
}
2929

30-
public end(): void {
31-
if (this._ended){
32-
return
33-
}
34-
this.diff = process.hrtime(this._hrtime)
35-
this._ended = true
36-
}
37-
38-
public get duration(): number {
39-
if (!this._ended){
40-
return null
41-
}
42-
var ns = this.diff[0] * 1e9 + this.diff[1]
43-
return ns / 1e6
44-
}
45-
46-
public offset(timer: Clock): number {
47-
var a = timer.hrtime
48-
var b = this.hrtime
49-
var ns = (b[0] - a[0]) * 1e9 + (b[1] - a[1])
50-
return ns / 1e6
30+
end(): void {
31+
if (this.endedLocal) {
32+
return;
5133
}
34+
this.diff = process.hrtime(this.hrtimeLocal);
35+
this.endedLocal = true;
36+
}
5237

53-
public get hrtime() : [number, number] {
54-
return this._hrtime;
55-
}
56-
57-
public get startTime(): Date {
58-
return this._startTime;
38+
get duration(): number {
39+
if (!this.endedLocal) {
40+
return null;
5941
}
60-
61-
public get endTime(): Date {
62-
let result: Date = null;
63-
if(this.ended) {
64-
result= new Date(this.startTime.getTime() + this.duration);
65-
}
66-
return result;
67-
}
68-
69-
public get ended(): boolean {
70-
return this._ended;
71-
}
72-
73-
}
74-
75-
76-
42+
const ns = this.diff[0] * 1e9 + this.diff[1];
43+
return ns / 1e6;
44+
}
7745

46+
offset(timer: Clock): number {
47+
const a = timer.hrtime;
48+
const b = this.hrtime;
49+
const ns = (b[0] - a[0]) * 1e9 + (b[1] - a[1]);
50+
return ns / 1e6;
51+
}
7852

53+
get hrtime(): [number, number] {
54+
return this.hrtimeLocal;
55+
}
7956

57+
get startTime(): Date {
58+
return this.startTimeLocal;
59+
}
8060

61+
get endTime(): Date {
62+
let result: Date = null;
63+
if (this.ended) {
64+
result = new Date(this.startTime.getTime() + this.duration);
65+
}
66+
return result;
67+
}
8168

69+
get ended(): boolean {
70+
return this.endedLocal;
71+
}
72+
}

0 commit comments

Comments
 (0)