@ztimson/utils 0.22.7 → 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 +14 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +14 -5
- 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) {
|
|
@@ -1447,11 +1452,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1447
1452
|
return (offset > 0 ? "-" : "") + `${hours}:${minutes.toString().padStart(2, "0")}`;
|
|
1448
1453
|
}
|
|
1449
1454
|
function timezone(date2) {
|
|
1450
|
-
|
|
1451
|
-
const formattedDate = formatter.format(date2);
|
|
1452
|
-
return formattedDate.split(" ").pop() || "";
|
|
1455
|
+
return new Intl.DateTimeFormat("en-US", { timeZoneName: "short" }).format(date2).split(" ").pop() || "";
|
|
1453
1456
|
}
|
|
1454
|
-
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);
|
|
1455
1462
|
}
|
|
1456
1463
|
function sleep(ms) {
|
|
1457
1464
|
return new Promise((res) => setTimeout(res, ms));
|
|
@@ -1500,6 +1507,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1500
1507
|
exports2.TypedEmitter = TypedEmitter;
|
|
1501
1508
|
exports2.UnauthorizedError = UnauthorizedError;
|
|
1502
1509
|
exports2.addUnique = addUnique;
|
|
1510
|
+
exports2.adjustTz = adjustTz;
|
|
1503
1511
|
exports2.adjustedInterval = adjustedInterval;
|
|
1504
1512
|
exports2.arrayDiff = arrayDiff;
|
|
1505
1513
|
exports2.caseInsensitiveSort = caseInsensitiveSort;
|
|
@@ -1527,6 +1535,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1527
1535
|
exports2.gravatar = gravatar;
|
|
1528
1536
|
exports2.includes = includes;
|
|
1529
1537
|
exports2.insertAt = insertAt;
|
|
1538
|
+
exports2.instantInterval = instantInterval;
|
|
1530
1539
|
exports2.isEqual = isEqual;
|
|
1531
1540
|
exports2.jwtDecode = jwtDecode;
|
|
1532
1541
|
exports2.makeArray = makeArray;
|