@oneuptime/common 14.0.91 → 14.0.92
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/Models/DatabaseModels/AutoRemediationRule.js +1 -1
- package/Models/DatabaseModels/CodeRepository.d.mts +1 -0
- package/Models/DatabaseModels/CodeRepository.d.ts +1 -0
- package/Models/DatabaseModels/CodeRepository.js +69 -6
- package/Types/AI/CodeTask.d.mts +1 -0
- package/Types/AI/CodeTask.d.ts +1 -0
- package/Types/AI/TelemetryAiActivity.d.mts +1 -0
- package/Types/AI/TelemetryAiActivity.d.ts +1 -0
- package/Types/AI/TelemetryAiActivity.js +4 -0
- package/Types/CodeRepository/CodeRepositorySetting.d.mts +15 -0
- package/Types/CodeRepository/CodeRepositorySetting.d.ts +15 -0
- package/Types/CodeRepository/CodeRepositorySetting.js +49 -0
- package/Types/CodeRepository/CodeRepositorySetting.mjs +3 -0
- package/Types/Date.d.mts +10 -0
- package/Types/Date.d.ts +10 -0
- package/Types/Date.js +385 -98
- package/Types/DateLanguage.d.mts +67 -0
- package/Types/DateLanguage.d.ts +67 -0
- package/Types/DateLanguage.js +478 -0
- package/Types/DateLanguage.mjs +21 -0
- package/Types/Runner/CodeRepositoryRunner.d.mts +7 -0
- package/Types/Runner/CodeRepositoryRunner.d.ts +7 -0
- package/Types/Runner/CodeRepositoryRunner.js +60 -14
- package/Types/Runner/CodeRepositoryRunner.mjs +1 -0
- package/Types/SecurityEvent/OcsfProcessActivity.d.mts +25 -0
- package/Types/SecurityEvent/OcsfProcessActivity.d.ts +25 -0
- package/Types/SecurityEvent/OcsfProcessActivity.js +131 -0
- package/Types/SecurityEvent/OcsfProcessActivity.mjs +8 -0
- package/UI/Utils/TranslateTemplate.d.mts +73 -0
- package/UI/Utils/TranslateTemplate.d.ts +73 -0
- package/Utils/CronTab.d.mts +41 -3
- package/Utils/CronTab.d.ts +41 -3
- package/Utils/CronTab.js +112 -38
- package/Utils/Monitor/MonitorOverviewTargetUtil.d.mts +2 -0
- package/Utils/Monitor/MonitorOverviewTargetUtil.d.ts +2 -0
- package/Utils/Monitor/MonitorOverviewTargetUtil.js +13 -2
- package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.d.mts +5 -0
- package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.d.ts +5 -0
- package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.js +219 -58
- package/Utils/SecurityEvent/OcsfNormalizer.js +22 -13
- package/Utils/Slo/SloDuration.d.mts +1 -0
- package/Utils/Slo/SloDuration.d.ts +1 -0
- package/Utils/Slo/SloDuration.js +57 -8
- package/Utils/Slo/SloDuration.mjs +1 -0
- package/Utils/Suggestions/CodeFixSuggestion.d.mts +15 -0
- package/Utils/Suggestions/CodeFixSuggestion.d.ts +15 -0
- package/Utils/Suggestions/CodeFixSuggestion.js +62 -1
- package/Utils/Suggestions/CodeFixSuggestion.mjs +4 -0
- package/Utils/Suggestions/ProfileFixSuggestion.js +4 -0
- package/Utils/Suggestions/SuggestionBlocker.d.mts +8 -0
- package/Utils/Suggestions/SuggestionBlocker.d.ts +8 -0
- package/Utils/Suggestions/SuggestionBlocker.js +51 -0
- package/Utils/Suggestions/SuggestionBlocker.mjs +4 -0
- package/Utils/Suggestions/SuggestionOffer.d.mts +2 -1
- package/Utils/Suggestions/SuggestionOffer.d.ts +2 -1
- package/Utils/Suggestions/SuggestionOffer.js +5 -0
- package/Utils/Suggestions/TelemetryAiFixSuggestion.d.mts +2 -7
- package/Utils/Suggestions/TelemetryAiFixSuggestion.d.ts +2 -7
- package/Utils/Suggestions/TelemetryAiFixSuggestion.js +8 -36
- package/Utils/Suggestions/TelemetryImprovementSuggestion.d.mts +1 -0
- package/Utils/Suggestions/TelemetryImprovementSuggestion.d.ts +1 -0
- package/Utils/Suggestions/TelemetryImprovementSuggestion.js +1 -0
- package/Utils/Suggestions/TracePerformanceFixSuggestion.d.mts +6 -0
- package/Utils/Suggestions/TracePerformanceFixSuggestion.d.ts +6 -0
- package/Utils/Suggestions/TracePerformanceFixSuggestion.js +46 -5
- package/package.json +8 -1
- package/Utils/Monitor/MonitorCheckScheduleUtil.d.mts +0 -61
- package/Utils/Monitor/MonitorCheckScheduleUtil.d.ts +0 -61
- package/Utils/Monitor/MonitorCheckScheduleUtil.js +0 -476
- package/Utils/Monitor/MonitorCheckScheduleUtil.mjs +0 -3
- package/Utils/Monitor/MonitorOverviewFamily.d.mts +0 -39
- package/Utils/Monitor/MonitorOverviewFamily.d.ts +0 -39
- package/Utils/Monitor/MonitorOverviewFamily.js +0 -206
- package/Utils/Monitor/MonitorOverviewFamily.mjs +0 -4
- package/Utils/Monitor/MonitorOverviewPresentationUtil.d.mts +0 -189
- package/Utils/Monitor/MonitorOverviewPresentationUtil.d.ts +0 -189
- package/Utils/Monitor/MonitorOverviewPresentationUtil.js +0 -1480
- package/Utils/Monitor/MonitorOverviewPresentationUtil.mjs +0 -5
- package/Utils/Monitor/MonitorOverviewProbeUtil.d.mts +0 -112
- package/Utils/Monitor/MonitorOverviewProbeUtil.d.ts +0 -112
- package/Utils/Monitor/MonitorOverviewProbeUtil.js +0 -640
- package/Utils/Monitor/MonitorOverviewProbeUtil.mjs +0 -3
- package/Utils/Monitor/MonitorStatusHistoryUtil.d.mts +0 -27
- package/Utils/Monitor/MonitorStatusHistoryUtil.d.ts +0 -27
- package/Utils/Monitor/MonitorStatusHistoryUtil.js +0 -132
- package/Utils/Monitor/MonitorStatusHistoryUtil.mjs +0 -2
- package/Utils/Monitor/MonitorUptimeSummaryUtil.d.mts +0 -42
- package/Utils/Monitor/MonitorUptimeSummaryUtil.d.ts +0 -42
- package/Utils/Monitor/MonitorUptimeSummaryUtil.js +0 -468
- package/Utils/Monitor/MonitorUptimeSummaryUtil.mjs +0 -2
package/Types/Date.js
CHANGED
|
@@ -47,9 +47,44 @@ const Timezone_1 = __importDefault(require("./Timezone"));
|
|
|
47
47
|
const TimezoneAlias_1 = __importDefault(require("./TimezoneAlias"));
|
|
48
48
|
const Zod_1 = __importDefault(require("../Utils/Schema/Zod"));
|
|
49
49
|
const RefusedValue_1 = require("../Utils/RefusedValue");
|
|
50
|
+
const DateLanguage_1 = require("./DateLanguage");
|
|
50
51
|
exports.Moment = moment_timezone_1.default;
|
|
52
|
+
/*
|
|
53
|
+
* The custom shapes (getDateAsCustomFormattedStringInTimezone) a date's words
|
|
54
|
+
* are written in the reader's language for, as Intl asks for them. A shape
|
|
55
|
+
* with no words in it ("YYYY", "HH:mm:ss.SSS") reads the same in every
|
|
56
|
+
* language; one that is not listed is written by moment, in English.
|
|
57
|
+
*/
|
|
58
|
+
const LOCALIZED_CUSTOM_DATE_FORMATS = {
|
|
59
|
+
"MMM D": { month: "short", day: "numeric" },
|
|
60
|
+
"MMM DD": { month: "short", day: "2-digit" },
|
|
61
|
+
"MMM D, YYYY": { month: "short", day: "numeric", year: "numeric" },
|
|
62
|
+
"MMM DD, YYYY": { month: "short", day: "2-digit", year: "numeric" },
|
|
63
|
+
"MMM DD YYYY": { month: "short", day: "2-digit", year: "numeric" },
|
|
64
|
+
"MMM YYYY": { month: "short", year: "numeric" },
|
|
65
|
+
"MMMM YYYY": { month: "long", year: "numeric" },
|
|
66
|
+
"MMMM D, YYYY": { month: "long", day: "numeric", year: "numeric" },
|
|
67
|
+
"h:mm A": { hour: "numeric", minute: "2-digit", hour12: true },
|
|
68
|
+
"hh:mm A": { hour: "2-digit", minute: "2-digit", hour12: true },
|
|
69
|
+
};
|
|
51
70
|
// A whole number of nanoseconds, as fromUnixNano reads one exactly.
|
|
52
71
|
const UNIX_NANO_INTEGER_PATTERN = /^[+-]?\d+$/;
|
|
72
|
+
/*
|
|
73
|
+
* The decimal point of a short duration's figure ("1.72 s", "2m 5.5s"): a
|
|
74
|
+
* digit either side of it. Read on a few characters, so linear.
|
|
75
|
+
*/
|
|
76
|
+
const DURATION_DECIMAL_POINT = /(\d)\.(\d)/g;
|
|
77
|
+
// Every digit, to find the separator a language writes between them.
|
|
78
|
+
const DIGITS = /\d/g;
|
|
79
|
+
// secondsToFormattedFriendlyTimeString's English unit words: one, many.
|
|
80
|
+
const FRIENDLY_TIME_ENGLISH_UNITS = {
|
|
81
|
+
year: ["year", "years"],
|
|
82
|
+
month: ["month", "months"],
|
|
83
|
+
day: ["day", "days"],
|
|
84
|
+
hour: ["hour", "hours"],
|
|
85
|
+
minute: ["min", "mins"],
|
|
86
|
+
second: ["sec", "secs"],
|
|
87
|
+
};
|
|
53
88
|
/*
|
|
54
89
|
* BigInt(1000000), made the first time fromUnixNano reads an integer string
|
|
55
90
|
* rather than when this module loads: every frontend bundle loads Date.ts,
|
|
@@ -96,12 +131,20 @@ class OneUptimeDate {
|
|
|
96
131
|
* finally moment, which carries its own zone data.
|
|
97
132
|
*/
|
|
98
133
|
const timezone = this.getCurrentTimezone();
|
|
134
|
+
const language = (0, DateLanguage_1.getDateDisplayLanguage)();
|
|
135
|
+
/*
|
|
136
|
+
* In the reader's language once a frontend set one ("Okt."); until then
|
|
137
|
+
* in the browser's own, as it always was.
|
|
138
|
+
*/
|
|
139
|
+
const locale = (0, DateLanguage_1.isEnglishDateLanguage)(language)
|
|
140
|
+
? "default"
|
|
141
|
+
: (0, DateLanguage_1.getDateLocale)(language);
|
|
99
142
|
for (const name of [
|
|
100
143
|
timezone,
|
|
101
144
|
...TimezoneAlias_1.default.getLegacyNamesOf(timezone),
|
|
102
145
|
]) {
|
|
103
146
|
try {
|
|
104
|
-
return date.toLocaleString(
|
|
147
|
+
return date.toLocaleString(locale, {
|
|
105
148
|
month: "short",
|
|
106
149
|
timeZone: name.toString(),
|
|
107
150
|
});
|
|
@@ -112,6 +155,38 @@ class OneUptimeDate {
|
|
|
112
155
|
}
|
|
113
156
|
return this.inCurrentTimezone(date).format("MMM");
|
|
114
157
|
}
|
|
158
|
+
/*
|
|
159
|
+
* The current timezone and its legacy spellings, for Intl: an engine with
|
|
160
|
+
* tzdata before 2022b throws a RangeError for "Europe/Kyiv", which is what
|
|
161
|
+
* getCurrentTimezone reports for a browser that says "Europe/Kiev", but
|
|
162
|
+
* knows the legacy name.
|
|
163
|
+
*/
|
|
164
|
+
static getCurrentTimezoneNames() {
|
|
165
|
+
return this.getTimezoneNames(this.getCurrentTimezone());
|
|
166
|
+
}
|
|
167
|
+
static getTimezoneNames(timezone) {
|
|
168
|
+
return [
|
|
169
|
+
timezone.toString(),
|
|
170
|
+
...TimezoneAlias_1.default.getLegacyNamesOf(timezone).map((name) => {
|
|
171
|
+
return name.toString();
|
|
172
|
+
}),
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
/*
|
|
176
|
+
* `date` in the reader's language, in the shape asked for, read in the
|
|
177
|
+
* current timezone (or the runtime's own zone with `timezones` empty).
|
|
178
|
+
* Null when the language is English or Intl cannot write it: the caller
|
|
179
|
+
* then writes moment's English.
|
|
180
|
+
*/
|
|
181
|
+
static getLocalizedDateText(data) {
|
|
182
|
+
var _a;
|
|
183
|
+
return (0, DateLanguage_1.formatDateText)({
|
|
184
|
+
date: data.date,
|
|
185
|
+
locale: data.locale,
|
|
186
|
+
timezones: (_a = data.timezones) !== null && _a !== void 0 ? _a : this.getCurrentTimezoneNames(),
|
|
187
|
+
shape: data.shape,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
115
190
|
static getSchema() {
|
|
116
191
|
return Zod_1.default.object({
|
|
117
192
|
_type: Zod_1.default.literal(JSON_1.ObjectType.DateTime),
|
|
@@ -137,14 +212,34 @@ class OneUptimeDate {
|
|
|
137
212
|
static getHoursAndMinutesFromMinutes(minutes) {
|
|
138
213
|
const hours = Math.floor(minutes / 60);
|
|
139
214
|
const mins = minutes % 60;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
215
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
216
|
+
let formattedString = "";
|
|
217
|
+
if (hours > 0) {
|
|
218
|
+
formattedString += hours + " hours ";
|
|
219
|
+
}
|
|
220
|
+
if (mins > 0) {
|
|
221
|
+
formattedString += mins + " minutes";
|
|
222
|
+
}
|
|
223
|
+
return formattedString.trim() || "0 minutes";
|
|
224
|
+
}, (_language, locale) => {
|
|
225
|
+
// "2 Stunden 5 Minuten", "0 Minuten".
|
|
226
|
+
const parts = [];
|
|
227
|
+
if (hours > 0) {
|
|
228
|
+
parts.push({ count: hours, unit: "hour" });
|
|
229
|
+
}
|
|
230
|
+
if (mins > 0) {
|
|
231
|
+
parts.push({ count: mins, unit: "minute" });
|
|
232
|
+
}
|
|
233
|
+
return this.formatLocalizedDuration(parts.length > 0 ? parts : [{ count: 0, unit: "minute" }], locale, "long", "narrow");
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/*
|
|
237
|
+
* A duration's parts in `locale`: "2 Tage, 3 Stunden", or with `listStyle`
|
|
238
|
+
* "narrow" as a compact reading joins them ("2 Std. 5 Min."). Null when
|
|
239
|
+
* Intl cannot write one of the units, and the caller writes English.
|
|
240
|
+
*/
|
|
241
|
+
static formatLocalizedDuration(parts, locale, unitDisplay, listStyle) {
|
|
242
|
+
return (0, DateLanguage_1.formatDurationText)({ parts, locale, unitDisplay, listStyle });
|
|
148
243
|
}
|
|
149
244
|
static fromUnixTimestamp(timestamp) {
|
|
150
245
|
return new Date(timestamp * 1000);
|
|
@@ -245,10 +340,20 @@ class OneUptimeDate {
|
|
|
245
340
|
return this.inCurrentTimezone(date).format(timeFormat);
|
|
246
341
|
}
|
|
247
342
|
static getDateAsLocalDayMonthString(date) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
343
|
+
const instant = this.fromString(date);
|
|
344
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
345
|
+
const day = this.padDatePart(this.inCurrentTimezone(instant).date());
|
|
346
|
+
const month = this.getLocalShortMonthName(instant);
|
|
347
|
+
return `${day} ${month}`;
|
|
348
|
+
}, (language, locale) => {
|
|
349
|
+
// "02. Okt.", "02 oct.", "10月02日".
|
|
350
|
+
return this.getLocalizedDateText({
|
|
351
|
+
date: instant,
|
|
352
|
+
language,
|
|
353
|
+
locale,
|
|
354
|
+
shape: { onlyShowDate: true, hideYear: true, twoDigitDay: true },
|
|
355
|
+
});
|
|
356
|
+
});
|
|
252
357
|
}
|
|
253
358
|
static getDateAsLocalDayMonthHourString(date) {
|
|
254
359
|
date = this.fromString(date);
|
|
@@ -302,13 +407,38 @@ class OneUptimeDate {
|
|
|
302
407
|
if (use12HourFormat) {
|
|
303
408
|
timeFormat += " A";
|
|
304
409
|
}
|
|
305
|
-
|
|
410
|
+
const instant = date;
|
|
411
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
412
|
+
return this.inCurrentTimezone(instant).format(`MMM D, ${timeFormat}`);
|
|
413
|
+
}, (language, locale) => {
|
|
414
|
+
// "1. März, 14:30", "1 mars, 14:30", "3月1日 14:30".
|
|
415
|
+
return this.getLocalizedDateText({
|
|
416
|
+
date: instant,
|
|
417
|
+
language,
|
|
418
|
+
locale,
|
|
419
|
+
shape: {
|
|
420
|
+
hideYear: true,
|
|
421
|
+
use12HourFormat,
|
|
422
|
+
showSeconds: Boolean(options === null || options === void 0 ? void 0 : options.includeSeconds),
|
|
423
|
+
},
|
|
424
|
+
});
|
|
425
|
+
});
|
|
306
426
|
}
|
|
307
427
|
static getDateAsLocalMonthYearString(date) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
428
|
+
const instant = this.fromString(date);
|
|
429
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
430
|
+
const month = this.getLocalShortMonthName(instant);
|
|
431
|
+
const year = this.inCurrentTimezone(instant).year().toString();
|
|
432
|
+
return `${month} ${year}`;
|
|
433
|
+
}, (_language, locale) => {
|
|
434
|
+
// "Okt. 2026", "oct. 2026", "2026年10月".
|
|
435
|
+
const format = (0, DateLanguage_1.getDateTimeFormat)({
|
|
436
|
+
locale,
|
|
437
|
+
timezones: this.getCurrentTimezoneNames(),
|
|
438
|
+
options: { month: "short", year: "numeric" },
|
|
439
|
+
});
|
|
440
|
+
return format ? format.format(instant) : null;
|
|
441
|
+
});
|
|
312
442
|
}
|
|
313
443
|
static getMillisecondsBetweenTwoUnixNanoDates(startDate, endDate) {
|
|
314
444
|
return endDate - startDate;
|
|
@@ -372,6 +502,39 @@ class OneUptimeDate {
|
|
|
372
502
|
var _a;
|
|
373
503
|
const date = this.fromString(data.date);
|
|
374
504
|
const use12HourFormat = (_a = data.use12HourFormat) !== null && _a !== void 0 ? _a : this.getUserPrefers12HourFormat();
|
|
505
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
506
|
+
return this.getEnglishDateInTimezone({
|
|
507
|
+
date,
|
|
508
|
+
timezone: data.timezone,
|
|
509
|
+
onlyShowDate: data.onlyShowDate,
|
|
510
|
+
showWeekday: data.showWeekday,
|
|
511
|
+
use12HourFormat,
|
|
512
|
+
});
|
|
513
|
+
}, (language, locale) => {
|
|
514
|
+
// "Di., 6. Okt. 2026, 10:05 BST".
|
|
515
|
+
const timezone = (data.timezone ||
|
|
516
|
+
this.getCurrentTimezone());
|
|
517
|
+
const text = this.getLocalizedDateText({
|
|
518
|
+
date,
|
|
519
|
+
language,
|
|
520
|
+
locale,
|
|
521
|
+
shape: {
|
|
522
|
+
onlyShowDate: data.onlyShowDate,
|
|
523
|
+
showWeekday: data.showWeekday,
|
|
524
|
+
use12HourFormat,
|
|
525
|
+
},
|
|
526
|
+
timezones: this.getTimezoneNames(timezone),
|
|
527
|
+
});
|
|
528
|
+
if (!text || data.onlyShowDate) {
|
|
529
|
+
return text;
|
|
530
|
+
}
|
|
531
|
+
return `${text} ${this.getZoneAbbrByTimezone(timezone, date)}`.trim();
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
// getDateAsFormattedStringInTimezone's English, as moment writes it.
|
|
535
|
+
static getEnglishDateInTimezone(data) {
|
|
536
|
+
const date = data.date;
|
|
537
|
+
const use12HourFormat = data.use12HourFormat;
|
|
375
538
|
const timePart = use12HourFormat ? "h:mm A" : "HH:mm";
|
|
376
539
|
const datePart = data.showWeekday
|
|
377
540
|
? "ddd, MMM D, YYYY"
|
|
@@ -402,10 +565,26 @@ class OneUptimeDate {
|
|
|
402
565
|
*/
|
|
403
566
|
static getDateAsCustomFormattedStringInTimezone(data) {
|
|
404
567
|
const date = this.fromString(data.date);
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
568
|
+
const english = () => {
|
|
569
|
+
if (!data.timezone) {
|
|
570
|
+
return this.inCurrentTimezone(date).format(data.format);
|
|
571
|
+
}
|
|
572
|
+
return (0, moment_timezone_1.default)(date).tz(data.timezone).format(data.format);
|
|
573
|
+
};
|
|
574
|
+
const options = LOCALIZED_CUSTOM_DATE_FORMATS[data.format];
|
|
575
|
+
if (!options) {
|
|
576
|
+
return english();
|
|
577
|
+
}
|
|
578
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(english, (_language, locale) => {
|
|
579
|
+
const format = (0, DateLanguage_1.getDateTimeFormat)({
|
|
580
|
+
locale,
|
|
581
|
+
timezones: data.timezone
|
|
582
|
+
? this.getTimezoneNames(data.timezone)
|
|
583
|
+
: this.getCurrentTimezoneNames(),
|
|
584
|
+
options,
|
|
585
|
+
});
|
|
586
|
+
return format ? format.format(date) : null;
|
|
587
|
+
});
|
|
409
588
|
}
|
|
410
589
|
/**
|
|
411
590
|
* Reinterpret the wall-clock components of `date` — read in the CURRENT
|
|
@@ -521,8 +700,20 @@ class OneUptimeDate {
|
|
|
521
700
|
*/
|
|
522
701
|
return new Date();
|
|
523
702
|
}
|
|
703
|
+
/*
|
|
704
|
+
* "5 hours ago", "in 3 days" - in the reader's language when a frontend set
|
|
705
|
+
* one ("vor 5 Stunden"), rounded as moment rounds it.
|
|
706
|
+
*/
|
|
524
707
|
static fromNow(date) {
|
|
525
|
-
return (0,
|
|
708
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
709
|
+
return (0, moment_timezone_1.default)(date).fromNow();
|
|
710
|
+
}, (_language, locale) => {
|
|
711
|
+
return (0, DateLanguage_1.formatRelativeDate)({
|
|
712
|
+
date: this.fromString(date),
|
|
713
|
+
now: new Date(),
|
|
714
|
+
locale,
|
|
715
|
+
});
|
|
716
|
+
});
|
|
526
717
|
}
|
|
527
718
|
static differenceBetweenTwoDatesAsFromattedString(date1, date2) {
|
|
528
719
|
const seconds = this.getSecondsBetweenTwoDates(date1, date2);
|
|
@@ -980,73 +1171,47 @@ class OneUptimeDate {
|
|
|
980
1171
|
static toUnixTimestamp(date) {
|
|
981
1172
|
return Math.floor(date.getTime() / 1000);
|
|
982
1173
|
}
|
|
1174
|
+
/*
|
|
1175
|
+
* "1 year 2 months 3 days 4 hours 5 mins 6 secs", each unit that is not
|
|
1176
|
+
* zero, counted on the calendar from the epoch - and in the reader's
|
|
1177
|
+
* language when a frontend set one ("1 J. 2 Mon. 3 Tg.").
|
|
1178
|
+
*/
|
|
983
1179
|
static secondsToFormattedFriendlyTimeString(seconds) {
|
|
1180
|
+
const parts = this.getFriendlyTimeParts(seconds);
|
|
1181
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
1182
|
+
return parts
|
|
1183
|
+
.map((part) => {
|
|
1184
|
+
const names = FRIENDLY_TIME_ENGLISH_UNITS[part.unit] || [part.unit, part.unit];
|
|
1185
|
+
return `${part.count} ${part.count === 1 ? names[0] : names[1]}`;
|
|
1186
|
+
})
|
|
1187
|
+
.join(" ");
|
|
1188
|
+
}, (_language, locale) => {
|
|
1189
|
+
return parts.length > 0
|
|
1190
|
+
? this.formatLocalizedDuration(parts, locale, "short", "narrow")
|
|
1191
|
+
: null;
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
// The non-zero calendar units in `seconds` from the epoch, largest first.
|
|
1195
|
+
static getFriendlyTimeParts(seconds) {
|
|
984
1196
|
const startDate = moment_timezone_1.default.utc(0);
|
|
985
1197
|
const date = moment_timezone_1.default.utc(seconds * 1000);
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
if (months > 0) {
|
|
1001
|
-
let text = "months ";
|
|
1002
|
-
if (months === 1) {
|
|
1003
|
-
text = "month ";
|
|
1004
|
-
}
|
|
1005
|
-
// add months to start date
|
|
1006
|
-
startDate.add(months, "months");
|
|
1007
|
-
formattedString += months + " " + text;
|
|
1008
|
-
}
|
|
1009
|
-
const days = date.diff(startDate, "days");
|
|
1010
|
-
if (days > 0) {
|
|
1011
|
-
let text = "days ";
|
|
1012
|
-
if (days === 1) {
|
|
1013
|
-
text = "day ";
|
|
1014
|
-
}
|
|
1015
|
-
// add days to start date
|
|
1016
|
-
startDate.add(days, "days");
|
|
1017
|
-
formattedString += days + " " + text;
|
|
1018
|
-
}
|
|
1019
|
-
const hours = date.diff(startDate, "hours");
|
|
1020
|
-
if (hours > 0) {
|
|
1021
|
-
let text = "hours ";
|
|
1022
|
-
if (hours === 1) {
|
|
1023
|
-
text = "hour ";
|
|
1024
|
-
}
|
|
1025
|
-
// add hours to start date
|
|
1026
|
-
startDate.add(hours, "hours");
|
|
1027
|
-
formattedString += hours + " " + text;
|
|
1028
|
-
}
|
|
1029
|
-
const minutes = date.diff(startDate, "minutes");
|
|
1030
|
-
if (minutes > 0) {
|
|
1031
|
-
let text = "mins ";
|
|
1032
|
-
if (minutes === 1) {
|
|
1033
|
-
text = "min ";
|
|
1034
|
-
}
|
|
1035
|
-
// add minutes to start date
|
|
1036
|
-
startDate.add(minutes, "minutes");
|
|
1037
|
-
formattedString += minutes + " " + text;
|
|
1038
|
-
}
|
|
1039
|
-
const secondsLeft = date.diff(startDate, "seconds");
|
|
1040
|
-
if (secondsLeft > 0) {
|
|
1041
|
-
let text = "secs ";
|
|
1042
|
-
if (secondsLeft === 1) {
|
|
1043
|
-
text = "sec ";
|
|
1198
|
+
const parts = [];
|
|
1199
|
+
const units = [
|
|
1200
|
+
{ unit: "year", moment: "years" },
|
|
1201
|
+
{ unit: "month", moment: "months" },
|
|
1202
|
+
{ unit: "day", moment: "days" },
|
|
1203
|
+
{ unit: "hour", moment: "hours" },
|
|
1204
|
+
{ unit: "minute", moment: "minutes" },
|
|
1205
|
+
{ unit: "second", moment: "seconds" },
|
|
1206
|
+
];
|
|
1207
|
+
for (const unit of units) {
|
|
1208
|
+
const count = date.diff(startDate, unit.moment);
|
|
1209
|
+
if (count > 0) {
|
|
1210
|
+
startDate.add(count, unit.moment);
|
|
1211
|
+
parts.push({ count, unit: unit.unit });
|
|
1044
1212
|
}
|
|
1045
|
-
// add seconds to start date
|
|
1046
|
-
startDate.add(secondsLeft, "seconds");
|
|
1047
|
-
formattedString += secondsLeft + " " + text;
|
|
1048
1213
|
}
|
|
1049
|
-
return
|
|
1214
|
+
return parts;
|
|
1050
1215
|
}
|
|
1051
1216
|
static getGreaterDate(a, b) {
|
|
1052
1217
|
a = this.fromString(a);
|
|
@@ -1328,9 +1493,30 @@ class OneUptimeDate {
|
|
|
1328
1493
|
if (options === null || options === void 0 ? void 0 : options.onlyShowDate) {
|
|
1329
1494
|
formatstring = "MMM DD, YYYY";
|
|
1330
1495
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
((
|
|
1496
|
+
const instant = date;
|
|
1497
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
1498
|
+
return ((0, moment_timezone_1.default)(instant).format(formatstring) +
|
|
1499
|
+
" " +
|
|
1500
|
+
((options === null || options === void 0 ? void 0 : options.onlyShowDate) ? "" : this.getCurrentTimezoneString()));
|
|
1501
|
+
}, (language, locale) => {
|
|
1502
|
+
// Read in the runtime's own zone, as moment(date) reads it.
|
|
1503
|
+
const text = this.getLocalizedDateText({
|
|
1504
|
+
date: instant,
|
|
1505
|
+
language,
|
|
1506
|
+
locale,
|
|
1507
|
+
shape: {
|
|
1508
|
+
onlyShowDate: options === null || options === void 0 ? void 0 : options.onlyShowDate,
|
|
1509
|
+
showSeconds: options === null || options === void 0 ? void 0 : options.showSeconds,
|
|
1510
|
+
use12HourFormat: options === null || options === void 0 ? void 0 : options.use12HourFormat,
|
|
1511
|
+
twoDigitDay: true,
|
|
1512
|
+
},
|
|
1513
|
+
timezones: [],
|
|
1514
|
+
});
|
|
1515
|
+
if (!text || (options === null || options === void 0 ? void 0 : options.onlyShowDate)) {
|
|
1516
|
+
return text;
|
|
1517
|
+
}
|
|
1518
|
+
return `${text} ${this.getCurrentTimezoneString()}`.trim();
|
|
1519
|
+
});
|
|
1334
1520
|
}
|
|
1335
1521
|
static getDifferenceInMinutes(date, date2) {
|
|
1336
1522
|
date = this.fromString(date);
|
|
@@ -1365,6 +1551,31 @@ class OneUptimeDate {
|
|
|
1365
1551
|
const hours = Math.floor((seconds % (24 * 60 * 60)) / (60 * 60));
|
|
1366
1552
|
const minutes = Math.floor((seconds % (60 * 60)) / 60);
|
|
1367
1553
|
const secs = seconds % 60;
|
|
1554
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
1555
|
+
return this.getEnglishDaysHoursMinutesAndSeconds({
|
|
1556
|
+
days,
|
|
1557
|
+
hours,
|
|
1558
|
+
minutes,
|
|
1559
|
+
secs,
|
|
1560
|
+
});
|
|
1561
|
+
}, (_language, locale) => {
|
|
1562
|
+
// "2 Tage, 3 Stunden, 4 Minuten und 5 Sekunden".
|
|
1563
|
+
const parts = [
|
|
1564
|
+
{ count: days, unit: "day" },
|
|
1565
|
+
{ count: hours, unit: "hour" },
|
|
1566
|
+
{ count: minutes, unit: "minute" },
|
|
1567
|
+
{ count: secs, unit: "second" },
|
|
1568
|
+
].filter((part) => {
|
|
1569
|
+
return part.count > 0;
|
|
1570
|
+
});
|
|
1571
|
+
return parts.length > 0
|
|
1572
|
+
? this.formatLocalizedDuration(parts, locale, "long", "long")
|
|
1573
|
+
: null;
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
// convertSecondsToDaysHoursMinutesAndSeconds's English, word for word.
|
|
1577
|
+
static getEnglishDaysHoursMinutesAndSeconds(data) {
|
|
1578
|
+
const { days, hours, minutes, secs } = data;
|
|
1368
1579
|
let formattedString = "";
|
|
1369
1580
|
if (days > 0) {
|
|
1370
1581
|
formattedString += days + " days";
|
|
@@ -1394,6 +1605,25 @@ class OneUptimeDate {
|
|
|
1394
1605
|
const days = Math.floor(minutes / (24 * 60));
|
|
1395
1606
|
const hours = Math.floor((minutes % (24 * 60)) / 60);
|
|
1396
1607
|
const mins = minutes % 60;
|
|
1608
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
1609
|
+
return this.getEnglishDaysHoursAndMinutes({ days, hours, mins });
|
|
1610
|
+
}, (_language, locale) => {
|
|
1611
|
+
// "2 Tage, 3 Stunden und 0 Minuten": the minutes are always said.
|
|
1612
|
+
const parts = [
|
|
1613
|
+
{ count: days, unit: "day" },
|
|
1614
|
+
{ count: hours, unit: "hour" },
|
|
1615
|
+
].filter((part) => {
|
|
1616
|
+
return part.count > 0;
|
|
1617
|
+
});
|
|
1618
|
+
if (mins >= 0) {
|
|
1619
|
+
parts.push({ count: mins, unit: "minute" });
|
|
1620
|
+
}
|
|
1621
|
+
return this.formatLocalizedDuration(parts, locale, "long", "long");
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
// convertMinutesToDaysHoursAndMinutes's English, word for word.
|
|
1625
|
+
static getEnglishDaysHoursAndMinutes(data) {
|
|
1626
|
+
const { days, hours, mins } = data;
|
|
1397
1627
|
let formattedString = "";
|
|
1398
1628
|
if (days > 0) {
|
|
1399
1629
|
formattedString += days + " days";
|
|
@@ -1412,7 +1642,29 @@ class OneUptimeDate {
|
|
|
1412
1642
|
}
|
|
1413
1643
|
return formattedString;
|
|
1414
1644
|
}
|
|
1645
|
+
/*
|
|
1646
|
+
* "1.72 s", "960 ms", "2h 5m". The unit symbols read the same in every
|
|
1647
|
+
* language, as a unit symbol does; the figure is written the reader's
|
|
1648
|
+
* way - "1,72 s" in German.
|
|
1649
|
+
*/
|
|
1415
1650
|
static getHumanizedDurationFromNanoseconds(data) {
|
|
1651
|
+
const english = this.getEnglishHumanizedDuration(data);
|
|
1652
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
1653
|
+
return english;
|
|
1654
|
+
}, (_language, locale) => {
|
|
1655
|
+
return this.withDecimalSeparatorOf(english, locale);
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
// `text`'s decimal points as `locale` writes them: "1.72 s" -> "1,72 s".
|
|
1659
|
+
static withDecimalSeparatorOf(text, locale) {
|
|
1660
|
+
const separator = ((0, DateLanguage_1.formatDecimal)({ value: 1.5, locale, maximumFractionDigits: 1 }) || "1.5").replace(DIGITS, "");
|
|
1661
|
+
if (!separator || separator === ".") {
|
|
1662
|
+
return text;
|
|
1663
|
+
}
|
|
1664
|
+
return text.replace(DURATION_DECIMAL_POINT, `$1${separator}$2`);
|
|
1665
|
+
}
|
|
1666
|
+
// getHumanizedDurationFromNanoseconds's English, as it always read.
|
|
1667
|
+
static getEnglishHumanizedDuration(data) {
|
|
1416
1668
|
var _a, _b;
|
|
1417
1669
|
let { nanoseconds } = data;
|
|
1418
1670
|
const maxParts = (_a = data.maxParts) !== null && _a !== void 0 ? _a : 2;
|
|
@@ -1551,14 +1803,32 @@ class OneUptimeDate {
|
|
|
1551
1803
|
Timezone_1.default.AustraliaSydney,
|
|
1552
1804
|
]; // default timezones.
|
|
1553
1805
|
}
|
|
1806
|
+
const instant = date;
|
|
1554
1807
|
for (let i = 0; i < timezones.length; i++) {
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
.format(formatstring) +
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1808
|
+
const timezone = timezones[i];
|
|
1809
|
+
timezoneDates.push((0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
1810
|
+
return ((0, moment_timezone_1.default)(instant).tz(timezone.toString()).format(formatstring) +
|
|
1811
|
+
" " +
|
|
1812
|
+
(onlyShowDate
|
|
1813
|
+
? ""
|
|
1814
|
+
: this.getZoneAbbrByTimezone(timezone, instant)));
|
|
1815
|
+
}, (language, locale) => {
|
|
1816
|
+
const text = this.getLocalizedDateText({
|
|
1817
|
+
date: instant,
|
|
1818
|
+
language,
|
|
1819
|
+
locale,
|
|
1820
|
+
shape: {
|
|
1821
|
+
onlyShowDate,
|
|
1822
|
+
use12HourFormat,
|
|
1823
|
+
twoDigitDay: true,
|
|
1824
|
+
},
|
|
1825
|
+
timezones: this.getTimezoneNames(timezone),
|
|
1826
|
+
});
|
|
1827
|
+
if (!text || onlyShowDate) {
|
|
1828
|
+
return text;
|
|
1829
|
+
}
|
|
1830
|
+
return `${text} ${this.getZoneAbbrByTimezone(timezone, instant)}`;
|
|
1831
|
+
}));
|
|
1562
1832
|
}
|
|
1563
1833
|
return timezoneDates;
|
|
1564
1834
|
}
|
|
@@ -1603,7 +1873,7 @@ class OneUptimeDate {
|
|
|
1603
1873
|
if (onlyShowDate) {
|
|
1604
1874
|
formatstring = "MMM DD, YYYY";
|
|
1605
1875
|
}
|
|
1606
|
-
const
|
|
1876
|
+
const instant = date;
|
|
1607
1877
|
/*
|
|
1608
1878
|
* The abbreviation has to describe THIS date's offset, not today's. Asking
|
|
1609
1879
|
* for it without the date labelled every January timestamp "EDT" all
|
|
@@ -1612,8 +1882,25 @@ class OneUptimeDate {
|
|
|
1612
1882
|
*/
|
|
1613
1883
|
const zoneAbbr = onlyShowDate
|
|
1614
1884
|
? ""
|
|
1615
|
-
: this.getZoneAbbrByTimezone(this.getCurrentTimezone(),
|
|
1616
|
-
return (
|
|
1885
|
+
: this.getZoneAbbrByTimezone(this.getCurrentTimezone(), instant);
|
|
1886
|
+
return (0, DateLanguage_1.writeInDateDisplayLanguage)(() => {
|
|
1887
|
+
const momentDate = this.inCurrentTimezone(instant);
|
|
1888
|
+
return (momentDate.format(formatstring) + " " + zoneAbbr).trim();
|
|
1889
|
+
}, (language, locale) => {
|
|
1890
|
+
// "06. Okt. 2026, 10:05 BST", "2026年10月06日 10:05 BST".
|
|
1891
|
+
const text = this.getLocalizedDateText({
|
|
1892
|
+
date: instant,
|
|
1893
|
+
language,
|
|
1894
|
+
locale,
|
|
1895
|
+
shape: {
|
|
1896
|
+
onlyShowDate,
|
|
1897
|
+
showSeconds,
|
|
1898
|
+
use12HourFormat,
|
|
1899
|
+
twoDigitDay: true,
|
|
1900
|
+
},
|
|
1901
|
+
});
|
|
1902
|
+
return text ? `${text} ${zoneAbbr}`.trim() : null;
|
|
1903
|
+
});
|
|
1617
1904
|
}
|
|
1618
1905
|
static getDayInSeconds(days) {
|
|
1619
1906
|
if (!days) {
|