@trackunit/react-date-and-time-hooks 1.21.4 → 1.21.6

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 CHANGED
@@ -486,6 +486,14 @@ const useDateAndTime = () => {
486
486
  const getUTCFromTimeZonedDate = react.useCallback((from, timeZoneId) => {
487
487
  return dateAndTimeUtils.getUTCFromTimeZonedUtil(from, timeZoneId);
488
488
  }, []);
489
+ /**
490
+ * Formats a {@link Date} as a short locale-aware calendar day using the hook's current locale.
491
+ *
492
+ * @param {Date | undefined} date - The date to format.
493
+ * @returns {string} Short date such as `"Mar 7, 2025"` (English), or `""` when the input is
494
+ * `undefined` or an invalid Date.
495
+ */
496
+ const formatShortDate = react.useCallback((date) => dateAndTimeUtils.formatShortDateUtil(date, currentLocale), [currentLocale]);
489
497
  return react.useMemo(() => ({
490
498
  getNowDate,
491
499
  nowDate,
@@ -508,6 +516,11 @@ const useDateAndTime = () => {
508
516
  dayName,
509
517
  days,
510
518
  getUTCFromTimeZonedDate,
519
+ parseYYYYMMDD: dateAndTimeUtils.parseYYYYMMDDUtil,
520
+ dateToYYYYMMDD: dateAndTimeUtils.dateToYYYYMMDDUtil,
521
+ YYYYMMDDToUTCMidnightISO: dateAndTimeUtils.YYYYMMDDToUTCMidnightISOUtil,
522
+ dateToUTCMidnightISO: dateAndTimeUtils.dateToUTCMidnightISOUtil,
523
+ formatShortDate,
511
524
  }), [
512
525
  add,
513
526
  convert,
@@ -520,6 +533,7 @@ const useDateAndTime = () => {
520
533
  formatDate,
521
534
  formatDateWithTimezone,
522
535
  formatRange,
536
+ formatShortDate,
523
537
  getNowDate,
524
538
  getUTCFromTimeZonedDate,
525
539
  monthName,
package/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getTimeZone, Temporal, toDateUtil, toZonedDateTimeUtil, formatDateUtil, formatRangeUtil, subtractYearsUtil, subtractMonthsUtil, subtractWeeksUtil, subtractDaysUtil, subtractHoursUtil, subtractMinutesUtil, addYearsUtil, addMonthsUtil, addWeeksUtil, addDaysUtil, addHoursUtil, addMinutesUtil, startOfMonthUtil, startOfWeekUtil, startOfDayUtil, startOfHourUtil, startOfMinuteUtil, endOfMonthUtil, endOfWeekUtil, endOfDayUtil, endOfHourUtil, endOfMinuteUtil, differenceInYearsUtil, differenceInMonthsUtil, differenceInWeeksUtil, differenceInDaysUtil, differenceInHoursUtil, differenceInMinutesUtil, differenceInSecondsUtil, isBetweenUtil, isTodayUtil, isFutureUtil, isPastUtil, isSameYearUtil, isSameMonthUtil, isSameWeekUtil, isSameDayUtil, timeSinceInYears, timeSinceInMonths, timeSinceInDays, timeSinceInHours, timeSinceInMinutes, timeSinceInSeconds, timeSinceAuto, toDuration, getDurationFormat, convertMillisecondsUtil, convertSecondsUtil, convertMinutesUtil, convertHoursUtil, dayNameUtil, daysUtil, monthNameUtil, monthsUtil, getUTCFromTimeZonedUtil, isEqualUtil } from '@trackunit/date-and-time-utils';
1
+ import { getTimeZone, Temporal, toDateUtil, toZonedDateTimeUtil, formatDateUtil, formatRangeUtil, subtractYearsUtil, subtractMonthsUtil, subtractWeeksUtil, subtractDaysUtil, subtractHoursUtil, subtractMinutesUtil, addYearsUtil, addMonthsUtil, addWeeksUtil, addDaysUtil, addHoursUtil, addMinutesUtil, startOfMonthUtil, startOfWeekUtil, startOfDayUtil, startOfHourUtil, startOfMinuteUtil, endOfMonthUtil, endOfWeekUtil, endOfDayUtil, endOfHourUtil, endOfMinuteUtil, differenceInYearsUtil, differenceInMonthsUtil, differenceInWeeksUtil, differenceInDaysUtil, differenceInHoursUtil, differenceInMinutesUtil, differenceInSecondsUtil, isBetweenUtil, isTodayUtil, isFutureUtil, isPastUtil, isSameYearUtil, isSameMonthUtil, isSameWeekUtil, isSameDayUtil, timeSinceInYears, timeSinceInMonths, timeSinceInDays, timeSinceInHours, timeSinceInMinutes, timeSinceInSeconds, timeSinceAuto, toDuration, getDurationFormat, convertMillisecondsUtil, convertSecondsUtil, convertMinutesUtil, convertHoursUtil, dayNameUtil, daysUtil, monthNameUtil, monthsUtil, getUTCFromTimeZonedUtil, formatShortDateUtil, dateToUTCMidnightISOUtil, YYYYMMDDToUTCMidnightISOUtil, dateToYYYYMMDDUtil, parseYYYYMMDDUtil, isEqualUtil } from '@trackunit/date-and-time-utils';
2
2
  import { exhaustiveCheck } from '@trackunit/shared-utils';
3
3
  import { useMemo, useCallback } from 'react';
4
4
  import { TimeZonePreference } from '@trackunit/iris-app-runtime-core-api';
@@ -484,6 +484,14 @@ const useDateAndTime = () => {
484
484
  const getUTCFromTimeZonedDate = useCallback((from, timeZoneId) => {
485
485
  return getUTCFromTimeZonedUtil(from, timeZoneId);
486
486
  }, []);
487
+ /**
488
+ * Formats a {@link Date} as a short locale-aware calendar day using the hook's current locale.
489
+ *
490
+ * @param {Date | undefined} date - The date to format.
491
+ * @returns {string} Short date such as `"Mar 7, 2025"` (English), or `""` when the input is
492
+ * `undefined` or an invalid Date.
493
+ */
494
+ const formatShortDate = useCallback((date) => formatShortDateUtil(date, currentLocale), [currentLocale]);
487
495
  return useMemo(() => ({
488
496
  getNowDate,
489
497
  nowDate,
@@ -506,6 +514,11 @@ const useDateAndTime = () => {
506
514
  dayName,
507
515
  days,
508
516
  getUTCFromTimeZonedDate,
517
+ parseYYYYMMDD: parseYYYYMMDDUtil,
518
+ dateToYYYYMMDD: dateToYYYYMMDDUtil,
519
+ YYYYMMDDToUTCMidnightISO: YYYYMMDDToUTCMidnightISOUtil,
520
+ dateToUTCMidnightISO: dateToUTCMidnightISOUtil,
521
+ formatShortDate,
509
522
  }), [
510
523
  add,
511
524
  convert,
@@ -518,6 +531,7 @@ const useDateAndTime = () => {
518
531
  formatDate,
519
532
  formatDateWithTimezone,
520
533
  formatRange,
534
+ formatShortDate,
521
535
  getNowDate,
522
536
  getUTCFromTimeZonedDate,
523
537
  monthName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-date-and-time-hooks",
3
- "version": "1.21.4",
3
+ "version": "1.21.6",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -10,14 +10,14 @@
10
10
  "@graphql-codegen/cli": "^5.0.3",
11
11
  "@graphql-typed-document-node/core": "^3.2.0",
12
12
  "zod": "^3.25.76",
13
- "@trackunit/iris-app-api": "1.17.4",
14
- "@trackunit/react-core-contexts-test": "1.15.14",
15
- "@trackunit/date-and-time-utils": "1.11.101",
16
- "@trackunit/shared-utils": "1.13.99",
17
- "@trackunit/react-core-hooks": "1.15.14",
18
- "@trackunit/react-components": "1.22.2",
19
- "@trackunit/react-graphql-hooks": "1.22.2",
20
- "@trackunit/iris-app-runtime-core-api": "1.14.13"
13
+ "@trackunit/iris-app-api": "1.17.5",
14
+ "@trackunit/react-core-contexts-test": "1.15.15",
15
+ "@trackunit/date-and-time-utils": "1.11.103",
16
+ "@trackunit/shared-utils": "1.13.100",
17
+ "@trackunit/react-core-hooks": "1.15.15",
18
+ "@trackunit/react-components": "1.22.3",
19
+ "@trackunit/react-graphql-hooks": "1.22.3",
20
+ "@trackunit/iris-app-runtime-core-api": "1.14.14"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@apollo/client": "^3.13.8",
@@ -34,6 +34,32 @@ interface UseDateAndTimeReturn {
34
34
  months: (format?: TemporalFormatStyle) => Array<string>;
35
35
  getUTCFromTimeZonedDate: (from: Date, timeZoneId: string) => Date;
36
36
  isEqual: (date1: TemporalDate, date2: TemporalDate) => boolean;
37
+ /**
38
+ * Parses a strict `YYYY-MM-DD` string into a local-midnight {@link Date}. Returns `null` for
39
+ * any other format or for an invalid calendar day.
40
+ */
41
+ parseYYYYMMDD: (value: string) => Date | null;
42
+ /**
43
+ * Converts a {@link Date} to the canonical `YYYY-MM-DD` string for its local calendar day.
44
+ * Time-zone safe replacement for `date.toISOString().split("T")[0]`. `undefined` and invalid
45
+ * Dates yield `""`.
46
+ */
47
+ dateToYYYYMMDD: (date: Date | undefined) => string;
48
+ /**
49
+ * Converts a strict `YYYY-MM-DD` string to the ISO timestamp at UTC midnight for that day.
50
+ * Returns `null` for invalid input.
51
+ */
52
+ YYYYMMDDToUTCMidnightISO: (value: string) => string | null;
53
+ /**
54
+ * Converts a {@link Date} to the ISO timestamp at UTC midnight for its local calendar day.
55
+ * Invalid Dates yield `""`.
56
+ */
57
+ dateToUTCMidnightISO: (date: Date) => string;
58
+ /**
59
+ * Formats a {@link Date} as a short locale-aware calendar day using the hook's current locale
60
+ * (e.g. `"Mar 7, 2025"` in English). `undefined` and invalid Dates yield `""`.
61
+ */
62
+ formatShortDate: (date: Date | undefined) => string;
37
63
  }
38
64
  /**
39
65
  * Hook for managing date and time operations.