-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
46 lines (36 loc) · 1 KB
/
utils.js
File metadata and controls
46 lines (36 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const { DateTime } = require('luxon');
class Utils {
static currentMskDateTime() {
return DateTime.local().setZone("Europe/Moscow");
}
static currentMskDate() {
return Utils.currentMskDateTime().toISO().slice(0, 10);
}
static defaultDate() {
return Utils.currentMskDate();
}
/**
* @param {string} dt - Datetime string in ISO format
*/
static getTimeDifferenceFromNow(dt) {
return DateTime.fromISO(dt).toMillis() - Date.now();
}
static binarySearchPositiveMinIdx(array, estimatorFunc) {
let startIdx = 0;
let endIdx = array.length - 1;
let min = -1;
let idx;
while (startIdx <= endIdx) {
idx = Math.floor((startIdx + endIdx) / 2);
if (estimatorFunc(array[idx]) < 0) {
startIdx = idx + 1;
}
else {
min = idx;
endIdx = idx - 1;
}
}
return min;
}
}
module.exports = Utils;