@trackunit/date-and-time-utils 1.11.101 → 1.11.102
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/index.cjs.js +127 -0
- package/index.esm.js +123 -1
- package/package.json +1 -1
- package/src/DateAndTimeUtils.d.ts +60 -0
package/index.cjs.js
CHANGED
|
@@ -137,6 +137,24 @@ const formatDateUtil = (date, format, timeZone, locale) => {
|
|
|
137
137
|
* @returns {string} A formatted string representing the date range.
|
|
138
138
|
*/
|
|
139
139
|
const formatRangeUtil = (range, locale, format) => Intl.DateTimeFormat(locale, format).formatRange(range.start ?? new Date(), range.end ?? new Date());
|
|
140
|
+
/**
|
|
141
|
+
* Formats a {@link TemporalDate} as a short locale-aware calendar day (medium `dateStyle` via
|
|
142
|
+
* {@link formatDateUtil}).
|
|
143
|
+
*
|
|
144
|
+
* @param date - The date to format. `undefined` and invalid Dates yield `""`.
|
|
145
|
+
* @param locale - Optional locale. Falls back to the system locale when omitted.
|
|
146
|
+
* @returns {string} A short date such as `"Mar 7, 2025"` in English.
|
|
147
|
+
* @example
|
|
148
|
+
* formatShortDateUtil(new Date(2025, 2, 7), "en"); // → "Mar 7, 2025"
|
|
149
|
+
* formatShortDateUtil(undefined, "en"); // → ""
|
|
150
|
+
*/
|
|
151
|
+
const formatShortDateUtil = (date, locale) => {
|
|
152
|
+
if (!date)
|
|
153
|
+
return "";
|
|
154
|
+
if (date instanceof Date && Number.isNaN(date.getTime()))
|
|
155
|
+
return "";
|
|
156
|
+
return formatDateUtil(date, { selectFormat: "dateOnly", dateFormat: "medium" }, undefined, locale);
|
|
157
|
+
};
|
|
140
158
|
/**
|
|
141
159
|
* Subtracts a specified number of minutes from a date.
|
|
142
160
|
*
|
|
@@ -1623,11 +1641,116 @@ const parseValidDate = (date) => {
|
|
|
1623
1641
|
}
|
|
1624
1642
|
return null;
|
|
1625
1643
|
};
|
|
1644
|
+
const YYYY_MM_DD_REGEX = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
1645
|
+
/**
|
|
1646
|
+
* Parses a strict `YYYY-MM-DD` string into a `Temporal.PlainDate`.
|
|
1647
|
+
* Returns `null` for any other format or for an invalid calendar day (e.g. `2025-02-30`).
|
|
1648
|
+
*
|
|
1649
|
+
* @param value - The string to parse.
|
|
1650
|
+
* @returns {TemporalPlainDate | null} The parsed calendar day or null.
|
|
1651
|
+
*/
|
|
1652
|
+
const parseYYYYMMDDToPlainDate = (value) => {
|
|
1653
|
+
const match = YYYY_MM_DD_REGEX.exec(value);
|
|
1654
|
+
if (!match)
|
|
1655
|
+
return null;
|
|
1656
|
+
try {
|
|
1657
|
+
return polyfill.Temporal.PlainDate.from({ year: Number(match[1]), month: Number(match[2]), day: Number(match[3]) }, { overflow: "reject" });
|
|
1658
|
+
}
|
|
1659
|
+
catch {
|
|
1660
|
+
return null;
|
|
1661
|
+
}
|
|
1662
|
+
};
|
|
1663
|
+
/**
|
|
1664
|
+
* Converts a {@link TemporalDate} to the `Temporal.PlainDate` representing its calendar day.
|
|
1665
|
+
*
|
|
1666
|
+
* Returns `null` when the input is `undefined` or an invalid `Date`. Delegates to
|
|
1667
|
+
* {@link toZonedDateTimeUtil} so the calendar day matches the rest of this file's conventions
|
|
1668
|
+
* (system time zone for `Date` / `Instant`, the zoned value's own time zone for `ZonedDateTime`).
|
|
1669
|
+
*
|
|
1670
|
+
* @param date - The date to convert.
|
|
1671
|
+
* @returns {TemporalPlainDate | null} The calendar day or null.
|
|
1672
|
+
*/
|
|
1673
|
+
const calendarDayOf = (date) => {
|
|
1674
|
+
if (!date)
|
|
1675
|
+
return null;
|
|
1676
|
+
if (date instanceof Date && Number.isNaN(date.getTime()))
|
|
1677
|
+
return null;
|
|
1678
|
+
return toZonedDateTimeUtil(date).toPlainDate();
|
|
1679
|
+
};
|
|
1680
|
+
/**
|
|
1681
|
+
* Parses a strict `YYYY-MM-DD` string into a {@link Date} at local midnight.
|
|
1682
|
+
*
|
|
1683
|
+
* Unlike `new Date("2025-03-07")` (which parses as UTC midnight and can shift calendar day when
|
|
1684
|
+
* displayed in a non-UTC zone), this returns a Date anchored to the local calendar day.
|
|
1685
|
+
*
|
|
1686
|
+
* @param value - The string to parse.
|
|
1687
|
+
* @returns {Date | null} The local-midnight Date or null when the input is not a valid YYYY-MM-DD.
|
|
1688
|
+
* @example
|
|
1689
|
+
* parseYYYYMMDDUtil("2025-03-07"); // → Date at local midnight on 7 March 2025
|
|
1690
|
+
* parseYYYYMMDDUtil("2025-02-30"); // → null
|
|
1691
|
+
* parseYYYYMMDDUtil("03/07/2025"); // → null
|
|
1692
|
+
*/
|
|
1693
|
+
const parseYYYYMMDDUtil = (value) => {
|
|
1694
|
+
const plain = parseYYYYMMDDToPlainDate(value);
|
|
1695
|
+
if (!plain)
|
|
1696
|
+
return null;
|
|
1697
|
+
return new Date(plain.year, plain.month - 1, plain.day);
|
|
1698
|
+
};
|
|
1699
|
+
/**
|
|
1700
|
+
* Converts a {@link TemporalDate} to a canonical `YYYY-MM-DD` string for its calendar day.
|
|
1701
|
+
*
|
|
1702
|
+
* Time-zone safe replacement for the `date.toISOString().split("T")[0]` pattern which returns
|
|
1703
|
+
* the UTC calendar day instead of the user's local day.
|
|
1704
|
+
*
|
|
1705
|
+
* @param date - The date to convert. `undefined` and invalid Dates yield `""`.
|
|
1706
|
+
* @returns {string} `YYYY-MM-DD` or empty string.
|
|
1707
|
+
* @example
|
|
1708
|
+
* dateToYYYYMMDDUtil(new Date(2025, 2, 7)); // → "2025-03-07"
|
|
1709
|
+
* dateToYYYYMMDDUtil(undefined); // → ""
|
|
1710
|
+
* dateToYYYYMMDDUtil(new Date("invalid")); // → ""
|
|
1711
|
+
*/
|
|
1712
|
+
const dateToYYYYMMDDUtil = (date) => {
|
|
1713
|
+
const plain = calendarDayOf(date);
|
|
1714
|
+
if (!plain)
|
|
1715
|
+
return "";
|
|
1716
|
+
return plain.toString();
|
|
1717
|
+
};
|
|
1718
|
+
/**
|
|
1719
|
+
* Converts a strict `YYYY-MM-DD` string to the ISO timestamp at UTC midnight for that calendar day.
|
|
1720
|
+
*
|
|
1721
|
+
* @param value - A `YYYY-MM-DD` string.
|
|
1722
|
+
* @returns {string | null} ISO timestamp at UTC midnight, or null when the input is not a valid `YYYY-MM-DD`.
|
|
1723
|
+
* @example
|
|
1724
|
+
* YYYYMMDDToUTCMidnightISOUtil("2025-03-07"); // → "2025-03-07T00:00:00.000Z"
|
|
1725
|
+
* YYYYMMDDToUTCMidnightISOUtil("not-a-date"); // → null
|
|
1726
|
+
*/
|
|
1727
|
+
const YYYYMMDDToUTCMidnightISOUtil = (value) => {
|
|
1728
|
+
const plain = parseYYYYMMDDToPlainDate(value);
|
|
1729
|
+
if (!plain)
|
|
1730
|
+
return null;
|
|
1731
|
+
return plain.toZonedDateTime("UTC").toInstant().toString({ smallestUnit: "millisecond" });
|
|
1732
|
+
};
|
|
1733
|
+
/**
|
|
1734
|
+
* Converts a {@link TemporalDate} to the ISO timestamp at UTC midnight for its calendar day.
|
|
1735
|
+
*
|
|
1736
|
+
* @param date - The date to convert. `undefined` and invalid Dates yield `""`.
|
|
1737
|
+
* @returns {string} ISO timestamp at UTC midnight, or empty string for an invalid Date.
|
|
1738
|
+
* @example
|
|
1739
|
+
* dateToUTCMidnightISOUtil(new Date(2025, 2, 7)); // → "2025-03-07T00:00:00.000Z"
|
|
1740
|
+
* dateToUTCMidnightISOUtil(new Date(2025, 2, 7, 14, 30)); // → "2025-03-07T00:00:00.000Z"
|
|
1741
|
+
*/
|
|
1742
|
+
const dateToUTCMidnightISOUtil = (date) => {
|
|
1743
|
+
const plain = calendarDayOf(date);
|
|
1744
|
+
if (!plain)
|
|
1745
|
+
return "";
|
|
1746
|
+
return plain.toZonedDateTime("UTC").toInstant().toString({ smallestUnit: "millisecond" });
|
|
1747
|
+
};
|
|
1626
1748
|
|
|
1627
1749
|
Object.defineProperty(exports, "Temporal", {
|
|
1628
1750
|
enumerable: true,
|
|
1629
1751
|
get: function () { return polyfill.Temporal; }
|
|
1630
1752
|
});
|
|
1753
|
+
exports.YYYYMMDDToUTCMidnightISOUtil = YYYYMMDDToUTCMidnightISOUtil;
|
|
1631
1754
|
exports.addDaysUtil = addDaysUtil;
|
|
1632
1755
|
exports.addHoursUtil = addHoursUtil;
|
|
1633
1756
|
exports.addMinutesUtil = addMinutesUtil;
|
|
@@ -1638,6 +1761,8 @@ exports.convertHoursUtil = convertHoursUtil;
|
|
|
1638
1761
|
exports.convertMillisecondsUtil = convertMillisecondsUtil;
|
|
1639
1762
|
exports.convertMinutesUtil = convertMinutesUtil;
|
|
1640
1763
|
exports.convertSecondsUtil = convertSecondsUtil;
|
|
1764
|
+
exports.dateToUTCMidnightISOUtil = dateToUTCMidnightISOUtil;
|
|
1765
|
+
exports.dateToYYYYMMDDUtil = dateToYYYYMMDDUtil;
|
|
1641
1766
|
exports.dayNameUtil = dayNameUtil;
|
|
1642
1767
|
exports.daysUtil = daysUtil;
|
|
1643
1768
|
exports.differenceInDaysUtil = differenceInDaysUtil;
|
|
@@ -1654,6 +1779,7 @@ exports.endOfMonthUtil = endOfMonthUtil;
|
|
|
1654
1779
|
exports.endOfWeekUtil = endOfWeekUtil;
|
|
1655
1780
|
exports.formatDateUtil = formatDateUtil;
|
|
1656
1781
|
exports.formatRangeUtil = formatRangeUtil;
|
|
1782
|
+
exports.formatShortDateUtil = formatShortDateUtil;
|
|
1657
1783
|
exports.getDurationFormat = getDurationFormat;
|
|
1658
1784
|
exports.getHourCycle = getHourCycle;
|
|
1659
1785
|
exports.getTimeZone = getTimeZone;
|
|
@@ -1673,6 +1799,7 @@ exports.isValidDate = isValidDate;
|
|
|
1673
1799
|
exports.monthNameUtil = monthNameUtil;
|
|
1674
1800
|
exports.monthsUtil = monthsUtil;
|
|
1675
1801
|
exports.parseValidDate = parseValidDate;
|
|
1802
|
+
exports.parseYYYYMMDDUtil = parseYYYYMMDDUtil;
|
|
1676
1803
|
exports.startOfDayUtil = startOfDayUtil;
|
|
1677
1804
|
exports.startOfHourUtil = startOfHourUtil;
|
|
1678
1805
|
exports.startOfMinuteUtil = startOfMinuteUtil;
|
package/index.esm.js
CHANGED
|
@@ -136,6 +136,24 @@ const formatDateUtil = (date, format, timeZone, locale) => {
|
|
|
136
136
|
* @returns {string} A formatted string representing the date range.
|
|
137
137
|
*/
|
|
138
138
|
const formatRangeUtil = (range, locale, format) => Intl.DateTimeFormat(locale, format).formatRange(range.start ?? new Date(), range.end ?? new Date());
|
|
139
|
+
/**
|
|
140
|
+
* Formats a {@link TemporalDate} as a short locale-aware calendar day (medium `dateStyle` via
|
|
141
|
+
* {@link formatDateUtil}).
|
|
142
|
+
*
|
|
143
|
+
* @param date - The date to format. `undefined` and invalid Dates yield `""`.
|
|
144
|
+
* @param locale - Optional locale. Falls back to the system locale when omitted.
|
|
145
|
+
* @returns {string} A short date such as `"Mar 7, 2025"` in English.
|
|
146
|
+
* @example
|
|
147
|
+
* formatShortDateUtil(new Date(2025, 2, 7), "en"); // → "Mar 7, 2025"
|
|
148
|
+
* formatShortDateUtil(undefined, "en"); // → ""
|
|
149
|
+
*/
|
|
150
|
+
const formatShortDateUtil = (date, locale) => {
|
|
151
|
+
if (!date)
|
|
152
|
+
return "";
|
|
153
|
+
if (date instanceof Date && Number.isNaN(date.getTime()))
|
|
154
|
+
return "";
|
|
155
|
+
return formatDateUtil(date, { selectFormat: "dateOnly", dateFormat: "medium" }, undefined, locale);
|
|
156
|
+
};
|
|
139
157
|
/**
|
|
140
158
|
* Subtracts a specified number of minutes from a date.
|
|
141
159
|
*
|
|
@@ -1622,5 +1640,109 @@ const parseValidDate = (date) => {
|
|
|
1622
1640
|
}
|
|
1623
1641
|
return null;
|
|
1624
1642
|
};
|
|
1643
|
+
const YYYY_MM_DD_REGEX = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
1644
|
+
/**
|
|
1645
|
+
* Parses a strict `YYYY-MM-DD` string into a `Temporal.PlainDate`.
|
|
1646
|
+
* Returns `null` for any other format or for an invalid calendar day (e.g. `2025-02-30`).
|
|
1647
|
+
*
|
|
1648
|
+
* @param value - The string to parse.
|
|
1649
|
+
* @returns {TemporalPlainDate | null} The parsed calendar day or null.
|
|
1650
|
+
*/
|
|
1651
|
+
const parseYYYYMMDDToPlainDate = (value) => {
|
|
1652
|
+
const match = YYYY_MM_DD_REGEX.exec(value);
|
|
1653
|
+
if (!match)
|
|
1654
|
+
return null;
|
|
1655
|
+
try {
|
|
1656
|
+
return Temporal.PlainDate.from({ year: Number(match[1]), month: Number(match[2]), day: Number(match[3]) }, { overflow: "reject" });
|
|
1657
|
+
}
|
|
1658
|
+
catch {
|
|
1659
|
+
return null;
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
/**
|
|
1663
|
+
* Converts a {@link TemporalDate} to the `Temporal.PlainDate` representing its calendar day.
|
|
1664
|
+
*
|
|
1665
|
+
* Returns `null` when the input is `undefined` or an invalid `Date`. Delegates to
|
|
1666
|
+
* {@link toZonedDateTimeUtil} so the calendar day matches the rest of this file's conventions
|
|
1667
|
+
* (system time zone for `Date` / `Instant`, the zoned value's own time zone for `ZonedDateTime`).
|
|
1668
|
+
*
|
|
1669
|
+
* @param date - The date to convert.
|
|
1670
|
+
* @returns {TemporalPlainDate | null} The calendar day or null.
|
|
1671
|
+
*/
|
|
1672
|
+
const calendarDayOf = (date) => {
|
|
1673
|
+
if (!date)
|
|
1674
|
+
return null;
|
|
1675
|
+
if (date instanceof Date && Number.isNaN(date.getTime()))
|
|
1676
|
+
return null;
|
|
1677
|
+
return toZonedDateTimeUtil(date).toPlainDate();
|
|
1678
|
+
};
|
|
1679
|
+
/**
|
|
1680
|
+
* Parses a strict `YYYY-MM-DD` string into a {@link Date} at local midnight.
|
|
1681
|
+
*
|
|
1682
|
+
* Unlike `new Date("2025-03-07")` (which parses as UTC midnight and can shift calendar day when
|
|
1683
|
+
* displayed in a non-UTC zone), this returns a Date anchored to the local calendar day.
|
|
1684
|
+
*
|
|
1685
|
+
* @param value - The string to parse.
|
|
1686
|
+
* @returns {Date | null} The local-midnight Date or null when the input is not a valid YYYY-MM-DD.
|
|
1687
|
+
* @example
|
|
1688
|
+
* parseYYYYMMDDUtil("2025-03-07"); // → Date at local midnight on 7 March 2025
|
|
1689
|
+
* parseYYYYMMDDUtil("2025-02-30"); // → null
|
|
1690
|
+
* parseYYYYMMDDUtil("03/07/2025"); // → null
|
|
1691
|
+
*/
|
|
1692
|
+
const parseYYYYMMDDUtil = (value) => {
|
|
1693
|
+
const plain = parseYYYYMMDDToPlainDate(value);
|
|
1694
|
+
if (!plain)
|
|
1695
|
+
return null;
|
|
1696
|
+
return new Date(plain.year, plain.month - 1, plain.day);
|
|
1697
|
+
};
|
|
1698
|
+
/**
|
|
1699
|
+
* Converts a {@link TemporalDate} to a canonical `YYYY-MM-DD` string for its calendar day.
|
|
1700
|
+
*
|
|
1701
|
+
* Time-zone safe replacement for the `date.toISOString().split("T")[0]` pattern which returns
|
|
1702
|
+
* the UTC calendar day instead of the user's local day.
|
|
1703
|
+
*
|
|
1704
|
+
* @param date - The date to convert. `undefined` and invalid Dates yield `""`.
|
|
1705
|
+
* @returns {string} `YYYY-MM-DD` or empty string.
|
|
1706
|
+
* @example
|
|
1707
|
+
* dateToYYYYMMDDUtil(new Date(2025, 2, 7)); // → "2025-03-07"
|
|
1708
|
+
* dateToYYYYMMDDUtil(undefined); // → ""
|
|
1709
|
+
* dateToYYYYMMDDUtil(new Date("invalid")); // → ""
|
|
1710
|
+
*/
|
|
1711
|
+
const dateToYYYYMMDDUtil = (date) => {
|
|
1712
|
+
const plain = calendarDayOf(date);
|
|
1713
|
+
if (!plain)
|
|
1714
|
+
return "";
|
|
1715
|
+
return plain.toString();
|
|
1716
|
+
};
|
|
1717
|
+
/**
|
|
1718
|
+
* Converts a strict `YYYY-MM-DD` string to the ISO timestamp at UTC midnight for that calendar day.
|
|
1719
|
+
*
|
|
1720
|
+
* @param value - A `YYYY-MM-DD` string.
|
|
1721
|
+
* @returns {string | null} ISO timestamp at UTC midnight, or null when the input is not a valid `YYYY-MM-DD`.
|
|
1722
|
+
* @example
|
|
1723
|
+
* YYYYMMDDToUTCMidnightISOUtil("2025-03-07"); // → "2025-03-07T00:00:00.000Z"
|
|
1724
|
+
* YYYYMMDDToUTCMidnightISOUtil("not-a-date"); // → null
|
|
1725
|
+
*/
|
|
1726
|
+
const YYYYMMDDToUTCMidnightISOUtil = (value) => {
|
|
1727
|
+
const plain = parseYYYYMMDDToPlainDate(value);
|
|
1728
|
+
if (!plain)
|
|
1729
|
+
return null;
|
|
1730
|
+
return plain.toZonedDateTime("UTC").toInstant().toString({ smallestUnit: "millisecond" });
|
|
1731
|
+
};
|
|
1732
|
+
/**
|
|
1733
|
+
* Converts a {@link TemporalDate} to the ISO timestamp at UTC midnight for its calendar day.
|
|
1734
|
+
*
|
|
1735
|
+
* @param date - The date to convert. `undefined` and invalid Dates yield `""`.
|
|
1736
|
+
* @returns {string} ISO timestamp at UTC midnight, or empty string for an invalid Date.
|
|
1737
|
+
* @example
|
|
1738
|
+
* dateToUTCMidnightISOUtil(new Date(2025, 2, 7)); // → "2025-03-07T00:00:00.000Z"
|
|
1739
|
+
* dateToUTCMidnightISOUtil(new Date(2025, 2, 7, 14, 30)); // → "2025-03-07T00:00:00.000Z"
|
|
1740
|
+
*/
|
|
1741
|
+
const dateToUTCMidnightISOUtil = (date) => {
|
|
1742
|
+
const plain = calendarDayOf(date);
|
|
1743
|
+
if (!plain)
|
|
1744
|
+
return "";
|
|
1745
|
+
return plain.toZonedDateTime("UTC").toInstant().toString({ smallestUnit: "millisecond" });
|
|
1746
|
+
};
|
|
1625
1747
|
|
|
1626
|
-
export { addDaysUtil, addHoursUtil, addMinutesUtil, addMonthsUtil, addWeeksUtil, addYearsUtil, convertHoursUtil, convertMillisecondsUtil, convertMinutesUtil, convertSecondsUtil, dayNameUtil, daysUtil, differenceInDaysUtil, differenceInHoursUtil, differenceInMinutesUtil, differenceInMonthsUtil, differenceInSecondsUtil, differenceInWeeksUtil, differenceInYearsUtil, endOfDayUtil, endOfHourUtil, endOfMinuteUtil, endOfMonthUtil, endOfWeekUtil, formatDateUtil, formatRangeUtil, getDurationFormat, getHourCycle, getTimeZone, getTimeZoneOffset, getUTCFromTimeZonedUtil, getWeekUtil, isBetweenUtil, isEqualUtil, isFutureUtil, isPastUtil, isSameDayUtil, isSameMonthUtil, isSameWeekUtil, isSameYearUtil, isTodayUtil, isValidDate, monthNameUtil, monthsUtil, parseValidDate, startOfDayUtil, startOfHourUtil, startOfMinuteUtil, startOfMonthUtil, startOfWeekUtil, subtractDaysUtil, subtractHoursUtil, subtractMinutesUtil, subtractMonthsUtil, subtractWeeksUtil, subtractYearsUtil, timeSinceAuto, timeSinceInDays, timeSinceInHours, timeSinceInMinutes, timeSinceInMonths, timeSinceInSeconds, timeSinceInYears, timeZonesAvailable, toDateUtil, toDuration, toInstantUtil, toTemporalUtil, toZonedDateTimeUtil };
|
|
1748
|
+
export { YYYYMMDDToUTCMidnightISOUtil, addDaysUtil, addHoursUtil, addMinutesUtil, addMonthsUtil, addWeeksUtil, addYearsUtil, convertHoursUtil, convertMillisecondsUtil, convertMinutesUtil, convertSecondsUtil, dateToUTCMidnightISOUtil, dateToYYYYMMDDUtil, dayNameUtil, daysUtil, differenceInDaysUtil, differenceInHoursUtil, differenceInMinutesUtil, differenceInMonthsUtil, differenceInSecondsUtil, differenceInWeeksUtil, differenceInYearsUtil, endOfDayUtil, endOfHourUtil, endOfMinuteUtil, endOfMonthUtil, endOfWeekUtil, formatDateUtil, formatRangeUtil, formatShortDateUtil, getDurationFormat, getHourCycle, getTimeZone, getTimeZoneOffset, getUTCFromTimeZonedUtil, getWeekUtil, isBetweenUtil, isEqualUtil, isFutureUtil, isPastUtil, isSameDayUtil, isSameMonthUtil, isSameWeekUtil, isSameYearUtil, isTodayUtil, isValidDate, monthNameUtil, monthsUtil, parseValidDate, parseYYYYMMDDUtil, startOfDayUtil, startOfHourUtil, startOfMinuteUtil, startOfMonthUtil, startOfWeekUtil, subtractDaysUtil, subtractHoursUtil, subtractMinutesUtil, subtractMonthsUtil, subtractWeeksUtil, subtractYearsUtil, timeSinceAuto, timeSinceInDays, timeSinceInHours, timeSinceInMinutes, timeSinceInMonths, timeSinceInSeconds, timeSinceInYears, timeZonesAvailable, toDateUtil, toDuration, toInstantUtil, toTemporalUtil, toZonedDateTimeUtil };
|
package/package.json
CHANGED
|
@@ -93,6 +93,18 @@ export declare const formatDateUtil: (date: TemporalDate, format?: TemporalForma
|
|
|
93
93
|
* @returns {string} A formatted string representing the date range.
|
|
94
94
|
*/
|
|
95
95
|
export declare const formatRangeUtil: (range: DateRange, locale: string, format?: TemporalFormatTypes) => string;
|
|
96
|
+
/**
|
|
97
|
+
* Formats a {@link TemporalDate} as a short locale-aware calendar day (medium `dateStyle` via
|
|
98
|
+
* {@link formatDateUtil}).
|
|
99
|
+
*
|
|
100
|
+
* @param date - The date to format. `undefined` and invalid Dates yield `""`.
|
|
101
|
+
* @param locale - Optional locale. Falls back to the system locale when omitted.
|
|
102
|
+
* @returns {string} A short date such as `"Mar 7, 2025"` in English.
|
|
103
|
+
* @example
|
|
104
|
+
* formatShortDateUtil(new Date(2025, 2, 7), "en"); // → "Mar 7, 2025"
|
|
105
|
+
* formatShortDateUtil(undefined, "en"); // → ""
|
|
106
|
+
*/
|
|
107
|
+
export declare const formatShortDateUtil: (date: TemporalDate | undefined, locale?: string) => string;
|
|
96
108
|
/**
|
|
97
109
|
* Subtracts a specified number of minutes from a date.
|
|
98
110
|
*
|
|
@@ -1038,4 +1050,52 @@ export declare const isValidDate: (date: Date | string | number) => boolean;
|
|
|
1038
1050
|
* @returns {Date | null} - The parsed date or null if the date is invalid.
|
|
1039
1051
|
*/
|
|
1040
1052
|
export declare const parseValidDate: (date: Date | string | number) => Date | null;
|
|
1053
|
+
/**
|
|
1054
|
+
* Parses a strict `YYYY-MM-DD` string into a {@link Date} at local midnight.
|
|
1055
|
+
*
|
|
1056
|
+
* Unlike `new Date("2025-03-07")` (which parses as UTC midnight and can shift calendar day when
|
|
1057
|
+
* displayed in a non-UTC zone), this returns a Date anchored to the local calendar day.
|
|
1058
|
+
*
|
|
1059
|
+
* @param value - The string to parse.
|
|
1060
|
+
* @returns {Date | null} The local-midnight Date or null when the input is not a valid YYYY-MM-DD.
|
|
1061
|
+
* @example
|
|
1062
|
+
* parseYYYYMMDDUtil("2025-03-07"); // → Date at local midnight on 7 March 2025
|
|
1063
|
+
* parseYYYYMMDDUtil("2025-02-30"); // → null
|
|
1064
|
+
* parseYYYYMMDDUtil("03/07/2025"); // → null
|
|
1065
|
+
*/
|
|
1066
|
+
export declare const parseYYYYMMDDUtil: (value: string) => Date | null;
|
|
1067
|
+
/**
|
|
1068
|
+
* Converts a {@link TemporalDate} to a canonical `YYYY-MM-DD` string for its calendar day.
|
|
1069
|
+
*
|
|
1070
|
+
* Time-zone safe replacement for the `date.toISOString().split("T")[0]` pattern which returns
|
|
1071
|
+
* the UTC calendar day instead of the user's local day.
|
|
1072
|
+
*
|
|
1073
|
+
* @param date - The date to convert. `undefined` and invalid Dates yield `""`.
|
|
1074
|
+
* @returns {string} `YYYY-MM-DD` or empty string.
|
|
1075
|
+
* @example
|
|
1076
|
+
* dateToYYYYMMDDUtil(new Date(2025, 2, 7)); // → "2025-03-07"
|
|
1077
|
+
* dateToYYYYMMDDUtil(undefined); // → ""
|
|
1078
|
+
* dateToYYYYMMDDUtil(new Date("invalid")); // → ""
|
|
1079
|
+
*/
|
|
1080
|
+
export declare const dateToYYYYMMDDUtil: (date: TemporalDate | undefined) => string;
|
|
1081
|
+
/**
|
|
1082
|
+
* Converts a strict `YYYY-MM-DD` string to the ISO timestamp at UTC midnight for that calendar day.
|
|
1083
|
+
*
|
|
1084
|
+
* @param value - A `YYYY-MM-DD` string.
|
|
1085
|
+
* @returns {string | null} ISO timestamp at UTC midnight, or null when the input is not a valid `YYYY-MM-DD`.
|
|
1086
|
+
* @example
|
|
1087
|
+
* YYYYMMDDToUTCMidnightISOUtil("2025-03-07"); // → "2025-03-07T00:00:00.000Z"
|
|
1088
|
+
* YYYYMMDDToUTCMidnightISOUtil("not-a-date"); // → null
|
|
1089
|
+
*/
|
|
1090
|
+
export declare const YYYYMMDDToUTCMidnightISOUtil: (value: string) => string | null;
|
|
1091
|
+
/**
|
|
1092
|
+
* Converts a {@link TemporalDate} to the ISO timestamp at UTC midnight for its calendar day.
|
|
1093
|
+
*
|
|
1094
|
+
* @param date - The date to convert. `undefined` and invalid Dates yield `""`.
|
|
1095
|
+
* @returns {string} ISO timestamp at UTC midnight, or empty string for an invalid Date.
|
|
1096
|
+
* @example
|
|
1097
|
+
* dateToUTCMidnightISOUtil(new Date(2025, 2, 7)); // → "2025-03-07T00:00:00.000Z"
|
|
1098
|
+
* dateToUTCMidnightISOUtil(new Date(2025, 2, 7, 14, 30)); // → "2025-03-07T00:00:00.000Z"
|
|
1099
|
+
*/
|
|
1100
|
+
export declare const dateToUTCMidnightISOUtil: (date: TemporalDate | undefined) => string;
|
|
1041
1101
|
export {};
|