@ztimson/utils 0.23.7 → 0.23.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 +40 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +40 -56
- package/dist/index.mjs.map +1 -1
- package/dist/time.d.ts +3 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1531,7 +1531,7 @@ ${opts.message || this.desc}`;
|
|
|
1531
1531
|
if (timeout) clearTimeout(timeout);
|
|
1532
1532
|
};
|
|
1533
1533
|
}
|
|
1534
|
-
function formatDate(
|
|
1534
|
+
function formatDate(format = "YYYY-MM-DD H:mm", date = /* @__PURE__ */ new Date(), tz) {
|
|
1535
1535
|
const timezones = [
|
|
1536
1536
|
["IDLW", -12],
|
|
1537
1537
|
["SST", -11],
|
|
@@ -1568,70 +1568,26 @@ ${opts.message || this.desc}`;
|
|
|
1568
1568
|
return new Date(date2.getTime() + (adjustedOffset + currentOffset) * 6e4);
|
|
1569
1569
|
}
|
|
1570
1570
|
function day(num) {
|
|
1571
|
-
|
|
1572
|
-
case 0:
|
|
1573
|
-
return "Sunday";
|
|
1574
|
-
case 1:
|
|
1575
|
-
return "Monday";
|
|
1576
|
-
case 2:
|
|
1577
|
-
return "Tuesday";
|
|
1578
|
-
case 3:
|
|
1579
|
-
return "Wednesday";
|
|
1580
|
-
case 4:
|
|
1581
|
-
return "Thursday";
|
|
1582
|
-
case 5:
|
|
1583
|
-
return "Friday";
|
|
1584
|
-
case 6:
|
|
1585
|
-
return "Saturday";
|
|
1586
|
-
default:
|
|
1587
|
-
return "Unknown";
|
|
1588
|
-
}
|
|
1571
|
+
return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][num] || "Unknown";
|
|
1589
1572
|
}
|
|
1590
1573
|
function doy(date2) {
|
|
1591
1574
|
const start = /* @__PURE__ */ new Date(`${date2.getFullYear()}-01-01 0:00:00`);
|
|
1592
1575
|
return Math.ceil((date2.getTime() - start.getTime()) / (1e3 * 60 * 60 * 24));
|
|
1593
1576
|
}
|
|
1594
1577
|
function month(num) {
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1578
|
+
return ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][num] || "Unknown";
|
|
1579
|
+
}
|
|
1580
|
+
function suffix(num) {
|
|
1581
|
+
if (num % 100 >= 11 && num % 100 <= 13) return `${num}th`;
|
|
1582
|
+
switch (num % 10) {
|
|
1598
1583
|
case 1:
|
|
1599
|
-
return
|
|
1584
|
+
return `${num}st`;
|
|
1600
1585
|
case 2:
|
|
1601
|
-
return
|
|
1586
|
+
return `${num}nd`;
|
|
1602
1587
|
case 3:
|
|
1603
|
-
return
|
|
1604
|
-
case 4:
|
|
1605
|
-
return "May";
|
|
1606
|
-
case 5:
|
|
1607
|
-
return "June";
|
|
1608
|
-
case 6:
|
|
1609
|
-
return "July";
|
|
1610
|
-
case 7:
|
|
1611
|
-
return "August";
|
|
1612
|
-
case 8:
|
|
1613
|
-
return "September";
|
|
1614
|
-
case 9:
|
|
1615
|
-
return "October";
|
|
1616
|
-
case 10:
|
|
1617
|
-
return "November";
|
|
1618
|
-
case 11:
|
|
1619
|
-
return "December";
|
|
1620
|
-
default:
|
|
1621
|
-
return "Unknown";
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
function suffix(num) {
|
|
1625
|
-
let n = num.toString();
|
|
1626
|
-
switch (n.at(-1)) {
|
|
1627
|
-
case "1":
|
|
1628
|
-
return num + "st";
|
|
1629
|
-
case "2":
|
|
1630
|
-
return num + "nd";
|
|
1631
|
-
case "3":
|
|
1632
|
-
return num + "rd";
|
|
1588
|
+
return `${num}rd`;
|
|
1633
1589
|
default:
|
|
1634
|
-
return num
|
|
1590
|
+
return `${num}th`;
|
|
1635
1591
|
}
|
|
1636
1592
|
}
|
|
1637
1593
|
function tzOffset(offset) {
|
|
@@ -1645,7 +1601,35 @@ ${opts.message || this.desc}`;
|
|
|
1645
1601
|
t = timezones.find((t2) => isNaN(tz) ? t2[0] == tz : t2[1] == tz);
|
|
1646
1602
|
if (!t) throw new Error(`Unknown timezone: ${tz}`);
|
|
1647
1603
|
date = adjustTz(date, t[1]);
|
|
1648
|
-
|
|
1604
|
+
const tokens = {
|
|
1605
|
+
"YYYY": date.getFullYear().toString(),
|
|
1606
|
+
"YY": date.getFullYear().toString().slice(2),
|
|
1607
|
+
"MMMM": month(date.getMonth()),
|
|
1608
|
+
"MMM": month(date.getMonth()).slice(0, 3),
|
|
1609
|
+
"MM": (date.getMonth() + 1).toString().padStart(2, "0"),
|
|
1610
|
+
"M": (date.getMonth() + 1).toString(),
|
|
1611
|
+
"DDD": doy(date).toString(),
|
|
1612
|
+
"DD": date.getDate().toString().padStart(2, "0"),
|
|
1613
|
+
"Do": suffix(date.getDate()),
|
|
1614
|
+
"D": date.getDate().toString(),
|
|
1615
|
+
"dddd": day(date.getDay()),
|
|
1616
|
+
"ddd": day(date.getDay()).slice(0, 3),
|
|
1617
|
+
"HH": date.getHours().toString().padStart(2, "0"),
|
|
1618
|
+
"H": date.getHours().toString(),
|
|
1619
|
+
"hh": (date.getHours() % 12 || 12).toString().padStart(2, "0"),
|
|
1620
|
+
"h": (date.getHours() % 12 || 12).toString(),
|
|
1621
|
+
"mm": date.getMinutes().toString().padStart(2, "0"),
|
|
1622
|
+
"m": date.getMinutes().toString(),
|
|
1623
|
+
"ss": date.getSeconds().toString().padStart(2, "0"),
|
|
1624
|
+
"s": date.getSeconds().toString(),
|
|
1625
|
+
"SSS": date.getMilliseconds().toString().padStart(3, "0"),
|
|
1626
|
+
"A": date.getHours() >= 12 ? "PM" : "AM",
|
|
1627
|
+
"a": date.getHours() >= 12 ? "pm" : "am",
|
|
1628
|
+
"ZZ": tzOffset(t[1] * 60).replace(":", ""),
|
|
1629
|
+
"Z": tzOffset(t[1] * 60),
|
|
1630
|
+
"z": typeof tz == "string" ? tz : t[0]
|
|
1631
|
+
};
|
|
1632
|
+
return format.replace(/YYYY|YY|MMMM|MMM|MM|M|DDD|DD|Do|D|dddd|ddd|HH|H|hh|h|mm|m|ss|s|SSS|A|a|ZZ|Z|z/g, (token) => tokens[token]);
|
|
1649
1633
|
}
|
|
1650
1634
|
function instantInterval(fn, interval) {
|
|
1651
1635
|
fn();
|