cynx-lib 1.3.41 → 1.3.44

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.
@@ -0,0 +1,542 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var tz_exports = {};
19
+ __export(tz_exports, {
20
+ COMMON_TIMEZONES: () => COMMON_TIMEZONES,
21
+ DEFAULT_OFFSET: () => DEFAULT_OFFSET,
22
+ DEFAULT_TIMEZONE: () => DEFAULT_TIMEZONE,
23
+ DEFAULT_TZ_LABEL: () => DEFAULT_TZ_LABEL,
24
+ addTime: () => addTime,
25
+ combineToTzIso: () => combineToTzIso,
26
+ daysBetween: () => daysBetween,
27
+ default: () => tz_default,
28
+ formatCustomDateTz: () => formatCustomDateTz,
29
+ formatDateKeyTz: () => formatDateKeyTz,
30
+ formatTZ: () => formatTZ,
31
+ getCurrentMonth: () => getCurrentMonth,
32
+ getDateRange: () => getDateRange,
33
+ getEndOfDay: () => getEndOfDay,
34
+ getEndOfMonth: () => getEndOfMonth,
35
+ getNow: () => getNow,
36
+ getPartsInTz: () => getPartsInTz,
37
+ getStartOfDay: () => getStartOfDay,
38
+ getStartOfMonth: () => getStartOfMonth,
39
+ getTimezoneList: () => getTimezoneList,
40
+ getTimezoneOffset: () => getTimezoneOffset,
41
+ getTimezoneParts: () => getTimezoneParts,
42
+ getToday: () => getToday,
43
+ getUserTimezone: () => getUserTimezone,
44
+ isSameDay: () => isSameDay,
45
+ isToday: () => isToday,
46
+ isValidTimezone: () => isValidTimezone,
47
+ nextDayStr: () => nextDayStr,
48
+ pad: () => pad,
49
+ parseInputDate: () => parseInputDate,
50
+ prevDayStr: () => prevDayStr,
51
+ shiftDateStr: () => shiftDateStr,
52
+ tashkentMonth: () => tashkentMonth,
53
+ tashkentNow: () => tashkentNow,
54
+ tashkentTimeStr: () => tashkentTimeStr,
55
+ tashkentToday: () => tashkentToday,
56
+ timeAgo: () => timeAgo
57
+ });
58
+ module.exports = __toCommonJS(tz_exports);
59
+ const formatterCache = /* @__PURE__ */ new Map();
60
+ function getCachedFormatter(locale, options) {
61
+ const key = `${locale}_${JSON.stringify(options)}`;
62
+ if (!formatterCache.has(key)) {
63
+ formatterCache.set(key, new Intl.DateTimeFormat(locale, options));
64
+ }
65
+ return formatterCache.get(key);
66
+ }
67
+ function parseDate(input) {
68
+ if (input instanceof Date) return new Date(input.getTime());
69
+ if (typeof input === "number") return new Date(input);
70
+ if (typeof input === "string") {
71
+ const d = new Date(input);
72
+ if (!isNaN(d.getTime())) return d;
73
+ }
74
+ return /* @__PURE__ */ new Date();
75
+ }
76
+ function pad(n, length = 2) {
77
+ return String(n).padStart(length, "0");
78
+ }
79
+ function getUserTimezone() {
80
+ try {
81
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
82
+ } catch {
83
+ return "UTC";
84
+ }
85
+ }
86
+ function isValidTimezone(timezone) {
87
+ if (!timezone || typeof timezone !== "string") return false;
88
+ try {
89
+ Intl.DateTimeFormat(void 0, { timeZone: timezone });
90
+ return true;
91
+ } catch {
92
+ return false;
93
+ }
94
+ }
95
+ function getTimezoneParts(date, timezone = getUserTimezone()) {
96
+ const d = parseDate(date);
97
+ const formatter = getCachedFormatter("en-US", {
98
+ timeZone: timezone,
99
+ year: "numeric",
100
+ month: "numeric",
101
+ day: "numeric",
102
+ hour: "numeric",
103
+ minute: "numeric",
104
+ second: "numeric",
105
+ fractionalSecondDigits: 3,
106
+ hour12: false,
107
+ weekday: "short"
108
+ });
109
+ const parts = formatter.formatToParts(d);
110
+ const result = {
111
+ year: 0,
112
+ month: 1,
113
+ day: 1,
114
+ hour: 0,
115
+ minute: 0,
116
+ second: 0,
117
+ millisecond: d.getMilliseconds(),
118
+ weekday: d.getDay()
119
+ };
120
+ for (const { type, value } of parts) {
121
+ if (type === "year") result.year = parseInt(value, 10);
122
+ else if (type === "month") result.month = parseInt(value, 10);
123
+ else if (type === "day") result.day = parseInt(value, 10);
124
+ else if (type === "hour") result.hour = parseInt(value, 10) === 24 ? 0 : parseInt(value, 10);
125
+ else if (type === "minute") result.minute = parseInt(value, 10);
126
+ else if (type === "second") result.second = parseInt(value, 10);
127
+ else if (type === "fractionalSecond") result.millisecond = parseInt(value, 10);
128
+ }
129
+ return result;
130
+ }
131
+ function getTimezoneOffset(timezone = getUserTimezone(), date = /* @__PURE__ */ new Date()) {
132
+ const d = parseDate(date);
133
+ try {
134
+ const parts = getTimezoneParts(d, timezone);
135
+ const utcParts = getTimezoneParts(d, "UTC");
136
+ const tzDate = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second);
137
+ const utcDate = Date.UTC(utcParts.year, utcParts.month - 1, utcParts.day, utcParts.hour, utcParts.minute, utcParts.second);
138
+ const diffMinutes = Math.round((tzDate - utcDate) / (1e3 * 60));
139
+ const sign = diffMinutes >= 0 ? "+" : "-";
140
+ const absMin = Math.abs(diffMinutes);
141
+ const hours = String(Math.floor(absMin / 60)).padStart(2, "0");
142
+ const mins = String(absMin % 60).padStart(2, "0");
143
+ const offsetString = `${sign}${hours}:${mins}`;
144
+ return {
145
+ offsetMinutes: diffMinutes,
146
+ offsetString,
147
+ formatted: `UTC${offsetString}`
148
+ };
149
+ } catch {
150
+ return { offsetMinutes: 0, offsetString: "+00:00", formatted: "UTC+00:00" };
151
+ }
152
+ }
153
+ const MONTH_NAMES = {
154
+ en: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
155
+ ru: ["\u042F\u043D\u0432\u0430\u0440\u044C", "\u0424\u0435\u0432\u0440\u0430\u043B\u044C", "\u041C\u0430\u0440\u0442", "\u0410\u043F\u0440\u0435\u043B\u044C", "\u041C\u0430\u0439", "\u0418\u044E\u043D\u044C", "\u0418\u044E\u043B\u044C", "\u0410\u0432\u0433\u0443\u0441\u0442", "\u0421\u0435\u043D\u0442\u044F\u0431\u0440\u044C", "\u041E\u043A\u0442\u044F\u0431\u0440\u044C", "\u041D\u043E\u044F\u0431\u0440\u044C", "\u0414\u0435\u043A\u0430\u0431\u0440\u044C"]
156
+ };
157
+ const MONTH_SHORT = {
158
+ en: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
159
+ ru: ["\u044F\u043D\u0432", "\u0444\u0435\u0432", "\u043C\u0430\u0440", "\u0430\u043F\u0440", "\u043C\u0430\u0439", "\u0438\u044E\u043D", "\u0438\u044E\u043B", "\u0430\u0432\u0433", "\u0441\u0435\u043D", "\u043E\u043A\u0442", "\u043D\u043E\u044F", "\u0434\u0435\u043A"]
160
+ };
161
+ function formatTZ(date, pattern = "YYYY-MM-DD HH:mm:ss", { timezone = getUserTimezone(), locale = "en" } = {}) {
162
+ const d = parseDate(date);
163
+ const p = getTimezoneParts(d, timezone);
164
+ const offset = getTimezoneOffset(timezone, d);
165
+ const lang = MONTH_NAMES[locale] ? locale : "en";
166
+ const monthIdx = p.month - 1;
167
+ const hour12 = p.hour % 12 || 12;
168
+ const isPM = p.hour >= 12;
169
+ const tokens = {
170
+ YYYY: String(p.year),
171
+ YY: String(p.year).slice(-2),
172
+ MMMM: MONTH_NAMES[lang][monthIdx],
173
+ MMM: MONTH_SHORT[lang][monthIdx],
174
+ MM: String(p.month).padStart(2, "0"),
175
+ M: String(p.month),
176
+ DD: String(p.day).padStart(2, "0"),
177
+ D: String(p.day),
178
+ HH: String(p.hour).padStart(2, "0"),
179
+ H: String(p.hour),
180
+ hh: String(hour12).padStart(2, "0"),
181
+ h: String(hour12),
182
+ mm: String(p.minute).padStart(2, "0"),
183
+ m: String(p.minute),
184
+ ss: String(p.second).padStart(2, "0"),
185
+ s: String(p.second),
186
+ SSS: String(p.millisecond).padStart(3, "0"),
187
+ A: isPM ? "PM" : "AM",
188
+ a: isPM ? "pm" : "am",
189
+ ZZ: offset.offsetString,
190
+ Z: offset.offsetString.replace(":", ""),
191
+ z: offset.formatted
192
+ };
193
+ return pattern.replace(/YYYY|YY|MMMM|MMM|MM|M|DD|D|HH|H|hh|h|mm|m|ss|s|SSS|A|a|ZZ|Z|z/g, (match) => tokens[match] || match);
194
+ }
195
+ function timeAgo(date, { baseDate = Date.now(), locale = "en" } = {}) {
196
+ const d = parseDate(date).getTime();
197
+ const base = parseDate(baseDate).getTime();
198
+ const diffSec = Math.round((d - base) / 1e3);
199
+ const rtf = typeof Intl !== "undefined" && Intl.RelativeTimeFormat ? new Intl.RelativeTimeFormat(locale, { numeric: "auto" }) : null;
200
+ const absSec = Math.abs(diffSec);
201
+ if (absSec < 10) {
202
+ return locale.startsWith("ru") ? "\u0442\u043E\u043B\u044C\u043A\u043E \u0447\u0442\u043E" : "just now";
203
+ }
204
+ const units = [
205
+ { name: "year", seconds: 31536e3 },
206
+ { name: "month", seconds: 2592e3 },
207
+ { name: "day", seconds: 86400 },
208
+ { name: "hour", seconds: 3600 },
209
+ { name: "minute", seconds: 60 },
210
+ { name: "second", seconds: 1 }
211
+ ];
212
+ for (const { name, seconds } of units) {
213
+ if (absSec >= seconds || name === "second") {
214
+ const val = Math.round(diffSec / seconds);
215
+ if (rtf) {
216
+ return rtf.format(val, name);
217
+ }
218
+ return `${Math.abs(val)} ${name}${Math.abs(val) > 1 ? "s" : ""} ${diffSec < 0 ? "ago" : "from now"}`;
219
+ }
220
+ }
221
+ return "";
222
+ }
223
+ function getNow(timezone = getUserTimezone()) {
224
+ const d = /* @__PURE__ */ new Date();
225
+ const offset = getTimezoneOffset(timezone, d);
226
+ return new Date(d.getTime() + offset.offsetMinutes * 60 * 1e3);
227
+ }
228
+ function getToday(timezone = getUserTimezone()) {
229
+ const p = getTimezoneParts(/* @__PURE__ */ new Date(), timezone);
230
+ return `${p.year}-${pad(p.month)}-${pad(p.day)}`;
231
+ }
232
+ function getCurrentMonth(timezone = getUserTimezone()) {
233
+ const p = getTimezoneParts(/* @__PURE__ */ new Date(), timezone);
234
+ return `${p.year}-${pad(p.month)}`;
235
+ }
236
+ function shiftDateStr(dateInput, amount = 0, unit = "days") {
237
+ let y, m, d;
238
+ if (typeof dateInput === "string" && /^\d{4}-\d{2}-\d{2}/.test(dateInput)) {
239
+ const parts = dateInput.slice(0, 10).split("-").map(Number);
240
+ y = parts[0];
241
+ m = parts[1];
242
+ d = parts[2];
243
+ } else {
244
+ const parsed = parseDate(dateInput);
245
+ y = parsed.getUTCFullYear();
246
+ m = parsed.getUTCMonth() + 1;
247
+ d = parsed.getUTCDate();
248
+ }
249
+ const dt = new Date(Date.UTC(y, m - 1, d));
250
+ switch (unit) {
251
+ case "years":
252
+ dt.setUTCFullYear(dt.getUTCFullYear() + amount);
253
+ break;
254
+ case "months":
255
+ dt.setUTCMonth(dt.getUTCMonth() + amount);
256
+ break;
257
+ case "days":
258
+ default:
259
+ dt.setUTCDate(dt.getUTCDate() + amount);
260
+ break;
261
+ }
262
+ return `${dt.getUTCFullYear()}-${pad(dt.getUTCMonth() + 1)}-${pad(dt.getUTCDate())}`;
263
+ }
264
+ function prevDayStr(dateStr, count = 1) {
265
+ return shiftDateStr(dateStr, -count, "days");
266
+ }
267
+ function nextDayStr(dateStr, count = 1) {
268
+ return shiftDateStr(dateStr, count, "days");
269
+ }
270
+ function daysBetween(date1, date2) {
271
+ const parseToUtcMidnight = (val) => {
272
+ if (typeof val === "string" && /^\d{4}-\d{2}-\d{2}/.test(val)) {
273
+ const [y, m, d] = val.slice(0, 10).split("-").map(Number);
274
+ return Date.UTC(y, m - 1, d);
275
+ }
276
+ const dt = parseDate(val);
277
+ return Date.UTC(dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate());
278
+ };
279
+ const ms1 = parseToUtcMidnight(date1);
280
+ const ms2 = parseToUtcMidnight(date2);
281
+ return Math.round((ms2 - ms1) / (1e3 * 60 * 60 * 24));
282
+ }
283
+ function getDateRange(startDate, endDate) {
284
+ const startStr = typeof startDate === "string" && /^\d{4}-\d{2}-\d{2}/.test(startDate) ? startDate.slice(0, 10) : formatTZ(startDate, "YYYY-MM-DD");
285
+ const endStr = typeof endDate === "string" && /^\d{4}-\d{2}-\d{2}/.test(endDate) ? endDate.slice(0, 10) : formatTZ(endDate, "YYYY-MM-DD");
286
+ if (startStr > endStr) return [];
287
+ const range = [];
288
+ let curr = startStr;
289
+ while (curr <= endStr) {
290
+ range.push(curr);
291
+ curr = nextDayStr(curr);
292
+ }
293
+ return range;
294
+ }
295
+ function getStartOfMonth(date = /* @__PURE__ */ new Date(), timezone = getUserTimezone()) {
296
+ const p = getTimezoneParts(date, timezone);
297
+ return `${p.year}-${pad(p.month)}-01`;
298
+ }
299
+ function getEndOfMonth(date = /* @__PURE__ */ new Date(), timezone = getUserTimezone()) {
300
+ const p = getTimezoneParts(date, timezone);
301
+ const dt = new Date(Date.UTC(p.year, p.month, 0));
302
+ return `${p.year}-${pad(p.month)}-${pad(dt.getUTCDate())}`;
303
+ }
304
+ function getStartOfDay(date = /* @__PURE__ */ new Date(), timezone = getUserTimezone()) {
305
+ const p = getTimezoneParts(date, timezone);
306
+ const offset = getTimezoneOffset(timezone, new Date(Date.UTC(p.year, p.month - 1, p.day, 12, 0, 0)));
307
+ return new Date(Date.UTC(p.year, p.month - 1, p.day, 0, 0, 0, 0) - offset.offsetMinutes * 60 * 1e3);
308
+ }
309
+ function getEndOfDay(date = /* @__PURE__ */ new Date(), timezone = getUserTimezone()) {
310
+ const p = getTimezoneParts(date, timezone);
311
+ const offset = getTimezoneOffset(timezone, new Date(Date.UTC(p.year, p.month - 1, p.day, 12, 0, 0)));
312
+ return new Date(Date.UTC(p.year, p.month - 1, p.day, 23, 59, 59, 999) - offset.offsetMinutes * 60 * 1e3);
313
+ }
314
+ function addTime(date, amount, unit = "days") {
315
+ const d = parseDate(date);
316
+ switch (unit) {
317
+ case "years":
318
+ d.setFullYear(d.getFullYear() + amount);
319
+ break;
320
+ case "months":
321
+ d.setMonth(d.getMonth() + amount);
322
+ break;
323
+ case "days":
324
+ d.setDate(d.getDate() + amount);
325
+ break;
326
+ case "hours":
327
+ d.setHours(d.getHours() + amount);
328
+ break;
329
+ case "minutes":
330
+ d.setMinutes(d.getMinutes() + amount);
331
+ break;
332
+ case "seconds":
333
+ d.setSeconds(d.getSeconds() + amount);
334
+ break;
335
+ }
336
+ return d;
337
+ }
338
+ function isSameDay(date1, date2, timezone = getUserTimezone()) {
339
+ const p1 = getTimezoneParts(date1, timezone);
340
+ const p2 = getTimezoneParts(date2, timezone);
341
+ return p1.year === p2.year && p1.month === p2.month && p1.day === p2.day;
342
+ }
343
+ function isToday(date, timezone = getUserTimezone()) {
344
+ return isSameDay(date, /* @__PURE__ */ new Date(), timezone);
345
+ }
346
+ const COMMON_TIMEZONES = [
347
+ { value: "Pacific/Midway", label: "(UTC-11:00) Midway Island, Samoa" },
348
+ { value: "Pacific/Honolulu", label: "(UTC-10:00) Hawaii" },
349
+ { value: "America/Anchorage", label: "(UTC-09:00) Alaska" },
350
+ { value: "America/Los_Angeles", label: "(UTC-08:00) Pacific Time (US & Canada)" },
351
+ { value: "America/Denver", label: "(UTC-07:00) Mountain Time (US & Canada)" },
352
+ { value: "America/Chicago", label: "(UTC-06:00) Central Time (US & Canada)" },
353
+ { value: "America/New_York", label: "(UTC-05:00) Eastern Time (US & Canada)" },
354
+ { value: "America/Sao_Paulo", label: "(UTC-03:00) Brasilia, Sao Paulo" },
355
+ { value: "UTC", label: "(UTC+00:00) Universal Coordinated Time, London" },
356
+ { value: "Europe/London", label: "(UTC+00:00) London, Dublin, Edinburgh" },
357
+ { value: "Europe/Paris", label: "(UTC+01:00) Paris, Berlin, Rome, Madrid" },
358
+ { value: "Europe/Kyiv", label: "(UTC+02:00) Kyiv, Helsinki, Athens" },
359
+ { value: "Europe/Moscow", label: "(UTC+03:00) Moscow, St. Petersburg, Istanbul" },
360
+ { value: "Asia/Dubai", label: "(UTC+04:00) Dubai, Abu Dhabi, Baku" },
361
+ { value: "Asia/Tashkent", label: "(UTC+05:00) Tashkent, Samarkand, Islamabad" },
362
+ { value: "Asia/Almaty", label: "(UTC+05:00) Almaty, Astana" },
363
+ { value: "Asia/Dhaka", label: "(UTC+06:00) Dhaka, Novosibirsk" },
364
+ { value: "Asia/Bangkok", label: "(UTC+07:00) Bangkok, Hanoi, Jakarta" },
365
+ { value: "Asia/Singapore", label: "(UTC+08:00) Singapore, Beijing, Hong Kong" },
366
+ { value: "Asia/Tokyo", label: "(UTC+09:00) Tokyo, Seoul" },
367
+ { value: "Australia/Sydney", label: "(UTC+10:00) Sydney, Melbourne" },
368
+ { value: "Pacific/Auckland", label: "(UTC+12:00) Auckland, Wellington" }
369
+ ];
370
+ function getTimezoneList() {
371
+ return COMMON_TIMEZONES.map((tz) => {
372
+ const off = getTimezoneOffset(tz.value);
373
+ return {
374
+ value: tz.value,
375
+ label: tz.label,
376
+ offset: off.offsetString,
377
+ offsetMinutes: off.offsetMinutes
378
+ };
379
+ });
380
+ }
381
+ function tashkentNow() {
382
+ return getNow("Asia/Tashkent");
383
+ }
384
+ function tashkentToday() {
385
+ return getToday("Asia/Tashkent");
386
+ }
387
+ function tashkentMonth() {
388
+ return getCurrentMonth("Asia/Tashkent");
389
+ }
390
+ function tashkentTimeStr() {
391
+ const p = getTimezoneParts(/* @__PURE__ */ new Date(), "Asia/Tashkent");
392
+ return `${pad(p.hour)}:${pad(p.minute)}`;
393
+ }
394
+ const DEFAULT_TIMEZONE = "Asia/Tashkent";
395
+ const DEFAULT_OFFSET = "+05:00";
396
+ const DEFAULT_TZ_LABEL = "GMT+5";
397
+ function formatCustomDateTz(date, timeZone = DEFAULT_TIMEZONE) {
398
+ if (!date) return "";
399
+ const d = new Date(date);
400
+ if (isNaN(d.getTime())) return "";
401
+ const dtf = new Intl.DateTimeFormat("en-US", {
402
+ timeZone,
403
+ month: "short",
404
+ day: "numeric",
405
+ year: "numeric",
406
+ hour: "numeric",
407
+ minute: "2-digit",
408
+ hour12: true
409
+ });
410
+ const parts = dtf.formatToParts(d);
411
+ const partMap = {};
412
+ for (const p of parts) {
413
+ partMap[p.type] = p.value;
414
+ }
415
+ return `${partMap.month} ${partMap.day}, ${partMap.year}, ${partMap.hour}:${partMap.minute} ${partMap.dayPeriod || ""} ${DEFAULT_TZ_LABEL}`.replace(/\s+/g, " ").trim();
416
+ }
417
+ function formatDateKeyTz(date = /* @__PURE__ */ new Date(), timeZone = DEFAULT_TIMEZONE) {
418
+ const d = new Date(date);
419
+ if (isNaN(d.getTime())) return "";
420
+ const dtf = new Intl.DateTimeFormat("en-CA", {
421
+ timeZone,
422
+ year: "numeric",
423
+ month: "2-digit",
424
+ day: "2-digit"
425
+ });
426
+ return dtf.format(d);
427
+ }
428
+ function getPartsInTz(date, timeZone = DEFAULT_TIMEZONE) {
429
+ if (!date) return { date: "", time: "" };
430
+ const d = new Date(date);
431
+ if (isNaN(d.getTime())) return { date: "", time: "" };
432
+ const dtf = new Intl.DateTimeFormat("en-GB", {
433
+ timeZone,
434
+ year: "numeric",
435
+ month: "2-digit",
436
+ day: "2-digit",
437
+ hour: "2-digit",
438
+ minute: "2-digit",
439
+ hour12: false
440
+ });
441
+ const parts = dtf.formatToParts(d);
442
+ const map = {};
443
+ for (const p of parts) map[p.type] = p.value;
444
+ return {
445
+ date: `${map.year}-${map.month}-${map.day}`,
446
+ time: `${map.hour}:${map.minute}`
447
+ };
448
+ }
449
+ function combineToTzIso(dateStr, timeStr = "00:00", offset = DEFAULT_OFFSET) {
450
+ if (!dateStr || !dateStr.trim()) return null;
451
+ const t = timeStr && timeStr.trim() ? timeStr.trim() : "00:00";
452
+ const fullTime = t.length === 5 ? `${t}:00` : t;
453
+ return `${dateStr.trim()}T${fullTime}${offset}`;
454
+ }
455
+ function parseInputDate(input, defaultOffset = DEFAULT_OFFSET) {
456
+ if (!input) return null;
457
+ if (input instanceof Date) return isNaN(input.getTime()) ? null : input;
458
+ let s = String(input).trim();
459
+ if (!s) return null;
460
+ if (!/[zZ]$/.test(s) && !/[+-]\d{2}(:?\d{2})?$/.test(s)) {
461
+ s = `${s}${defaultOffset}`;
462
+ }
463
+ const d = new Date(s);
464
+ return isNaN(d.getTime()) ? null : d;
465
+ }
466
+ var tz_default = {
467
+ pad,
468
+ getUserTimezone,
469
+ isValidTimezone,
470
+ getTimezoneParts,
471
+ getTimezoneOffset,
472
+ formatTZ,
473
+ timeAgo,
474
+ getNow,
475
+ getToday,
476
+ getCurrentMonth,
477
+ shiftDateStr,
478
+ prevDayStr,
479
+ nextDayStr,
480
+ daysBetween,
481
+ getDateRange,
482
+ getStartOfMonth,
483
+ getEndOfMonth,
484
+ getStartOfDay,
485
+ getEndOfDay,
486
+ addTime,
487
+ isSameDay,
488
+ isToday,
489
+ getTimezoneList,
490
+ COMMON_TIMEZONES,
491
+ tashkentNow,
492
+ tashkentToday,
493
+ tashkentMonth,
494
+ tashkentTimeStr,
495
+ DEFAULT_TIMEZONE,
496
+ DEFAULT_OFFSET,
497
+ DEFAULT_TZ_LABEL,
498
+ formatCustomDateTz,
499
+ formatDateKeyTz,
500
+ getPartsInTz,
501
+ combineToTzIso,
502
+ parseInputDate
503
+ };
504
+ // Annotate the CommonJS export names for ESM import in node:
505
+ 0 && (module.exports = {
506
+ COMMON_TIMEZONES,
507
+ DEFAULT_OFFSET,
508
+ DEFAULT_TIMEZONE,
509
+ DEFAULT_TZ_LABEL,
510
+ addTime,
511
+ combineToTzIso,
512
+ daysBetween,
513
+ formatCustomDateTz,
514
+ formatDateKeyTz,
515
+ formatTZ,
516
+ getCurrentMonth,
517
+ getDateRange,
518
+ getEndOfDay,
519
+ getEndOfMonth,
520
+ getNow,
521
+ getPartsInTz,
522
+ getStartOfDay,
523
+ getStartOfMonth,
524
+ getTimezoneList,
525
+ getTimezoneOffset,
526
+ getTimezoneParts,
527
+ getToday,
528
+ getUserTimezone,
529
+ isSameDay,
530
+ isToday,
531
+ isValidTimezone,
532
+ nextDayStr,
533
+ pad,
534
+ parseInputDate,
535
+ prevDayStr,
536
+ shiftDateStr,
537
+ tashkentMonth,
538
+ tashkentNow,
539
+ tashkentTimeStr,
540
+ tashkentToday,
541
+ timeAgo
542
+ });
@@ -0,0 +1,105 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var ui_exports = {};
19
+ __export(ui_exports, {
20
+ cn: () => cn,
21
+ copyToClipboard: () => copyToClipboard,
22
+ default: () => ui_default,
23
+ fmtAgo: () => fmtAgo,
24
+ fmtDate: () => fmtDate
25
+ });
26
+ module.exports = __toCommonJS(ui_exports);
27
+ function cn(...inputs) {
28
+ const classes = [];
29
+ for (let i = 0; i < inputs.length; i++) {
30
+ const arg = inputs[i];
31
+ if (!arg) continue;
32
+ const argType = typeof arg;
33
+ if (argType === "string" || argType === "number") {
34
+ classes.push(arg);
35
+ } else if (Array.isArray(arg)) {
36
+ if (arg.length) {
37
+ const inner = cn(...arg);
38
+ if (inner) classes.push(inner);
39
+ }
40
+ } else if (argType === "object") {
41
+ for (const key in arg) {
42
+ if (Object.prototype.hasOwnProperty.call(arg, key) && arg[key]) {
43
+ classes.push(key);
44
+ }
45
+ }
46
+ }
47
+ }
48
+ return classes.join(" ");
49
+ }
50
+ async function copyToClipboard(text) {
51
+ if (typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
52
+ try {
53
+ await navigator.clipboard.writeText(text);
54
+ return true;
55
+ } catch {
56
+ }
57
+ }
58
+ if (typeof document !== "undefined") {
59
+ try {
60
+ const el = document.createElement("textarea");
61
+ el.value = text;
62
+ el.setAttribute("readonly", "");
63
+ el.style.position = "absolute";
64
+ el.style.left = "-9999px";
65
+ document.body.appendChild(el);
66
+ el.select();
67
+ const successful = document.execCommand("copy");
68
+ document.body.removeChild(el);
69
+ return successful;
70
+ } catch {
71
+ }
72
+ }
73
+ return false;
74
+ }
75
+ function fmtAgo(d) {
76
+ if (!d) return "\u2014";
77
+ const s = Math.floor((Date.now() - new Date(d).getTime()) / 1e3);
78
+ if (isNaN(s)) return "\u2014";
79
+ if (s < 60) return `${Math.max(0, s)}s ago`;
80
+ if (s < 3600) return `${Math.floor(s / 60)}m ago`;
81
+ if (s < 86400) return `${Math.floor(s / 3600)}h ago`;
82
+ return `${Math.floor(s / 86400)}d ago`;
83
+ }
84
+ function fmtDate(d, locale = "ru-RU") {
85
+ if (!d) return "\u2014";
86
+ try {
87
+ const date = new Date(d);
88
+ return isNaN(date.getTime()) ? "\u2014" : date.toLocaleString(locale);
89
+ } catch {
90
+ return "\u2014";
91
+ }
92
+ }
93
+ var ui_default = {
94
+ cn,
95
+ copyToClipboard,
96
+ fmtAgo,
97
+ fmtDate
98
+ };
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ cn,
102
+ copyToClipboard,
103
+ fmtAgo,
104
+ fmtDate
105
+ });