@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.mjs CHANGED
@@ -1368,7 +1368,12 @@ function adjustedInterval(cb, ms) {
1368
1368
  if (timeout) clearTimeout(timeout);
1369
1369
  };
1370
1370
  }
1371
- function formatDate(date, format = "YYYY-MM-DD H:mm ") {
1371
+ function adjustTz(date, offset) {
1372
+ const currentOffset = date.getTimezoneOffset();
1373
+ offset = currentOffset - offset * 60;
1374
+ return new Date(date.getTime() + offset * 6e4);
1375
+ }
1376
+ function formatDate(date, format = "YYYY-MM-DD H:mm", tz) {
1372
1377
  if (typeof date == "number" || typeof date == "string") date = new Date(date);
1373
1378
  function day(num) {
1374
1379
  switch (num) {
@@ -1443,11 +1448,13 @@ function formatDate(date, format = "YYYY-MM-DD H:mm ") {
1443
1448
  return (offset > 0 ? "-" : "") + `${hours}:${minutes.toString().padStart(2, "0")}`;
1444
1449
  }
1445
1450
  function timezone(date2) {
1446
- const formatter = new Intl.DateTimeFormat("en-US", { timeZoneName: "short" });
1447
- const formattedDate = formatter.format(date2);
1448
- return formattedDate.split(" ").pop() || "";
1451
+ return new Intl.DateTimeFormat("en-US", { timeZoneName: "short" }).format(date2).split(" ").pop() || "";
1449
1452
  }
1450
- 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));
1453
+ 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));
1454
+ }
1455
+ function instantInterval(fn, interval) {
1456
+ fn();
1457
+ return setInterval(fn, interval);
1451
1458
  }
1452
1459
  function sleep(ms) {
1453
1460
  return new Promise((res) => setTimeout(res, ms));
@@ -1497,6 +1504,7 @@ export {
1497
1504
  TypedEmitter,
1498
1505
  UnauthorizedError,
1499
1506
  addUnique,
1507
+ adjustTz,
1500
1508
  adjustedInterval,
1501
1509
  arrayDiff,
1502
1510
  caseInsensitiveSort,
@@ -1524,6 +1532,7 @@ export {
1524
1532
  gravatar,
1525
1533
  includes,
1526
1534
  insertAt,
1535
+ instantInterval,
1527
1536
  isEqual,
1528
1537
  jwtDecode,
1529
1538
  makeArray,