@ztimson/utils 0.22.6 → 0.22.8
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/index.cjs +15 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +15 -58
- package/dist/index.mjs.map +1 -1
- package/dist/time.d.ts +11 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1372,7 +1372,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1372
1372
|
if (timeout) clearTimeout(timeout);
|
|
1373
1373
|
};
|
|
1374
1374
|
}
|
|
1375
|
-
function
|
|
1375
|
+
function adjustTz(date, offset) {
|
|
1376
|
+
const currentOffset = date.getTimezoneOffset();
|
|
1377
|
+
offset = currentOffset - offset * 60;
|
|
1378
|
+
return new Date(date.getTime() + offset * 6e4);
|
|
1379
|
+
}
|
|
1380
|
+
function formatDate(date, format = "YYYY-MM-DD H:mm", tz) {
|
|
1376
1381
|
if (typeof date == "number" || typeof date == "string") date = new Date(date);
|
|
1377
1382
|
function day(num) {
|
|
1378
1383
|
switch (num) {
|
|
@@ -1446,64 +1451,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1446
1451
|
const minutes = offset % 60;
|
|
1447
1452
|
return (offset > 0 ? "-" : "") + `${hours}:${minutes.toString().padStart(2, "0")}`;
|
|
1448
1453
|
}
|
|
1449
|
-
function timezone(
|
|
1450
|
-
|
|
1451
|
-
switch (hours) {
|
|
1452
|
-
case -12:
|
|
1453
|
-
return "IDLW";
|
|
1454
|
-
case -11:
|
|
1455
|
-
return "SST";
|
|
1456
|
-
case -10:
|
|
1457
|
-
return "HST";
|
|
1458
|
-
case -9:
|
|
1459
|
-
return "AKST";
|
|
1460
|
-
case -8:
|
|
1461
|
-
return "PST";
|
|
1462
|
-
case -7:
|
|
1463
|
-
return "MST";
|
|
1464
|
-
case -6:
|
|
1465
|
-
return "CST";
|
|
1466
|
-
case -5:
|
|
1467
|
-
return "EST";
|
|
1468
|
-
case -4:
|
|
1469
|
-
return "AST";
|
|
1470
|
-
case -3:
|
|
1471
|
-
return "ART";
|
|
1472
|
-
case -2:
|
|
1473
|
-
return "FNT";
|
|
1474
|
-
case -1:
|
|
1475
|
-
return "AZOT";
|
|
1476
|
-
case 0:
|
|
1477
|
-
return "UTC";
|
|
1478
|
-
case 1:
|
|
1479
|
-
return "CET";
|
|
1480
|
-
case 2:
|
|
1481
|
-
return "EET";
|
|
1482
|
-
case 3:
|
|
1483
|
-
return "MSK";
|
|
1484
|
-
case 4:
|
|
1485
|
-
return "SAMT";
|
|
1486
|
-
case 5:
|
|
1487
|
-
return "YEKT";
|
|
1488
|
-
case 6:
|
|
1489
|
-
return "OMST";
|
|
1490
|
-
case 7:
|
|
1491
|
-
return "KRAT";
|
|
1492
|
-
case 8:
|
|
1493
|
-
return "CST";
|
|
1494
|
-
case 9:
|
|
1495
|
-
return "JST";
|
|
1496
|
-
case 10:
|
|
1497
|
-
return "AEST";
|
|
1498
|
-
case 11:
|
|
1499
|
-
return "SBT";
|
|
1500
|
-
case 12:
|
|
1501
|
-
return "NZST";
|
|
1502
|
-
default:
|
|
1503
|
-
return "";
|
|
1504
|
-
}
|
|
1454
|
+
function timezone(date2) {
|
|
1455
|
+
return new Intl.DateTimeFormat("en-US", { timeZoneName: "short" }).format(date2).split(" ").pop() || "";
|
|
1505
1456
|
}
|
|
1506
|
-
return format.replaceAll("YYYY", date.getFullYear().toString()).replaceAll("YY", date.getFullYear().toString().slice(2)).replaceAll("MMMM", month(date.getMonth())).replaceAll("MMM", month(date.getMonth()).slice(0, 2)).replaceAll("MM", (date.getMonth() + 1).toString().padStart(2, "0")).replaceAll("M", (date.getMonth() + 1).toString()).replaceAll("DDD", doy(date).toString()).replaceAll("DD", date.getDate().toString().padStart(2, "0")).replaceAll("Do", suffix(date.getDate())).replaceAll("D", date.getDate().toString()).replaceAll("dddd", day(date.getDay())).replaceAll("ddd", day(date.getDay()).slice(0, 2)).replaceAll("dd", date.getDate().toString().padStart(2, "0")).replaceAll("d", date.getDay().toString()).replaceAll("HH", date.getHours().toString().padStart(2, "0")).replaceAll("H", date.getHours().toString()).replaceAll("hh", (date.getHours() > 12 ? date.getHours() - 12 : date.getHours()).toString().padStart(2, "0")).replaceAll("h", (date.getHours() > 12 ? date.getHours() - 12 : date.getHours()).toString()).replaceAll("mm", date.getMinutes().toString().padStart(2, "0")).replaceAll("m", date.getMinutes().toString()).replaceAll("ss", date.getSeconds().toString().padStart(2, "0")).replaceAll("s", date.getSeconds().toString()).replaceAll("SSS", date.getMilliseconds().toString()).replaceAll("SS", date.getMilliseconds().toString().slice(0, 1)).replaceAll("S", date.getMilliseconds().toString()[0]).replaceAll("A", date.getHours() >= 12 ? "PM" : "AM").replaceAll("a", date.getHours() >= 12 ? "pm" : "am").replaceAll("ZZ", tzOffset(date.getTimezoneOffset()).replace(":", "")).replaceAll("Z", tzOffset(date.getTimezoneOffset())).replaceAll("z", timezone(date
|
|
1457
|
+
return format.replaceAll("YYYY", date.getFullYear().toString()).replaceAll("YY", date.getFullYear().toString().slice(2)).replaceAll("MMMM", month(date.getMonth())).replaceAll("MMM", month(date.getMonth()).slice(0, 2)).replaceAll("MM", (date.getMonth() + 1).toString().padStart(2, "0")).replaceAll("M", (date.getMonth() + 1).toString()).replaceAll("DDD", doy(date).toString()).replaceAll("DD", date.getDate().toString().padStart(2, "0")).replaceAll("Do", suffix(date.getDate())).replaceAll("D", date.getDate().toString()).replaceAll("dddd", day(date.getDay())).replaceAll("ddd", day(date.getDay()).slice(0, 2)).replaceAll("dd", date.getDate().toString().padStart(2, "0")).replaceAll("d", date.getDay().toString()).replaceAll("HH", date.getHours().toString().padStart(2, "0")).replaceAll("H", date.getHours().toString()).replaceAll("hh", (date.getHours() > 12 ? date.getHours() - 12 : date.getHours()).toString().padStart(2, "0")).replaceAll("h", (date.getHours() > 12 ? date.getHours() - 12 : date.getHours()).toString()).replaceAll("mm", date.getMinutes().toString().padStart(2, "0")).replaceAll("m", date.getMinutes().toString()).replaceAll("ss", date.getSeconds().toString().padStart(2, "0")).replaceAll("s", date.getSeconds().toString()).replaceAll("SSS", date.getMilliseconds().toString().padEnd(3, "0")).replaceAll("SS", date.getMilliseconds().toString().slice(0, 1).padEnd(2, "0")).replaceAll("S", date.getMilliseconds().toString()[0]).replaceAll("A", date.getHours() >= 12 ? "PM" : "AM").replaceAll("a", date.getHours() >= 12 ? "pm" : "am").replaceAll("ZZ", tzOffset(isNaN(tz) ? date.getTimezoneOffset() : tz).replace(":", "")).replaceAll("Z", tzOffset(isNaN(tz) ? date.getTimezoneOffset() : tz)).replaceAll("z", typeof tz == "string" ? tz : timezone(date));
|
|
1458
|
+
}
|
|
1459
|
+
function instantInterval(fn, interval) {
|
|
1460
|
+
fn();
|
|
1461
|
+
return setInterval(fn, interval);
|
|
1507
1462
|
}
|
|
1508
1463
|
function sleep(ms) {
|
|
1509
1464
|
return new Promise((res) => setTimeout(res, ms));
|
|
@@ -1552,6 +1507,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1552
1507
|
exports2.TypedEmitter = TypedEmitter;
|
|
1553
1508
|
exports2.UnauthorizedError = UnauthorizedError;
|
|
1554
1509
|
exports2.addUnique = addUnique;
|
|
1510
|
+
exports2.adjustTz = adjustTz;
|
|
1555
1511
|
exports2.adjustedInterval = adjustedInterval;
|
|
1556
1512
|
exports2.arrayDiff = arrayDiff;
|
|
1557
1513
|
exports2.caseInsensitiveSort = caseInsensitiveSort;
|
|
@@ -1579,6 +1535,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1579
1535
|
exports2.gravatar = gravatar;
|
|
1580
1536
|
exports2.includes = includes;
|
|
1581
1537
|
exports2.insertAt = insertAt;
|
|
1538
|
+
exports2.instantInterval = instantInterval;
|
|
1582
1539
|
exports2.isEqual = isEqual;
|
|
1583
1540
|
exports2.jwtDecode = jwtDecode;
|
|
1584
1541
|
exports2.makeArray = makeArray;
|