@trackunit/react-date-and-time-hooks 1.21.0 → 1.21.2

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
@@ -154,12 +154,10 @@ const useDateAndTime = () => {
154
154
  const currentLocale = useLocale();
155
155
  const { current, assetTimeZone, preferred } = useTimezone();
156
156
  const currentTimeZone = react.useMemo(() => current.id || preferred.id || assetTimeZone?.id, [current, assetTimeZone, preferred]);
157
+ const getNowDate = react.useCallback(() => {
158
+ return dateAndTimeUtils.toDateUtil(dateAndTimeUtils.toZonedDateTimeUtil(dateAndTimeUtils.Temporal.Now.instant(), currentTimeZone));
159
+ }, [currentTimeZone]);
157
160
  const currentDate = react.useMemo(() => dateAndTimeUtils.toZonedDateTimeUtil(dateAndTimeUtils.Temporal.Now.instant(), currentTimeZone), [currentTimeZone]);
158
- /**
159
- * Returns the current date and time.
160
- *
161
- * @returns {Date}
162
- */
163
161
  const nowDate = react.useMemo(() => dateAndTimeUtils.toDateUtil(currentDate), [currentDate]);
164
162
  /**
165
163
  * Formats a date using the current locale and time zone.
@@ -489,6 +487,7 @@ const useDateAndTime = () => {
489
487
  return dateAndTimeUtils.getUTCFromTimeZonedUtil(from, timeZoneId);
490
488
  }, []);
491
489
  return react.useMemo(() => ({
490
+ getNowDate,
492
491
  nowDate,
493
492
  formatDate,
494
493
  formatDateWithTimezone,
@@ -521,6 +520,7 @@ const useDateAndTime = () => {
521
520
  formatDate,
522
521
  formatDateWithTimezone,
523
522
  formatRange,
523
+ getNowDate,
524
524
  getUTCFromTimeZonedDate,
525
525
  monthName,
526
526
  months,
package/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getTimeZone, Temporal, toZonedDateTimeUtil, toDateUtil, 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, 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';
@@ -152,12 +152,10 @@ const useDateAndTime = () => {
152
152
  const currentLocale = useLocale();
153
153
  const { current, assetTimeZone, preferred } = useTimezone();
154
154
  const currentTimeZone = useMemo(() => current.id || preferred.id || assetTimeZone?.id, [current, assetTimeZone, preferred]);
155
+ const getNowDate = useCallback(() => {
156
+ return toDateUtil(toZonedDateTimeUtil(Temporal.Now.instant(), currentTimeZone));
157
+ }, [currentTimeZone]);
155
158
  const currentDate = useMemo(() => toZonedDateTimeUtil(Temporal.Now.instant(), currentTimeZone), [currentTimeZone]);
156
- /**
157
- * Returns the current date and time.
158
- *
159
- * @returns {Date}
160
- */
161
159
  const nowDate = useMemo(() => toDateUtil(currentDate), [currentDate]);
162
160
  /**
163
161
  * Formats a date using the current locale and time zone.
@@ -487,6 +485,7 @@ const useDateAndTime = () => {
487
485
  return getUTCFromTimeZonedUtil(from, timeZoneId);
488
486
  }, []);
489
487
  return useMemo(() => ({
488
+ getNowDate,
490
489
  nowDate,
491
490
  formatDate,
492
491
  formatDateWithTimezone,
@@ -519,6 +518,7 @@ const useDateAndTime = () => {
519
518
  formatDate,
520
519
  formatDateWithTimezone,
521
520
  formatRange,
521
+ getNowDate,
522
522
  getUTCFromTimeZonedDate,
523
523
  monthName,
524
524
  months,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-date-and-time-hooks",
3
- "version": "1.21.0",
3
+ "version": "1.21.2",
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.2",
14
- "@trackunit/react-core-contexts-test": "1.15.12",
15
- "@trackunit/date-and-time-utils": "1.11.99",
16
- "@trackunit/shared-utils": "1.13.97",
17
- "@trackunit/react-core-hooks": "1.15.12",
18
- "@trackunit/react-components": "1.22.0",
19
- "@trackunit/react-graphql-hooks": "1.22.0",
20
- "@trackunit/iris-app-runtime-core-api": "1.14.11"
13
+ "@trackunit/iris-app-api": "1.17.3",
14
+ "@trackunit/react-core-contexts-test": "1.15.13",
15
+ "@trackunit/date-and-time-utils": "1.11.100",
16
+ "@trackunit/shared-utils": "1.13.98",
17
+ "@trackunit/react-core-hooks": "1.15.13",
18
+ "@trackunit/react-components": "1.22.1",
19
+ "@trackunit/react-graphql-hooks": "1.22.1",
20
+ "@trackunit/iris-app-runtime-core-api": "1.14.12"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@apollo/client": "^3.13.8",
@@ -9,6 +9,11 @@ export type TemporalIsType = "past" | "present" | "future" | "between";
9
9
  export type TemporalSameType = Extract<TemporalTypes, "day" | "week" | "month" | "year">;
10
10
  export type TemporalTimeRounding = Extract<TemporalTypes, "hour" | "minute" | "second">;
11
11
  interface UseDateAndTimeReturn {
12
+ /** Current instant in the active timezone as a `Date`. Call when you need “now”; the function reference is stable until the timezone changes; each call returns a fresh time. */
13
+ getNowDate: () => Date;
14
+ /**
15
+ * @deprecated Use `getNowDate()` instead. This snapshot only updates when the active timezone changes, not as wall-clock time advances (so long-lived sessions can show stale “now”).
16
+ */
12
17
  nowDate: Date;
13
18
  formatDate: (date: TemporalDate, format?: TemporalFormat) => string;
14
19
  formatDateWithTimezone: (date: TemporalDate, format?: TemporalFormat, timezone?: string, locale?: string) => string;