@trackunit/date-and-time-utils 1.10.26 → 1.11.7
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 +14 -0
- package/index.esm.js +14 -1
- package/package.json +1 -1
- package/src/DateAndTimeUtils.d.ts +8 -0
package/index.cjs.js
CHANGED
|
@@ -1609,11 +1609,24 @@ const startOfWeek = (date, weekStartsOn) => {
|
|
|
1609
1609
|
/**
|
|
1610
1610
|
*
|
|
1611
1611
|
* @param date - The date to check if it is valid.
|
|
1612
|
+
* @returns {boolean} - True if the date is valid, false otherwise.
|
|
1612
1613
|
*/
|
|
1613
1614
|
const isValidDate = (date) => {
|
|
1614
1615
|
const isDate = new Date(date).getTime();
|
|
1615
1616
|
return !isNaN(isDate);
|
|
1616
1617
|
};
|
|
1618
|
+
/**
|
|
1619
|
+
* Parses a date, if it is valid, returns a valid Date object, otherwise returns null.
|
|
1620
|
+
*
|
|
1621
|
+
* @param date - The date to parse.
|
|
1622
|
+
* @returns {Date | null} - The parsed date or null if the date is invalid.
|
|
1623
|
+
*/
|
|
1624
|
+
const parseValidDate = (date) => {
|
|
1625
|
+
if (isValidDate(date)) {
|
|
1626
|
+
return new Date(date);
|
|
1627
|
+
}
|
|
1628
|
+
return null;
|
|
1629
|
+
};
|
|
1617
1630
|
|
|
1618
1631
|
exports.addDaysUtil = addDaysUtil;
|
|
1619
1632
|
exports.addHoursUtil = addHoursUtil;
|
|
@@ -1659,6 +1672,7 @@ exports.isTodayUtil = isTodayUtil;
|
|
|
1659
1672
|
exports.isValidDate = isValidDate;
|
|
1660
1673
|
exports.monthNameUtil = monthNameUtil;
|
|
1661
1674
|
exports.monthsUtil = monthsUtil;
|
|
1675
|
+
exports.parseValidDate = parseValidDate;
|
|
1662
1676
|
exports.startOfDayUtil = startOfDayUtil;
|
|
1663
1677
|
exports.startOfHourUtil = startOfHourUtil;
|
|
1664
1678
|
exports.startOfMinuteUtil = startOfMinuteUtil;
|
package/index.esm.js
CHANGED
|
@@ -1607,10 +1607,23 @@ const startOfWeek = (date, weekStartsOn) => {
|
|
|
1607
1607
|
/**
|
|
1608
1608
|
*
|
|
1609
1609
|
* @param date - The date to check if it is valid.
|
|
1610
|
+
* @returns {boolean} - True if the date is valid, false otherwise.
|
|
1610
1611
|
*/
|
|
1611
1612
|
const isValidDate = (date) => {
|
|
1612
1613
|
const isDate = new Date(date).getTime();
|
|
1613
1614
|
return !isNaN(isDate);
|
|
1614
1615
|
};
|
|
1616
|
+
/**
|
|
1617
|
+
* Parses a date, if it is valid, returns a valid Date object, otherwise returns null.
|
|
1618
|
+
*
|
|
1619
|
+
* @param date - The date to parse.
|
|
1620
|
+
* @returns {Date | null} - The parsed date or null if the date is invalid.
|
|
1621
|
+
*/
|
|
1622
|
+
const parseValidDate = (date) => {
|
|
1623
|
+
if (isValidDate(date)) {
|
|
1624
|
+
return new Date(date);
|
|
1625
|
+
}
|
|
1626
|
+
return null;
|
|
1627
|
+
};
|
|
1615
1628
|
|
|
1616
|
-
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, startOfDayUtil, startOfHourUtil, startOfMinuteUtil, startOfMonthUtil, startOfWeekUtil, subtractDaysUtil, subtractHoursUtil, subtractMinutesUtil, subtractMonthsUtil, subtractWeeksUtil, subtractYearsUtil, timeSinceAuto, timeSinceInDays, timeSinceInHours, timeSinceInMinutes, timeSinceInMonths, timeSinceInSeconds, timeSinceInYears, timeZonesAvailable, toDateUtil, toDuration, toInstantUtil, toTemporalUtil, toZonedDateTimeUtil };
|
|
1629
|
+
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 };
|
package/package.json
CHANGED
|
@@ -1029,6 +1029,14 @@ export declare const convertHoursUtil: (hours: number, unit: Extract<Temporal.Ti
|
|
|
1029
1029
|
/**
|
|
1030
1030
|
*
|
|
1031
1031
|
* @param date - The date to check if it is valid.
|
|
1032
|
+
* @returns {boolean} - True if the date is valid, false otherwise.
|
|
1032
1033
|
*/
|
|
1033
1034
|
export declare const isValidDate: (date: Date | string | number) => boolean;
|
|
1035
|
+
/**
|
|
1036
|
+
* Parses a date, if it is valid, returns a valid Date object, otherwise returns null.
|
|
1037
|
+
*
|
|
1038
|
+
* @param date - The date to parse.
|
|
1039
|
+
* @returns {Date | null} - The parsed date or null if the date is invalid.
|
|
1040
|
+
*/
|
|
1041
|
+
export declare const parseValidDate: (date: Date | string | number) => Date | null;
|
|
1034
1042
|
export {};
|