@oneuptime/common 14.0.91 → 14.0.93

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.
Files changed (174) hide show
  1. package/Models/DatabaseModels/Alert.js +8 -1
  2. package/Models/DatabaseModels/AlertEpisodeMember.d.mts +1 -0
  3. package/Models/DatabaseModels/AlertEpisodeMember.d.ts +1 -0
  4. package/Models/DatabaseModels/AlertEpisodeMember.js +50 -0
  5. package/Models/DatabaseModels/AutoRemediationRule.js +1 -1
  6. package/Models/DatabaseModels/CodeRepository.d.mts +1 -0
  7. package/Models/DatabaseModels/CodeRepository.d.ts +1 -0
  8. package/Models/DatabaseModels/CodeRepository.js +69 -6
  9. package/Models/DatabaseModels/IncidentEpisodeMember.d.mts +1 -0
  10. package/Models/DatabaseModels/IncidentEpisodeMember.d.ts +1 -0
  11. package/Models/DatabaseModels/IncidentEpisodeMember.js +50 -0
  12. package/Models/DatabaseModels/IncomingCallPolicy.js +1 -1
  13. package/Models/DatabaseModels/LlmProvider.js +1 -1
  14. package/Models/DatabaseModels/MonitorTemplate.js +10 -4
  15. package/Models/DatabaseModels/NetworkDeviceDiscoveryScan.js +13 -13
  16. package/Models/DatabaseModels/OnCallDutyPolicy.js +1 -1
  17. package/Models/DatabaseModels/ScheduledMaintenanceReminderRule.js +1 -1
  18. package/Models/DatabaseModels/StatusPage.d.mts +2 -0
  19. package/Models/DatabaseModels/StatusPage.d.ts +2 -0
  20. package/Models/DatabaseModels/StatusPage.js +100 -0
  21. package/Types/AI/CodeTask.d.mts +1 -0
  22. package/Types/AI/CodeTask.d.ts +1 -0
  23. package/Types/AI/TelemetryAiActivity.d.mts +1 -0
  24. package/Types/AI/TelemetryAiActivity.d.ts +1 -0
  25. package/Types/AI/TelemetryAiActivity.js +4 -0
  26. package/Types/CodeRepository/CodeRepositorySetting.d.mts +15 -0
  27. package/Types/CodeRepository/CodeRepositorySetting.d.ts +15 -0
  28. package/Types/CodeRepository/CodeRepositorySetting.js +49 -0
  29. package/Types/CodeRepository/CodeRepositorySetting.mjs +3 -0
  30. package/Types/Database/BlankColumnValue.d.mts +6 -0
  31. package/Types/Database/BlankColumnValue.d.ts +6 -0
  32. package/Types/Database/BlankColumnValue.js +77 -0
  33. package/Types/Database/BlankColumnValue.mjs +4 -0
  34. package/Types/Date.d.mts +10 -0
  35. package/Types/Date.d.ts +10 -0
  36. package/Types/Date.js +385 -98
  37. package/Types/DateLanguage.d.mts +67 -0
  38. package/Types/DateLanguage.d.ts +67 -0
  39. package/Types/DateLanguage.js +478 -0
  40. package/Types/DateLanguage.mjs +21 -0
  41. package/Types/Email/EmailTemplateType.d.mts +1 -0
  42. package/Types/Email/EmailTemplateType.d.ts +1 -0
  43. package/Types/Email/EmailTemplateType.js +1 -0
  44. package/Types/IncomingCall/IncomingCallPolicyRepeat.d.mts +6 -0
  45. package/Types/IncomingCall/IncomingCallPolicyRepeat.d.ts +6 -0
  46. package/Types/IncomingCall/IncomingCallPolicyRepeat.js +41 -14
  47. package/Types/IncomingCall/IncomingCallPolicyRepeat.mjs +3 -0
  48. package/Types/Monitor/CriteriaFilter.d.mts +1 -0
  49. package/Types/Monitor/CriteriaFilter.d.ts +1 -0
  50. package/Types/Monitor/CriteriaFilter.js +9 -0
  51. package/Types/Monitor/DatabaseMetricCatalog.js +2 -2
  52. package/Types/Monitor/KubernetesEventAlertTemplates.d.mts +20 -0
  53. package/Types/Monitor/KubernetesEventAlertTemplates.d.ts +20 -0
  54. package/Types/Monitor/KubernetesEventAlertTemplates.js +232 -0
  55. package/Types/Monitor/KubernetesEventAlertTemplates.mjs +8 -0
  56. package/Types/Monitor/MonitorType.js +12 -2
  57. package/Types/Monitor/Recommendation/MonitorRecommendationCatalog.js +27 -2
  58. package/Types/Monitor/Recommendation/MonitorRecommendationUtil.d.mts +1 -0
  59. package/Types/Monitor/Recommendation/MonitorRecommendationUtil.d.ts +1 -0
  60. package/Types/Monitor/Recommendation/MonitorRecommendationUtil.js +31 -1
  61. package/Types/Monitor/SnmpMonitor/NetworkDeviceAlertPack.d.mts +3 -1
  62. package/Types/Monitor/SnmpMonitor/NetworkDeviceAlertPack.d.ts +3 -1
  63. package/Types/Monitor/SnmpMonitor/NetworkDeviceAlertPack.js +3 -2
  64. package/Types/Monitor/SnmpMonitor/SnmpMonitorResponse.d.mts +1 -0
  65. package/Types/Monitor/SnmpMonitor/SnmpMonitorResponse.d.ts +1 -0
  66. package/Types/NotificationSetting/NotificationEmailRollupCategory.js +2 -0
  67. package/Types/NotificationSetting/NotificationEmailRollupPolicy.js +10 -3
  68. package/Types/NotificationSetting/NotificationSettingEventType.d.mts +1 -0
  69. package/Types/NotificationSetting/NotificationSettingEventType.d.ts +1 -0
  70. package/Types/NotificationSetting/NotificationSettingEventType.js +7 -0
  71. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRepeat.d.mts +7 -0
  72. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRepeat.d.ts +7 -0
  73. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRepeat.js +51 -0
  74. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRepeat.mjs +4 -0
  75. package/Types/Reminder/ScheduledMaintenanceReminderNeverReminds.d.mts +8 -0
  76. package/Types/Reminder/ScheduledMaintenanceReminderNeverReminds.d.ts +8 -0
  77. package/Types/Reminder/ScheduledMaintenanceReminderNeverReminds.js +55 -0
  78. package/Types/Reminder/ScheduledMaintenanceReminderNeverReminds.mjs +5 -0
  79. package/Types/Runner/CodeRepositoryRunner.d.mts +7 -0
  80. package/Types/Runner/CodeRepositoryRunner.d.ts +7 -0
  81. package/Types/Runner/CodeRepositoryRunner.js +60 -14
  82. package/Types/Runner/CodeRepositoryRunner.mjs +1 -0
  83. package/Types/SecurityEvent/OcsfProcessActivity.d.mts +25 -0
  84. package/Types/SecurityEvent/OcsfProcessActivity.d.ts +25 -0
  85. package/Types/SecurityEvent/OcsfProcessActivity.js +131 -0
  86. package/Types/SecurityEvent/OcsfProcessActivity.mjs +8 -0
  87. package/Types/Workflow/Templates.js +2 -5
  88. package/UI/Utils/TranslateTemplate.d.mts +73 -0
  89. package/UI/Utils/TranslateTemplate.d.ts +73 -0
  90. package/Utils/ColorContrast.d.mts +3 -0
  91. package/Utils/ColorContrast.d.ts +3 -0
  92. package/Utils/ColorContrast.js +41 -3
  93. package/Utils/ColorContrast.mjs +2 -0
  94. package/Utils/CronTab.d.mts +41 -3
  95. package/Utils/CronTab.d.ts +41 -3
  96. package/Utils/CronTab.js +112 -38
  97. package/Utils/Incident/WhoOpenedItRootCause.d.mts +2 -0
  98. package/Utils/Incident/WhoOpenedItRootCause.d.ts +2 -0
  99. package/Utils/Incident/WhoOpenedItRootCause.js +50 -0
  100. package/Utils/Incident/WhoOpenedItRootCause.mjs +3 -0
  101. package/Utils/Monitor/MonitorOverviewTargetUtil.d.mts +2 -0
  102. package/Utils/Monitor/MonitorOverviewTargetUtil.d.ts +2 -0
  103. package/Utils/Monitor/MonitorOverviewTargetUtil.js +13 -2
  104. package/Utils/Monitor/SyntheticMonitorStepsUtil.d.mts +18 -0
  105. package/Utils/Monitor/SyntheticMonitorStepsUtil.d.ts +18 -0
  106. package/Utils/Monitor/SyntheticMonitorStepsUtil.js +129 -0
  107. package/Utils/Monitor/SyntheticMonitorStepsUtil.mjs +4 -0
  108. package/Utils/Rules/RuleRunSummary.d.mts +1 -0
  109. package/Utils/Rules/RuleRunSummary.d.ts +1 -0
  110. package/Utils/Rules/RuleRunSummary.js +19 -1
  111. package/Utils/Rules/RuleRunSummary.mjs +1 -0
  112. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.d.mts +5 -0
  113. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.d.ts +5 -0
  114. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.js +219 -58
  115. package/Utils/SecurityEvent/OcsfNormalizer.js +22 -13
  116. package/Utils/Slo/SloDuration.d.mts +1 -0
  117. package/Utils/Slo/SloDuration.d.ts +1 -0
  118. package/Utils/Slo/SloDuration.js +57 -8
  119. package/Utils/Slo/SloDuration.mjs +1 -0
  120. package/Utils/Sms/Gsm7Text.js +9 -1
  121. package/Utils/Sms/OnCallPageSms.d.mts +2 -0
  122. package/Utils/Sms/OnCallPageSms.d.ts +2 -0
  123. package/Utils/Sms/OnCallPageSms.js +19 -2
  124. package/Utils/Sms/OnCallPageSms.mjs +1 -0
  125. package/Utils/Sms/SubscriberSms.d.mts +2 -0
  126. package/Utils/Sms/SubscriberSms.d.ts +2 -0
  127. package/Utils/Sms/SubscriberSms.js +35 -0
  128. package/Utils/Sms/SubscriberSms.mjs +3 -0
  129. package/Utils/Suggestions/CodeFixSuggestion.d.mts +15 -0
  130. package/Utils/Suggestions/CodeFixSuggestion.d.ts +15 -0
  131. package/Utils/Suggestions/CodeFixSuggestion.js +62 -1
  132. package/Utils/Suggestions/CodeFixSuggestion.mjs +4 -0
  133. package/Utils/Suggestions/ProfileFixSuggestion.js +4 -0
  134. package/Utils/Suggestions/SuggestionBlocker.d.mts +8 -0
  135. package/Utils/Suggestions/SuggestionBlocker.d.ts +8 -0
  136. package/Utils/Suggestions/SuggestionBlocker.js +51 -0
  137. package/Utils/Suggestions/SuggestionBlocker.mjs +4 -0
  138. package/Utils/Suggestions/SuggestionOffer.d.mts +2 -1
  139. package/Utils/Suggestions/SuggestionOffer.d.ts +2 -1
  140. package/Utils/Suggestions/SuggestionOffer.js +5 -0
  141. package/Utils/Suggestions/TelemetryAiFixSuggestion.d.mts +2 -7
  142. package/Utils/Suggestions/TelemetryAiFixSuggestion.d.ts +2 -7
  143. package/Utils/Suggestions/TelemetryAiFixSuggestion.js +8 -36
  144. package/Utils/Suggestions/TelemetryImprovementSuggestion.d.mts +1 -0
  145. package/Utils/Suggestions/TelemetryImprovementSuggestion.d.ts +1 -0
  146. package/Utils/Suggestions/TelemetryImprovementSuggestion.js +1 -0
  147. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.mts +6 -0
  148. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.ts +6 -0
  149. package/Utils/Suggestions/TracePerformanceFixSuggestion.js +46 -5
  150. package/package.json +8 -1
  151. package/Utils/Monitor/MonitorCheckScheduleUtil.d.mts +0 -61
  152. package/Utils/Monitor/MonitorCheckScheduleUtil.d.ts +0 -61
  153. package/Utils/Monitor/MonitorCheckScheduleUtil.js +0 -476
  154. package/Utils/Monitor/MonitorCheckScheduleUtil.mjs +0 -3
  155. package/Utils/Monitor/MonitorOverviewFamily.d.mts +0 -39
  156. package/Utils/Monitor/MonitorOverviewFamily.d.ts +0 -39
  157. package/Utils/Monitor/MonitorOverviewFamily.js +0 -206
  158. package/Utils/Monitor/MonitorOverviewFamily.mjs +0 -4
  159. package/Utils/Monitor/MonitorOverviewPresentationUtil.d.mts +0 -189
  160. package/Utils/Monitor/MonitorOverviewPresentationUtil.d.ts +0 -189
  161. package/Utils/Monitor/MonitorOverviewPresentationUtil.js +0 -1480
  162. package/Utils/Monitor/MonitorOverviewPresentationUtil.mjs +0 -5
  163. package/Utils/Monitor/MonitorOverviewProbeUtil.d.mts +0 -112
  164. package/Utils/Monitor/MonitorOverviewProbeUtil.d.ts +0 -112
  165. package/Utils/Monitor/MonitorOverviewProbeUtil.js +0 -640
  166. package/Utils/Monitor/MonitorOverviewProbeUtil.mjs +0 -3
  167. package/Utils/Monitor/MonitorStatusHistoryUtil.d.mts +0 -27
  168. package/Utils/Monitor/MonitorStatusHistoryUtil.d.ts +0 -27
  169. package/Utils/Monitor/MonitorStatusHistoryUtil.js +0 -132
  170. package/Utils/Monitor/MonitorStatusHistoryUtil.mjs +0 -2
  171. package/Utils/Monitor/MonitorUptimeSummaryUtil.d.mts +0 -42
  172. package/Utils/Monitor/MonitorUptimeSummaryUtil.d.ts +0 -42
  173. package/Utils/Monitor/MonitorUptimeSummaryUtil.js +0 -468
  174. 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("default", {
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
- let formattedString = "";
141
- if (hours > 0) {
142
- formattedString += hours + " hours ";
143
- }
144
- if (mins > 0) {
145
- formattedString += mins + " minutes";
146
- }
147
- return formattedString.trim() || "0 minutes";
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
- date = this.fromString(date);
249
- const day = this.padDatePart(this.inCurrentTimezone(date).date());
250
- const month = this.getLocalShortMonthName(date);
251
- return `${day} ${month}`;
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
- return this.inCurrentTimezone(date).format(`MMM D, ${timeFormat}`);
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
- date = this.fromString(date);
309
- const month = this.getLocalShortMonthName(date);
310
- const year = this.inCurrentTimezone(date).year().toString();
311
- return `${month} ${year}`;
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
- if (!data.timezone) {
406
- return this.inCurrentTimezone(date).format(data.format);
407
- }
408
- return (0, moment_timezone_1.default)(date).tz(data.timezone).format(data.format);
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, moment_timezone_1.default)(date).fromNow();
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
- // get the difference between the two dates as friendly formatted string
987
- let formattedString = "";
988
- // years between two dates
989
- const years = date.diff(startDate, "years");
990
- if (years > 0) {
991
- let text = "years ";
992
- if (years === 1) {
993
- text = "year ";
994
- }
995
- // add years to start date
996
- startDate.add(years, "years");
997
- formattedString += years + " " + text;
998
- }
999
- const months = date.diff(startDate, "months");
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 formattedString.trim();
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
- return ((0, moment_timezone_1.default)(date).format(formatstring) +
1332
- " " +
1333
- ((options === null || options === void 0 ? void 0 : options.onlyShowDate) ? "" : this.getCurrentTimezoneString()));
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
- timezoneDates.push((0, moment_timezone_1.default)(date)
1556
- .tz(timezones[i])
1557
- .format(formatstring) +
1558
- " " +
1559
- (onlyShowDate
1560
- ? ""
1561
- : this.getZoneAbbrByTimezone(timezones[i], date)));
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 momentDate = this.inCurrentTimezone(date);
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(), date);
1616
- return (momentDate.format(formatstring) + " " + zoneAbbr).trim();
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) {