@zelgadis87/utils-core 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/async/CancelableDeferred.d.ts +1 -1
- package/dist/async/Deferred.d.ts +7 -2
- package/dist/async/Semaphore.d.ts +5 -1
- package/dist/time/TimeInstant.d.ts +63 -36
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/empties.d.ts +17 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/json.d.ts +1 -0
- package/dist/types/records.d.ts +6 -0
- package/esbuild/index.cjs +427 -280
- package/esbuild/index.mjs +439 -280
- package/package.json +4 -1
- package/src/time/TimeDuration.ts +5 -3
- package/src/time/TimeInstant.ts +84 -208
- package/src/time/TimeInstantBuilder.ts +3 -3
- package/src/types/json.ts +10 -0
- package/src/types/records.ts +6 -1
package/esbuild/index.cjs
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
6
11
|
var __export = (target, all) => {
|
|
7
12
|
for (var name in all)
|
|
8
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -15,8 +20,154 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
18
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
32
|
|
|
33
|
+
// ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js
|
|
34
|
+
var require_format = __commonJS({
|
|
35
|
+
"../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js"(exports2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
Object.defineProperty(exports2, "__esModule", {
|
|
38
|
+
value: true
|
|
39
|
+
});
|
|
40
|
+
exports2["default"] = format2;
|
|
41
|
+
function ownKeys(object, enumerableOnly) {
|
|
42
|
+
var keys = Object.keys(object);
|
|
43
|
+
if (Object.getOwnPropertySymbols) {
|
|
44
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
45
|
+
if (enumerableOnly) {
|
|
46
|
+
symbols = symbols.filter(function(sym) {
|
|
47
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
keys.push.apply(keys, symbols);
|
|
51
|
+
}
|
|
52
|
+
return keys;
|
|
53
|
+
}
|
|
54
|
+
function _objectSpread(target) {
|
|
55
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
56
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
57
|
+
if (i % 2) {
|
|
58
|
+
ownKeys(Object(source), true).forEach(function(key) {
|
|
59
|
+
_defineProperty(target, key, source[key]);
|
|
60
|
+
});
|
|
61
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
|
62
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
63
|
+
} else {
|
|
64
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
65
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return target;
|
|
70
|
+
}
|
|
71
|
+
function _defineProperty(obj, key, value) {
|
|
72
|
+
if (key in obj) {
|
|
73
|
+
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
74
|
+
} else {
|
|
75
|
+
obj[key] = value;
|
|
76
|
+
}
|
|
77
|
+
return obj;
|
|
78
|
+
}
|
|
79
|
+
var PATTERN_REGEX = /(M|y|d|D|h|H|m|s|S|G|Z|P|a)+/g;
|
|
80
|
+
var ESCAPE_REGEX = /\\"|"((?:\\"|[^"])*)"|(\+)/g;
|
|
81
|
+
var optionNames = {
|
|
82
|
+
y: "year",
|
|
83
|
+
M: "month",
|
|
84
|
+
d: "day",
|
|
85
|
+
D: "weekday",
|
|
86
|
+
S: "fractionalSecondDigits",
|
|
87
|
+
G: "era",
|
|
88
|
+
Z: "timeZoneName",
|
|
89
|
+
P: "dayPeriod",
|
|
90
|
+
a: "hour12",
|
|
91
|
+
h: "hour",
|
|
92
|
+
H: "hour",
|
|
93
|
+
m: "minute",
|
|
94
|
+
s: "second"
|
|
95
|
+
};
|
|
96
|
+
var values = {
|
|
97
|
+
y: ["numeric", "2-digit", void 0, "numeric"],
|
|
98
|
+
M: ["narrow", "2-digit", "short", "long"],
|
|
99
|
+
d: ["numeric", "2-digit"],
|
|
100
|
+
D: ["narrow", "short", "long"],
|
|
101
|
+
S: [1, 2, 3],
|
|
102
|
+
G: ["narrow", "short", "long"],
|
|
103
|
+
Z: ["short", "long"],
|
|
104
|
+
P: ["narrow", "short", "long"],
|
|
105
|
+
a: [true],
|
|
106
|
+
h: ["numeric", "2-digit"],
|
|
107
|
+
H: ["numeric", "2-digit"],
|
|
108
|
+
m: ["numeric", "2-digit"],
|
|
109
|
+
s: ["numeric", "2-digit"]
|
|
110
|
+
};
|
|
111
|
+
function padIf(condition, value, length) {
|
|
112
|
+
return condition && length === 2 && value / 10 < 1 ? "0" + value : value;
|
|
113
|
+
}
|
|
114
|
+
function formatType(date, type, length) {
|
|
115
|
+
var _options;
|
|
116
|
+
var _ref = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}, locale = _ref.locale, timeZone = _ref.timeZone;
|
|
117
|
+
var option = optionNames[type];
|
|
118
|
+
var value = values[type][length - 1];
|
|
119
|
+
if (!value) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
var options = (_options = {}, _defineProperty(_options, option, value), _defineProperty(_options, "timeZone", timeZone), _options);
|
|
123
|
+
if (type === "a") {
|
|
124
|
+
return Intl.DateTimeFormat(locale, _objectSpread(_objectSpread({}, options), {}, {
|
|
125
|
+
hour: "numeric"
|
|
126
|
+
})).formatToParts(date).pop().value;
|
|
127
|
+
}
|
|
128
|
+
if (type === "G" || type === "Z") {
|
|
129
|
+
return Intl.DateTimeFormat(locale, options).formatToParts(date).pop().value;
|
|
130
|
+
}
|
|
131
|
+
if (type === "H" || type === "h") {
|
|
132
|
+
return Intl.DateTimeFormat("en-GB", _objectSpread(_objectSpread({}, options), {}, {
|
|
133
|
+
hourCycle: type === "H" ? "h23" : "h11"
|
|
134
|
+
})).format(date).toLocaleLowerCase().replace(" am", "").replace(" pm", "");
|
|
135
|
+
}
|
|
136
|
+
return padIf(["m", "s"].includes(type) && value === "2-digit", Intl.DateTimeFormat(locale, options).format(date), 2);
|
|
137
|
+
}
|
|
138
|
+
function format2(date, pattern, config) {
|
|
139
|
+
return pattern.split(ESCAPE_REGEX).filter(function(sub) {
|
|
140
|
+
return sub !== void 0;
|
|
141
|
+
}).map(function(sub, index) {
|
|
142
|
+
if (index % 2 !== 0) {
|
|
143
|
+
return sub;
|
|
144
|
+
}
|
|
145
|
+
return sub.replace(PATTERN_REGEX, function(match) {
|
|
146
|
+
var type = match.charAt(0);
|
|
147
|
+
return formatType(date, type, match.length, config) || match;
|
|
148
|
+
});
|
|
149
|
+
}).join("");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js
|
|
155
|
+
var require_lib = __commonJS({
|
|
156
|
+
"../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js"(exports2) {
|
|
157
|
+
"use strict";
|
|
158
|
+
Object.defineProperty(exports2, "__esModule", {
|
|
159
|
+
value: true
|
|
160
|
+
});
|
|
161
|
+
exports2.format = void 0;
|
|
162
|
+
var _format = require_format();
|
|
163
|
+
var _format2 = _interopRequireDefault(_format);
|
|
164
|
+
function _interopRequireDefault(obj) {
|
|
165
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
166
|
+
}
|
|
167
|
+
exports2.format = _format2["default"];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
20
171
|
// src/index.ts
|
|
21
172
|
var src_exports = {};
|
|
22
173
|
__export(src_exports, {
|
|
@@ -139,6 +290,7 @@ __export(src_exports, {
|
|
|
139
290
|
sum: () => sum,
|
|
140
291
|
sumBy: () => sumBy,
|
|
141
292
|
throttle: () => throttle,
|
|
293
|
+
tryToParseJson: () => tryToParseJson,
|
|
142
294
|
uniq: () => uniq,
|
|
143
295
|
uniqBy: () => uniqBy,
|
|
144
296
|
uniqByKey: () => uniqByKey,
|
|
@@ -236,6 +388,16 @@ function isFunction(t) {
|
|
|
236
388
|
return typeof t === "function";
|
|
237
389
|
}
|
|
238
390
|
|
|
391
|
+
// src/types/json.ts
|
|
392
|
+
function tryToParseJson(jsonContent) {
|
|
393
|
+
try {
|
|
394
|
+
const data = JSON.parse(jsonContent);
|
|
395
|
+
return [data, null];
|
|
396
|
+
} catch (err) {
|
|
397
|
+
return [null, asError(err)];
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
239
401
|
// src/types/nulls.ts
|
|
240
402
|
function ensureDefined(v, name = "value") {
|
|
241
403
|
if (isDefined(v))
|
|
@@ -582,8 +744,132 @@ var LazyAsync = class _LazyAsync {
|
|
|
582
744
|
}
|
|
583
745
|
};
|
|
584
746
|
|
|
747
|
+
// src/time/TimeInstant.ts
|
|
748
|
+
var import_small_date = __toESM(require_lib());
|
|
749
|
+
|
|
750
|
+
// src/time/TimeUnit.ts
|
|
751
|
+
var TimeUnit = class _TimeUnit {
|
|
752
|
+
constructor(multiplier) {
|
|
753
|
+
this.multiplier = multiplier;
|
|
754
|
+
}
|
|
755
|
+
toUnit(value, unit) {
|
|
756
|
+
return value * (this.multiplier / unit.multiplier);
|
|
757
|
+
}
|
|
758
|
+
toMs(value) {
|
|
759
|
+
return this.toUnit(value, _TimeUnit.MILLISECONDS);
|
|
760
|
+
}
|
|
761
|
+
toSeconds(value) {
|
|
762
|
+
return this.toUnit(value, _TimeUnit.SECONDS);
|
|
763
|
+
}
|
|
764
|
+
toMinutes(value) {
|
|
765
|
+
return this.toUnit(value, _TimeUnit.MINUTES);
|
|
766
|
+
}
|
|
767
|
+
toHours(value) {
|
|
768
|
+
return this.toUnit(value, _TimeUnit.HOURS);
|
|
769
|
+
}
|
|
770
|
+
toDays(value) {
|
|
771
|
+
return this.toUnit(value, _TimeUnit.DAYS);
|
|
772
|
+
}
|
|
773
|
+
toWeeks(value) {
|
|
774
|
+
return this.toUnit(value, _TimeUnit.WEEKS);
|
|
775
|
+
}
|
|
776
|
+
static MILLISECONDS = new _TimeUnit(1);
|
|
777
|
+
static SECONDS = new _TimeUnit(1e3 * _TimeUnit.MILLISECONDS.multiplier);
|
|
778
|
+
static MINUTES = new _TimeUnit(60 * _TimeUnit.SECONDS.multiplier);
|
|
779
|
+
static HOURS = new _TimeUnit(60 * _TimeUnit.MINUTES.multiplier);
|
|
780
|
+
static DAYS = new _TimeUnit(24 * _TimeUnit.HOURS.multiplier);
|
|
781
|
+
static WEEKS = new _TimeUnit(7 * _TimeUnit.DAYS.multiplier);
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
// src/time/TimeBase.ts
|
|
785
|
+
var TimeBase = class {
|
|
786
|
+
_ms;
|
|
787
|
+
constructor(value, unit) {
|
|
788
|
+
this._ms = unit.toMs(value);
|
|
789
|
+
}
|
|
790
|
+
get ms() {
|
|
791
|
+
return Math.floor(this._ms / TimeUnit.MILLISECONDS.multiplier);
|
|
792
|
+
}
|
|
793
|
+
get seconds() {
|
|
794
|
+
return Math.floor(this._ms / TimeUnit.SECONDS.multiplier);
|
|
795
|
+
}
|
|
796
|
+
get minutes() {
|
|
797
|
+
return Math.floor(this._ms / TimeUnit.MINUTES.multiplier);
|
|
798
|
+
}
|
|
799
|
+
get hours() {
|
|
800
|
+
return Math.floor(this._ms / TimeUnit.HOURS.multiplier);
|
|
801
|
+
}
|
|
802
|
+
get days() {
|
|
803
|
+
return Math.floor(this._ms / TimeUnit.DAYS.multiplier);
|
|
804
|
+
}
|
|
805
|
+
addMs(milliseconds) {
|
|
806
|
+
return this.addUnits(milliseconds, TimeUnit.MILLISECONDS);
|
|
807
|
+
}
|
|
808
|
+
addSeconds(seconds) {
|
|
809
|
+
return this.addUnits(seconds, TimeUnit.SECONDS);
|
|
810
|
+
}
|
|
811
|
+
addMinutes(minutes) {
|
|
812
|
+
return this.addUnits(minutes, TimeUnit.MINUTES);
|
|
813
|
+
}
|
|
814
|
+
addHours(hours) {
|
|
815
|
+
return this.addUnits(hours, TimeUnit.HOURS);
|
|
816
|
+
}
|
|
817
|
+
addDays(days) {
|
|
818
|
+
return this.addUnits(days, TimeUnit.DAYS);
|
|
819
|
+
}
|
|
820
|
+
removeDays(days) {
|
|
821
|
+
return this.removeUnits(days, TimeUnit.DAYS);
|
|
822
|
+
}
|
|
823
|
+
addUnits(n, unit) {
|
|
824
|
+
return this.create(this._ms + unit.toMs(n), TimeUnit.MILLISECONDS);
|
|
825
|
+
}
|
|
826
|
+
removeMs(milliseconds) {
|
|
827
|
+
return this.addUnits(-milliseconds, TimeUnit.MILLISECONDS);
|
|
828
|
+
}
|
|
829
|
+
removeSeconds(seconds) {
|
|
830
|
+
return this.addUnits(-seconds, TimeUnit.SECONDS);
|
|
831
|
+
}
|
|
832
|
+
removeMinutes(minutes) {
|
|
833
|
+
return this.addUnits(-minutes, TimeUnit.MINUTES);
|
|
834
|
+
}
|
|
835
|
+
removeHours(hours) {
|
|
836
|
+
return this.addUnits(-hours, TimeUnit.HOURS);
|
|
837
|
+
}
|
|
838
|
+
removeUnits(n, unit) {
|
|
839
|
+
return this.addUnits(-n, unit);
|
|
840
|
+
}
|
|
841
|
+
getUnit(unit) {
|
|
842
|
+
return this._ms / unit.multiplier;
|
|
843
|
+
}
|
|
844
|
+
toUnits() {
|
|
845
|
+
return {
|
|
846
|
+
days: Math.floor(this._ms / TimeUnit.DAYS.multiplier),
|
|
847
|
+
hours: Math.floor(this._ms / TimeUnit.HOURS.multiplier % 24),
|
|
848
|
+
minutes: Math.floor(this._ms / TimeUnit.MINUTES.multiplier % 60),
|
|
849
|
+
seconds: Math.floor(this._ms / TimeUnit.SECONDS.multiplier % 60)
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
static toMs(units) {
|
|
853
|
+
if (!units)
|
|
854
|
+
throw new Error("Invalid units given");
|
|
855
|
+
let ms = 0;
|
|
856
|
+
ms += units.ms ?? 0 * TimeUnit.MILLISECONDS.multiplier;
|
|
857
|
+
ms += (units.seconds ?? 0) * TimeUnit.SECONDS.multiplier;
|
|
858
|
+
ms += (units.minutes ?? 0) * TimeUnit.MINUTES.multiplier;
|
|
859
|
+
ms += (units.hours ?? 0) * TimeUnit.HOURS.multiplier;
|
|
860
|
+
ms += (units.days ?? 0) * TimeUnit.DAYS.multiplier;
|
|
861
|
+
return ms;
|
|
862
|
+
}
|
|
863
|
+
toJSON() {
|
|
864
|
+
return this._ms;
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
|
|
585
868
|
// src/async/Deferred.ts
|
|
586
869
|
var DeferredCanceledError = class extends Error {
|
|
870
|
+
constructor() {
|
|
871
|
+
super("Execution canceled");
|
|
872
|
+
}
|
|
587
873
|
};
|
|
588
874
|
var Deferred = class {
|
|
589
875
|
_pending;
|
|
@@ -600,15 +886,37 @@ var Deferred = class {
|
|
|
600
886
|
this._internals = this.createInternals();
|
|
601
887
|
}
|
|
602
888
|
resolve(val) {
|
|
603
|
-
if (!this._pending)
|
|
889
|
+
if (!this._pending)
|
|
890
|
+
throw new Error("Illegal state exception");
|
|
891
|
+
this.resolveIfPending(val);
|
|
892
|
+
}
|
|
893
|
+
reject(reason) {
|
|
894
|
+
if (!this._pending)
|
|
895
|
+
throw new Error("Illegal state exception");
|
|
896
|
+
this.rejectIfPending(reason);
|
|
897
|
+
}
|
|
898
|
+
cancel() {
|
|
899
|
+
if (!this._pending)
|
|
900
|
+
throw new Error("Illegal state exception");
|
|
901
|
+
this.cancelIfPending();
|
|
902
|
+
}
|
|
903
|
+
resolveIfPending(val) {
|
|
904
|
+
if (!this._pending)
|
|
905
|
+
return;
|
|
604
906
|
this._pending = false;
|
|
605
907
|
this._internals.resolve(val);
|
|
606
908
|
}
|
|
607
|
-
|
|
608
|
-
if (!this._pending)
|
|
909
|
+
rejectIfPending(reason) {
|
|
910
|
+
if (!this._pending)
|
|
911
|
+
return;
|
|
609
912
|
this._pending = false;
|
|
610
913
|
this._internals.reject(reason);
|
|
611
914
|
}
|
|
915
|
+
cancelIfPending() {
|
|
916
|
+
if (!this._pending)
|
|
917
|
+
return;
|
|
918
|
+
this.reject(new DeferredCanceledError());
|
|
919
|
+
}
|
|
612
920
|
then(onFulfilled, onRejected) {
|
|
613
921
|
return this._internals.promise.then(onFulfilled, onRejected);
|
|
614
922
|
}
|
|
@@ -618,10 +926,6 @@ var Deferred = class {
|
|
|
618
926
|
finally(onfinally) {
|
|
619
927
|
return this._internals.promise.finally(onfinally);
|
|
620
928
|
}
|
|
621
|
-
cancel() {
|
|
622
|
-
if (!this._pending) throw new Error("Illegal state exception");
|
|
623
|
-
this._internals.reject(new DeferredCanceledError("Execution aborted by the user"));
|
|
624
|
-
}
|
|
625
929
|
get asPromise() {
|
|
626
930
|
return this;
|
|
627
931
|
}
|
|
@@ -646,6 +950,16 @@ var Deferred = class {
|
|
|
646
950
|
};
|
|
647
951
|
var Deferred_default = Deferred;
|
|
648
952
|
|
|
953
|
+
// src/random/randomInterval.ts
|
|
954
|
+
function randomInterval(min2, max2) {
|
|
955
|
+
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
// src/random/randomPercentage.ts
|
|
959
|
+
function randomPercentage(min2, max2) {
|
|
960
|
+
return randomInterval(min2, max2) / 100;
|
|
961
|
+
}
|
|
962
|
+
|
|
649
963
|
// src/utils/bindThis.ts
|
|
650
964
|
function bindThis(fn, _this) {
|
|
651
965
|
return fn.bind(_this);
|
|
@@ -926,25 +1240,28 @@ var RateThrottler = class {
|
|
|
926
1240
|
var Semaphore = class {
|
|
927
1241
|
constructor(_availableSlots = 1) {
|
|
928
1242
|
this._availableSlots = _availableSlots;
|
|
929
|
-
this.
|
|
1243
|
+
this._queuedRequests = [];
|
|
930
1244
|
}
|
|
931
|
-
|
|
1245
|
+
_queuedRequests;
|
|
1246
|
+
_inProgress = 0;
|
|
932
1247
|
async _awaitSlot() {
|
|
933
1248
|
if (this._availableSlots > 0) {
|
|
934
1249
|
this._availableSlots -= 1;
|
|
1250
|
+
this._inProgress += 1;
|
|
935
1251
|
return void 0;
|
|
936
1252
|
} else {
|
|
937
1253
|
const deferred = new Deferred_default();
|
|
938
|
-
this.
|
|
1254
|
+
this._queuedRequests.push(deferred);
|
|
939
1255
|
return deferred.asPromise;
|
|
940
1256
|
}
|
|
941
1257
|
}
|
|
942
1258
|
_releaseSlot() {
|
|
943
|
-
const waitingSlotToResolve = this.
|
|
1259
|
+
const waitingSlotToResolve = this._queuedRequests.shift();
|
|
944
1260
|
if (waitingSlotToResolve) {
|
|
945
1261
|
waitingSlotToResolve.resolve();
|
|
946
1262
|
} else {
|
|
947
1263
|
this._availableSlots += 1;
|
|
1264
|
+
this._inProgress -= 1;
|
|
948
1265
|
}
|
|
949
1266
|
}
|
|
950
1267
|
async execute(fn, cooldown = TimeDuration.ZERO) {
|
|
@@ -952,6 +1269,15 @@ var Semaphore = class {
|
|
|
952
1269
|
void cooldown.promise().then(() => this._releaseSlot());
|
|
953
1270
|
});
|
|
954
1271
|
}
|
|
1272
|
+
get availableSlots() {
|
|
1273
|
+
return this._availableSlots;
|
|
1274
|
+
}
|
|
1275
|
+
get queueSize() {
|
|
1276
|
+
return this._queuedRequests.length;
|
|
1277
|
+
}
|
|
1278
|
+
get inProgressSize() {
|
|
1279
|
+
return this._inProgress;
|
|
1280
|
+
}
|
|
955
1281
|
};
|
|
956
1282
|
|
|
957
1283
|
// src/utils/throttle.ts
|
|
@@ -1006,134 +1332,6 @@ function wrap(str, delimiter) {
|
|
|
1006
1332
|
return delimiter + str + delimiter;
|
|
1007
1333
|
}
|
|
1008
1334
|
|
|
1009
|
-
// src/time/TimeUnit.ts
|
|
1010
|
-
var TimeUnit = class _TimeUnit {
|
|
1011
|
-
constructor(multiplier) {
|
|
1012
|
-
this.multiplier = multiplier;
|
|
1013
|
-
}
|
|
1014
|
-
toUnit(value, unit) {
|
|
1015
|
-
return value * (this.multiplier / unit.multiplier);
|
|
1016
|
-
}
|
|
1017
|
-
toMs(value) {
|
|
1018
|
-
return this.toUnit(value, _TimeUnit.MILLISECONDS);
|
|
1019
|
-
}
|
|
1020
|
-
toSeconds(value) {
|
|
1021
|
-
return this.toUnit(value, _TimeUnit.SECONDS);
|
|
1022
|
-
}
|
|
1023
|
-
toMinutes(value) {
|
|
1024
|
-
return this.toUnit(value, _TimeUnit.MINUTES);
|
|
1025
|
-
}
|
|
1026
|
-
toHours(value) {
|
|
1027
|
-
return this.toUnit(value, _TimeUnit.HOURS);
|
|
1028
|
-
}
|
|
1029
|
-
toDays(value) {
|
|
1030
|
-
return this.toUnit(value, _TimeUnit.DAYS);
|
|
1031
|
-
}
|
|
1032
|
-
toWeeks(value) {
|
|
1033
|
-
return this.toUnit(value, _TimeUnit.WEEKS);
|
|
1034
|
-
}
|
|
1035
|
-
static MILLISECONDS = new _TimeUnit(1);
|
|
1036
|
-
static SECONDS = new _TimeUnit(1e3 * _TimeUnit.MILLISECONDS.multiplier);
|
|
1037
|
-
static MINUTES = new _TimeUnit(60 * _TimeUnit.SECONDS.multiplier);
|
|
1038
|
-
static HOURS = new _TimeUnit(60 * _TimeUnit.MINUTES.multiplier);
|
|
1039
|
-
static DAYS = new _TimeUnit(24 * _TimeUnit.HOURS.multiplier);
|
|
1040
|
-
static WEEKS = new _TimeUnit(7 * _TimeUnit.DAYS.multiplier);
|
|
1041
|
-
};
|
|
1042
|
-
|
|
1043
|
-
// src/time/TimeBase.ts
|
|
1044
|
-
var TimeBase = class {
|
|
1045
|
-
_ms;
|
|
1046
|
-
constructor(value, unit) {
|
|
1047
|
-
this._ms = unit.toMs(value);
|
|
1048
|
-
}
|
|
1049
|
-
get ms() {
|
|
1050
|
-
return Math.floor(this._ms / TimeUnit.MILLISECONDS.multiplier);
|
|
1051
|
-
}
|
|
1052
|
-
get seconds() {
|
|
1053
|
-
return Math.floor(this._ms / TimeUnit.SECONDS.multiplier);
|
|
1054
|
-
}
|
|
1055
|
-
get minutes() {
|
|
1056
|
-
return Math.floor(this._ms / TimeUnit.MINUTES.multiplier);
|
|
1057
|
-
}
|
|
1058
|
-
get hours() {
|
|
1059
|
-
return Math.floor(this._ms / TimeUnit.HOURS.multiplier);
|
|
1060
|
-
}
|
|
1061
|
-
get days() {
|
|
1062
|
-
return Math.floor(this._ms / TimeUnit.DAYS.multiplier);
|
|
1063
|
-
}
|
|
1064
|
-
addMs(milliseconds) {
|
|
1065
|
-
return this.addUnits(milliseconds, TimeUnit.MILLISECONDS);
|
|
1066
|
-
}
|
|
1067
|
-
addSeconds(seconds) {
|
|
1068
|
-
return this.addUnits(seconds, TimeUnit.SECONDS);
|
|
1069
|
-
}
|
|
1070
|
-
addMinutes(minutes) {
|
|
1071
|
-
return this.addUnits(minutes, TimeUnit.MINUTES);
|
|
1072
|
-
}
|
|
1073
|
-
addHours(hours) {
|
|
1074
|
-
return this.addUnits(hours, TimeUnit.HOURS);
|
|
1075
|
-
}
|
|
1076
|
-
addDays(days) {
|
|
1077
|
-
return this.addUnits(days, TimeUnit.DAYS);
|
|
1078
|
-
}
|
|
1079
|
-
removeDays(days) {
|
|
1080
|
-
return this.removeUnits(days, TimeUnit.DAYS);
|
|
1081
|
-
}
|
|
1082
|
-
addUnits(n, unit) {
|
|
1083
|
-
return this.create(this._ms + unit.toMs(n), TimeUnit.MILLISECONDS);
|
|
1084
|
-
}
|
|
1085
|
-
removeMs(milliseconds) {
|
|
1086
|
-
return this.addUnits(-milliseconds, TimeUnit.MILLISECONDS);
|
|
1087
|
-
}
|
|
1088
|
-
removeSeconds(seconds) {
|
|
1089
|
-
return this.addUnits(-seconds, TimeUnit.SECONDS);
|
|
1090
|
-
}
|
|
1091
|
-
removeMinutes(minutes) {
|
|
1092
|
-
return this.addUnits(-minutes, TimeUnit.MINUTES);
|
|
1093
|
-
}
|
|
1094
|
-
removeHours(hours) {
|
|
1095
|
-
return this.addUnits(-hours, TimeUnit.HOURS);
|
|
1096
|
-
}
|
|
1097
|
-
removeUnits(n, unit) {
|
|
1098
|
-
return this.addUnits(-n, unit);
|
|
1099
|
-
}
|
|
1100
|
-
getUnit(unit) {
|
|
1101
|
-
return this._ms / unit.multiplier;
|
|
1102
|
-
}
|
|
1103
|
-
toUnits() {
|
|
1104
|
-
return {
|
|
1105
|
-
days: Math.floor(this._ms / TimeUnit.DAYS.multiplier),
|
|
1106
|
-
hours: Math.floor(this._ms / TimeUnit.HOURS.multiplier % 24),
|
|
1107
|
-
minutes: Math.floor(this._ms / TimeUnit.MINUTES.multiplier % 60),
|
|
1108
|
-
seconds: Math.floor(this._ms / TimeUnit.SECONDS.multiplier % 60)
|
|
1109
|
-
};
|
|
1110
|
-
}
|
|
1111
|
-
static toMs(units) {
|
|
1112
|
-
if (!units)
|
|
1113
|
-
throw new Error("Invalid units given");
|
|
1114
|
-
let ms = 0;
|
|
1115
|
-
ms += units.ms ?? 0 * TimeUnit.MILLISECONDS.multiplier;
|
|
1116
|
-
ms += (units.seconds ?? 0) * TimeUnit.SECONDS.multiplier;
|
|
1117
|
-
ms += (units.minutes ?? 0) * TimeUnit.MINUTES.multiplier;
|
|
1118
|
-
ms += (units.hours ?? 0) * TimeUnit.HOURS.multiplier;
|
|
1119
|
-
ms += (units.days ?? 0) * TimeUnit.DAYS.multiplier;
|
|
1120
|
-
return ms;
|
|
1121
|
-
}
|
|
1122
|
-
toJSON() {
|
|
1123
|
-
return this._ms;
|
|
1124
|
-
}
|
|
1125
|
-
};
|
|
1126
|
-
|
|
1127
|
-
// src/random/randomInterval.ts
|
|
1128
|
-
function randomInterval(min2, max2) {
|
|
1129
|
-
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
// src/random/randomPercentage.ts
|
|
1133
|
-
function randomPercentage(min2, max2) {
|
|
1134
|
-
return randomInterval(min2, max2) / 100;
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
1335
|
// src/time/TimeDuration.ts
|
|
1138
1336
|
var TimeDuration = class _TimeDuration extends TimeBase {
|
|
1139
1337
|
constructor(value, unit) {
|
|
@@ -1174,14 +1372,14 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1174
1372
|
* @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
|
|
1175
1373
|
*/
|
|
1176
1374
|
get formatted() {
|
|
1177
|
-
const
|
|
1375
|
+
const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
|
|
1178
1376
|
const units = this.toUnits();
|
|
1179
1377
|
if (units.days >= 1)
|
|
1180
|
-
return
|
|
1378
|
+
return format2(units.days, "d", units.hours, "h");
|
|
1181
1379
|
else if (units.hours >= 1)
|
|
1182
|
-
return
|
|
1380
|
+
return format2(units.hours, "h", units.minutes, "m");
|
|
1183
1381
|
else if (units.minutes >= 1)
|
|
1184
|
-
return
|
|
1382
|
+
return format2(units.minutes, "m", units.seconds, "s");
|
|
1185
1383
|
else if (units.seconds >= 0)
|
|
1186
1384
|
return units.seconds.toString() + "s";
|
|
1187
1385
|
else if (units.seconds > -60)
|
|
@@ -1214,8 +1412,10 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1214
1412
|
const deferred = this.promise();
|
|
1215
1413
|
void deferred.then(() => {
|
|
1216
1414
|
cb();
|
|
1217
|
-
}, (
|
|
1218
|
-
|
|
1415
|
+
}, (err) => {
|
|
1416
|
+
if (err instanceof DeferredCanceledError)
|
|
1417
|
+
return;
|
|
1418
|
+
throw err;
|
|
1219
1419
|
});
|
|
1220
1420
|
return { cancel: () => deferred.cancel() };
|
|
1221
1421
|
}
|
|
@@ -1414,7 +1614,7 @@ var timeInstantResolveValue = (getFromDate2, referenceDate, x) => {
|
|
|
1414
1614
|
if (relativeTo === void 0 || relativeTo === "now") {
|
|
1415
1615
|
return getFromDate2(referenceDate) + relative;
|
|
1416
1616
|
} else {
|
|
1417
|
-
return getFromDate2(relativeTo.
|
|
1617
|
+
return getFromDate2(relativeTo.toDate()) + relative;
|
|
1418
1618
|
}
|
|
1419
1619
|
} else if ("absolute" in x) {
|
|
1420
1620
|
return x.absolute;
|
|
@@ -1433,7 +1633,7 @@ var getFromDate = {
|
|
|
1433
1633
|
};
|
|
1434
1634
|
var toReferenceDate = (x) => {
|
|
1435
1635
|
ensureDefined(x);
|
|
1436
|
-
if (isTimeInstant(x)) return x.
|
|
1636
|
+
if (isTimeInstant(x)) return x.toDate();
|
|
1437
1637
|
return x;
|
|
1438
1638
|
};
|
|
1439
1639
|
function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInstant.now()) {
|
|
@@ -1453,7 +1653,7 @@ function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInsta
|
|
|
1453
1653
|
return TimeInstant.fromUnixTimestamp(timestamp2);
|
|
1454
1654
|
}
|
|
1455
1655
|
function timeInstantBuilder() {
|
|
1456
|
-
let referenceDate = TimeInstant.now().
|
|
1656
|
+
let referenceDate = TimeInstant.now().toDate();
|
|
1457
1657
|
const value = { ...defaultTimeInstantCreationParameters };
|
|
1458
1658
|
const ret = {
|
|
1459
1659
|
year: (x) => {
|
|
@@ -1529,157 +1729,103 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1529
1729
|
atEndOfDay() {
|
|
1530
1730
|
return this.atTime({ hours: 23, minutes: 59, seconds: 59, milliseconds: 999 });
|
|
1531
1731
|
}
|
|
1532
|
-
/** @deprecated[2024-10-24]: Use #promise() instead. */
|
|
1533
|
-
timeout(cb) {
|
|
1534
|
-
if (!this.isInTheFuture) {
|
|
1535
|
-
throw new Error("Instant is in the past");
|
|
1536
|
-
} else {
|
|
1537
|
-
return this.distanceFromNow().timeout(() => cb());
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
1732
|
promise() {
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
deferred.resolve();
|
|
1544
|
-
} else {
|
|
1545
|
-
this.distanceFromNow().timeout(() => deferred.resolve());
|
|
1546
|
-
}
|
|
1547
|
-
return deferred.asCancelablePromise;
|
|
1733
|
+
this.ensureInTheFuture();
|
|
1734
|
+
return this.distanceFromNow().promise();
|
|
1548
1735
|
}
|
|
1549
1736
|
delay(cb) {
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1737
|
+
this.ensureInTheFuture();
|
|
1738
|
+
return this.distanceFromNow().delay(cb);
|
|
1739
|
+
}
|
|
1740
|
+
ensureInTheFuture() {
|
|
1741
|
+
if (!this.isInTheFuture)
|
|
1742
|
+
throw new Error("Instant is in the past");
|
|
1743
|
+
}
|
|
1744
|
+
ensureInThePast() {
|
|
1745
|
+
if (!this.isInThePast)
|
|
1746
|
+
throw new Error("Instant is in the future");
|
|
1557
1747
|
}
|
|
1558
1748
|
isToday() {
|
|
1559
1749
|
return Math.floor(this.days) === Math.floor(_TimeInstant.now().days);
|
|
1560
1750
|
}
|
|
1751
|
+
/**
|
|
1752
|
+
* @returns the time as HH:mm:ss
|
|
1753
|
+
* @deprecated [2024-12-11] this method is too ambigous and should be removed.
|
|
1754
|
+
*/
|
|
1561
1755
|
asTimeString() {
|
|
1562
|
-
|
|
1563
|
-
return `${this.doGetTwoDigitsHours(date)}:${this.doGetTwoDigitsMinutes(date)}:${this.doGetTwoDigitsSeconds(date)}`;
|
|
1756
|
+
return this.format("HH:mm:ss");
|
|
1564
1757
|
}
|
|
1758
|
+
/**
|
|
1759
|
+
* @returns the date as dd/MM/yyyy
|
|
1760
|
+
* @deprecated [2024-12-11] this method is too ambigous and should be removed.
|
|
1761
|
+
*/
|
|
1565
1762
|
asDateString() {
|
|
1566
|
-
|
|
1567
|
-
return `${this.doGetTwoDigitsDays(date)}/${this.doGetTwoDigitsMonths(date)}/${this.doGetFourDigitsYears(date)}`;
|
|
1763
|
+
return this.format("dd/MM/yyyy");
|
|
1568
1764
|
}
|
|
1569
1765
|
/**
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1766
|
+
* Formats this instant using the given pattern. The pattern can contain the following tokens:
|
|
1767
|
+
*
|
|
1768
|
+
* | Token | Description | Example |
|
|
1769
|
+
* |:------|:--------------------------------|:------------------------------|
|
|
1770
|
+
* | D | Weekday, 1 letter | W |
|
|
1771
|
+
* | DD | Weekday, 3 letters | Wed |
|
|
1772
|
+
* | DDD | Weekday, long | Wednesday |
|
|
1773
|
+
* | d | Day of the month, no padding | 3 |
|
|
1774
|
+
* | dd | Day of the month, padded to 2 | 03 |
|
|
1775
|
+
* | M | Month, numeric | 3 |
|
|
1776
|
+
* | MM | Month, 2 digits | 03 |
|
|
1777
|
+
* | MMM | Month, 3 letters | Mar |
|
|
1778
|
+
* | MMMM | Month, long | March |
|
|
1779
|
+
* | y | Year, numeric | 2021 |
|
|
1780
|
+
* | yy | Year, 2 digits | 21 |
|
|
1781
|
+
* | yyyy | Year, numeric | 2021 |
|
|
1782
|
+
* | h | Hours, no padding | 6 |
|
|
1783
|
+
* | hh | Hours, padded to 2 | 06 |
|
|
1784
|
+
* | H | Hours in 24-format, no padding | 18 |
|
|
1785
|
+
* | HH | Hours in 24-format, padded to 2 | 18 |
|
|
1786
|
+
* | m | Minutes, no padding | 7 |
|
|
1787
|
+
* | m | Minutes, padded to 2 | 07 |
|
|
1788
|
+
* | s | Seconds, no padding | 8 |
|
|
1789
|
+
* | ss | Seconds, padded to 2 | 08 |
|
|
1790
|
+
* | S | Milliseconds, no padding | 9 |
|
|
1791
|
+
* | SS | Milliseconds, padded to 2 | 09 |
|
|
1792
|
+
* | SSS | Milliseconds, padded to 3 | 009 |
|
|
1793
|
+
* | G | Era, narrow | A |
|
|
1794
|
+
* | GG | Era, short | AD |
|
|
1795
|
+
* | GGG | Era, long | Anno Domino |
|
|
1796
|
+
* | Z | Time zone, short | GMT+1 |
|
|
1797
|
+
* | ZZ | Time short, long C | entral European Standard Time |
|
|
1798
|
+
* | P | Period of the day, narrow | in the morning |
|
|
1799
|
+
* | PP | Period of the day, short | in the morning |
|
|
1800
|
+
* | PPP | Period of the day, long | in the morning |
|
|
1801
|
+
* | a | Meridiem | pm |
|
|
1802
|
+
* @param pattern The pattern to use. Refer to the token table above for details.
|
|
1803
|
+
* @param config An optional locale and timeZone definition to use during the format.
|
|
1804
|
+
* @returns a string, formatted using the given pattern, at the given timeZone with the given locale.
|
|
1805
|
+
*/
|
|
1806
|
+
format(pattern, config = {}) {
|
|
1807
|
+
return (0, import_small_date.format)(this.toDate(), pattern, config);
|
|
1575
1808
|
}
|
|
1576
1809
|
/**
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
return this.doGetFourDigitsYears(utcDate) + dash + this.doGetTwoDigitsMonths(utcDate) + dash + this.doGetTwoDigitsDays(utcDate) + T + this.doGetTwoDigitsHours(utcDate) + doublecolon + this.doGetTwoDigitsMinutes(utcDate) + doublecolon + this.doGetTwoDigitsSeconds(utcDate) + colon + this.doGetThreeDigitsMilliseconds(utcDate) + "Z";
|
|
1810
|
+
* @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024Z). The format is meant to always be realiable.
|
|
1811
|
+
*/
|
|
1812
|
+
asIso8601() {
|
|
1813
|
+
return this.format('yyyy-MM-dd"T"HH:mm:ss.SSS"Z"', { timeZone: "UTC" });
|
|
1582
1814
|
}
|
|
1583
1815
|
/**
|
|
1584
1816
|
* @returns this instant, in a human readable format. The format COULD change in the future, do NOT use this method for consistent outputs.
|
|
1817
|
+
* @deprecated [2024-12-11] this method is too broad and ambigous and should be removed.
|
|
1585
1818
|
*/
|
|
1586
1819
|
asHumanTimestamp() {
|
|
1587
|
-
|
|
1588
|
-
return this.doGetFourDigitsYears(date) + dash + this.doGetTwoDigitsMonths(date) + dash + this.doGetTwoDigitsDays(date) + space + this.doGetTwoDigitsHours(date) + doublecolon + this.doGetTwoDigitsMinutes(date) + doublecolon + this.doGetTwoDigitsSeconds(date);
|
|
1589
|
-
}
|
|
1590
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1591
|
-
get twoDigitsDays() {
|
|
1592
|
-
return this.doGetTwoDigitsDays(this.asDate());
|
|
1593
|
-
}
|
|
1594
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1595
|
-
get twoDigitsMonths() {
|
|
1596
|
-
return this.doGetTwoDigitsMonths(this.asDate());
|
|
1597
|
-
}
|
|
1598
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1599
|
-
get fourDigitsYears() {
|
|
1600
|
-
return this.doGetFourDigitsYears(this.asDate());
|
|
1601
|
-
}
|
|
1602
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1603
|
-
get twoDigitsHours() {
|
|
1604
|
-
return this.doGetTwoDigitsHours(this.asDate());
|
|
1605
|
-
}
|
|
1606
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1607
|
-
get twoDigitsMinutes() {
|
|
1608
|
-
return this.doGetTwoDigitsMinutes(this.asDate());
|
|
1609
|
-
}
|
|
1610
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1611
|
-
get twoDigitsSeconds() {
|
|
1612
|
-
return this.doGetTwoDigitsSeconds(this.asDate());
|
|
1613
|
-
}
|
|
1614
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1615
|
-
get threeDigitsMilliseconds() {
|
|
1616
|
-
return this.doGetThreeDigitsMilliseconds(this.asDate());
|
|
1617
|
-
}
|
|
1618
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1619
|
-
get twoDigitsDaysUTC() {
|
|
1620
|
-
return this.doGetTwoDigitsDays(this.asDateUTC());
|
|
1621
|
-
}
|
|
1622
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1623
|
-
get twoDigitsMonthsUTC() {
|
|
1624
|
-
return this.doGetTwoDigitsMonths(this.asDateUTC());
|
|
1625
|
-
}
|
|
1626
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1627
|
-
get fourDigitsYearsUTC() {
|
|
1628
|
-
return this.doGetFourDigitsYears(this.asDateUTC());
|
|
1629
|
-
}
|
|
1630
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1631
|
-
get twoDigitsHoursUTC() {
|
|
1632
|
-
return this.doGetTwoDigitsHours(this.asDateUTC());
|
|
1633
|
-
}
|
|
1634
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1635
|
-
get twoDigitsMinutesUTC() {
|
|
1636
|
-
return this.doGetTwoDigitsMinutes(this.asDateUTC());
|
|
1637
|
-
}
|
|
1638
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1639
|
-
get twoDigitsSecondsUTC() {
|
|
1640
|
-
return this.doGetTwoDigitsSeconds(this.asDateUTC());
|
|
1641
|
-
}
|
|
1642
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1643
|
-
get threeDigitsMillisecondsUTC() {
|
|
1644
|
-
return this.doGetThreeDigitsMilliseconds(this.asDateUTC());
|
|
1645
|
-
}
|
|
1646
|
-
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
1647
|
-
get fourDigitsTimezoneOffset() {
|
|
1648
|
-
const offset = this.asDate().getTimezoneOffset();
|
|
1649
|
-
return (offset >= 0 ? "+" : "-") + pad(Math.floor(Math.abs(offset) / 60).toString(), 2, "0") + pad((Math.abs(offset) % 60).toString(), 2, "0");
|
|
1650
|
-
}
|
|
1651
|
-
doGetTwoDigitsDays(date) {
|
|
1652
|
-
return pad(date.getDate().toString(), 2, "0");
|
|
1653
|
-
}
|
|
1654
|
-
doGetTwoDigitsMonths(date) {
|
|
1655
|
-
return pad((date.getMonth() + 1).toString(), 2, "0");
|
|
1656
|
-
}
|
|
1657
|
-
doGetFourDigitsYears(date) {
|
|
1658
|
-
return pad(date.getFullYear().toString(), 4, "0");
|
|
1659
|
-
}
|
|
1660
|
-
doGetTwoDigitsHours(date) {
|
|
1661
|
-
return pad(date.getHours().toString(), 2, "0");
|
|
1662
|
-
}
|
|
1663
|
-
doGetTwoDigitsMinutes(date) {
|
|
1664
|
-
return pad(date.getMinutes().toString(), 2, "0");
|
|
1665
|
-
}
|
|
1666
|
-
doGetTwoDigitsSeconds(date) {
|
|
1667
|
-
return pad(date.getSeconds().toString(), 2, "0");
|
|
1668
|
-
}
|
|
1669
|
-
doGetThreeDigitsMilliseconds(date) {
|
|
1670
|
-
return pad(date.getMilliseconds().toString(), 3, "0");
|
|
1671
|
-
}
|
|
1672
|
-
doGetFourDigitsTimezoneOffset(date) {
|
|
1673
|
-
const offset = date.getTimezoneOffset();
|
|
1674
|
-
return (offset >= 0 ? "+" : "-") + pad(Math.floor(Math.abs(offset) / 60).toString(), 2, "0") + pad((Math.abs(offset) % 60).toString(), 2, "0");
|
|
1820
|
+
return this.format("yyyy-MM-dd HH:mm:ss");
|
|
1675
1821
|
}
|
|
1676
|
-
|
|
1822
|
+
toUnixTimestamp() {
|
|
1677
1823
|
return this.ms;
|
|
1678
1824
|
}
|
|
1679
|
-
|
|
1825
|
+
toDate() {
|
|
1680
1826
|
return new Date(this.ms);
|
|
1681
1827
|
}
|
|
1682
|
-
|
|
1828
|
+
toDateUTC() {
|
|
1683
1829
|
return new Date(this.ms + (/* @__PURE__ */ new Date()).getTimezoneOffset() * 60 * 1e3);
|
|
1684
1830
|
}
|
|
1685
1831
|
get isInThePast() {
|
|
@@ -1800,23 +1946,23 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1800
1946
|
return _TimeInstant.fromUnixTimestamp(timestamp2);
|
|
1801
1947
|
}
|
|
1802
1948
|
get dayOfMonth() {
|
|
1803
|
-
return this.
|
|
1949
|
+
return this.toDate().getDate();
|
|
1804
1950
|
}
|
|
1805
1951
|
get dayOfWeek() {
|
|
1806
|
-
return this.
|
|
1952
|
+
return this.toDate().getDay() + 1;
|
|
1807
1953
|
}
|
|
1808
1954
|
get month() {
|
|
1809
|
-
return this.
|
|
1955
|
+
return this.toDate().getMonth() + 1;
|
|
1810
1956
|
}
|
|
1811
1957
|
get year() {
|
|
1812
|
-
return this.
|
|
1958
|
+
return this.toDate().getFullYear();
|
|
1813
1959
|
}
|
|
1814
1960
|
/**
|
|
1815
1961
|
* Returns the week number represented by this instant, according to the ISO 8601 standard.
|
|
1816
1962
|
* Please note that the instant and the week number could be of two different years, eg the friday 1st january is actually part of week 52 of the previous year.
|
|
1817
1963
|
*/
|
|
1818
1964
|
get weekNumber() {
|
|
1819
|
-
const date = this.
|
|
1965
|
+
const date = this.toDate();
|
|
1820
1966
|
const oneDay = 1e3 * 60 * 60 * 24;
|
|
1821
1967
|
const thursdayOfThisWeek = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 4 - (date.getDay() || 7), 14, 0, 0);
|
|
1822
1968
|
const firstOfJanuary = new Date(thursdayOfThisWeek.getFullYear(), 0, 1, 14, 0, 0);
|
|
@@ -2669,6 +2815,7 @@ function isUpgradable(obj) {
|
|
|
2669
2815
|
sum,
|
|
2670
2816
|
sumBy,
|
|
2671
2817
|
throttle,
|
|
2818
|
+
tryToParseJson,
|
|
2672
2819
|
uniq,
|
|
2673
2820
|
uniqBy,
|
|
2674
2821
|
uniqByKey,
|