Skip to content

Commit 61bb7b9

Browse files
Tchoupinaxtargos
authored andcommitted
lib: replace Date.now function by primordial DateNow
PR-URL: #30689 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
1 parent 67de744 commit 61bb7b9

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/internal/fs/utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {
44
ArrayIsArray,
5+
DateNow,
56
ObjectSetPrototypeOf,
67
ReflectOwnKeys,
78
} = primordials;
@@ -487,7 +488,7 @@ function toUnixTimestamp(time, name = 'time') {
487488
}
488489
if (Number.isFinite(time)) {
489490
if (time < 0) {
490-
return Date.now() / 1000;
491+
return DateNow() / 1000;
491492
}
492493
return time;
493494
}

lib/readline.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'use strict';
2929

3030
const {
31+
DateNow,
3132
MathCeil,
3233
MathFloor,
3334
MathMax,
@@ -438,7 +439,7 @@ Interface.prototype._normalWrite = function(b) {
438439
}
439440
let string = this._decoder.write(b);
440441
if (this._sawReturnAt &&
441-
Date.now() - this._sawReturnAt <= this.crlfDelay) {
442+
DateNow() - this._sawReturnAt <= this.crlfDelay) {
442443
string = string.replace(/^\n/, '');
443444
this._sawReturnAt = 0;
444445
}
@@ -451,7 +452,7 @@ Interface.prototype._normalWrite = function(b) {
451452
this._line_buffer = null;
452453
}
453454
if (newPartContainsEnding) {
454-
this._sawReturnAt = string.endsWith('\r') ? Date.now() : 0;
455+
this._sawReturnAt = string.endsWith('\r') ? DateNow() : 0;
455456

456457
// Got one or more newlines; process into "line" events
457458
const lines = string.split(lineEnding);
@@ -834,14 +835,14 @@ function _ttyWriteDumb(s, key) {
834835

835836
switch (key.name) {
836837
case 'return': // Carriage return, i.e. \r
837-
this._sawReturnAt = Date.now();
838+
this._sawReturnAt = DateNow();
838839
this._line();
839840
break;
840841

841842
case 'enter':
842843
// When key interval > crlfDelay
843844
if (this._sawReturnAt === 0 ||
844-
Date.now() - this._sawReturnAt > this.crlfDelay) {
845+
DateNow() - this._sawReturnAt > this.crlfDelay) {
845846
this._line();
846847
}
847848
this._sawReturnAt = 0;
@@ -1015,14 +1016,14 @@ Interface.prototype._ttyWrite = function(s, key) {
10151016

10161017
switch (key.name) {
10171018
case 'return': // Carriage return, i.e. \r
1018-
this._sawReturnAt = Date.now();
1019+
this._sawReturnAt = DateNow();
10191020
this._line();
10201021
break;
10211022

10221023
case 'enter':
10231024
// When key interval > crlfDelay
10241025
if (this._sawReturnAt === 0 ||
1025-
Date.now() - this._sawReturnAt > this.crlfDelay) {
1026+
DateNow() - this._sawReturnAt > this.crlfDelay) {
10261027
this._line();
10271028
}
10281029
this._sawReturnAt = 0;

0 commit comments

Comments
 (0)