@trackunit/react-date-and-time-hooks 1.21.19 → 1.21.21

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
@@ -106,7 +106,18 @@ const GetAssetTimezoneDocument = {
106
106
 
107
107
  const customTimeZoneSchema = zod.z.string().nullable();
108
108
  /**
109
+ * Resolves the active timezone based on user preference, custom override, and optional asset location.
109
110
  *
111
+ * Returns `current` (browser or custom override), `preferred` (resolved per user settings
112
+ * and optional asset), and `assetTimeZone` (fetched from the asset's GPS location).
113
+ *
114
+ * **When to use:**
115
+ * - Use `useTimezone` whenever you need to display or calculate dates in the correct
116
+ * timezone — especially on asset-detail pages where the machine's timezone may differ
117
+ * from the user's browser timezone.
118
+ * - Pair with `useDateAndTime` to format dates in the resolved `preferred` timezone.
119
+ * - Do **not** rely on `Intl.DateTimeFormat().resolvedOptions().timeZone` directly —
120
+ * this hook respects the user's preference setting (browser, machine, or custom).
110
121
  */
111
122
  const useTimezone = ({ assetId } = {}) => {
112
123
  const { timeZonePreference } = reactCoreHooks.useCurrentUserTimeZonePreference();
@@ -147,8 +158,18 @@ const useTimezone = ({ assetId } = {}) => {
147
158
  };
148
159
 
149
160
  /**
150
- * Hook for managing date and time operations.
161
+ * Hook for locale- and timezone-aware date/time operations including formatting,
162
+ * arithmetic, comparisons, relative time, and duration formatting.
163
+ *
164
+ * ### When to use
165
+ * Use `useDateAndTime` whenever you need to format, compare, or manipulate dates in a
166
+ * way that respects the user's locale and timezone.
151
167
  *
168
+ * ### When not to use
169
+ * - For raw UTC timestamps that never reach the UI — use plain `Date` math or
170
+ * `date-and-time-utils` directly.
171
+ * - For date picker value handling — the date/time components already consume locale
172
+ * and timezone internally.
152
173
  */
153
174
  const useDateAndTime = () => {
154
175
  const currentLocale = useLocale();
package/index.esm.js CHANGED
@@ -104,7 +104,18 @@ const GetAssetTimezoneDocument = {
104
104
 
105
105
  const customTimeZoneSchema = z.string().nullable();
106
106
  /**
107
+ * Resolves the active timezone based on user preference, custom override, and optional asset location.
107
108
  *
109
+ * Returns `current` (browser or custom override), `preferred` (resolved per user settings
110
+ * and optional asset), and `assetTimeZone` (fetched from the asset's GPS location).
111
+ *
112
+ * **When to use:**
113
+ * - Use `useTimezone` whenever you need to display or calculate dates in the correct
114
+ * timezone — especially on asset-detail pages where the machine's timezone may differ
115
+ * from the user's browser timezone.
116
+ * - Pair with `useDateAndTime` to format dates in the resolved `preferred` timezone.
117
+ * - Do **not** rely on `Intl.DateTimeFormat().resolvedOptions().timeZone` directly —
118
+ * this hook respects the user's preference setting (browser, machine, or custom).
108
119
  */
109
120
  const useTimezone = ({ assetId } = {}) => {
110
121
  const { timeZonePreference } = useCurrentUserTimeZonePreference();
@@ -145,8 +156,18 @@ const useTimezone = ({ assetId } = {}) => {
145
156
  };
146
157
 
147
158
  /**
148
- * Hook for managing date and time operations.
159
+ * Hook for locale- and timezone-aware date/time operations including formatting,
160
+ * arithmetic, comparisons, relative time, and duration formatting.
161
+ *
162
+ * ### When to use
163
+ * Use `useDateAndTime` whenever you need to format, compare, or manipulate dates in a
164
+ * way that respects the user's locale and timezone.
149
165
  *
166
+ * ### When not to use
167
+ * - For raw UTC timestamps that never reach the UI — use plain `Date` math or
168
+ * `date-and-time-utils` directly.
169
+ * - For date picker value handling — the date/time components already consume locale
170
+ * and timezone internally.
150
171
  */
151
172
  const useDateAndTime = () => {
152
173
  const currentLocale = useLocale();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-date-and-time-hooks",
3
- "version": "1.21.19",
3
+ "version": "1.21.21",
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.15",
14
- "@trackunit/react-core-contexts-test": "1.15.25",
15
- "@trackunit/date-and-time-utils": "1.11.113",
16
- "@trackunit/shared-utils": "1.13.110",
17
- "@trackunit/react-core-hooks": "1.15.25",
18
- "@trackunit/react-components": "1.22.16",
19
- "@trackunit/react-graphql-hooks": "1.22.16",
20
- "@trackunit/iris-app-runtime-core-api": "1.14.24"
13
+ "@trackunit/iris-app-api": "1.17.17",
14
+ "@trackunit/react-core-contexts-test": "1.15.27",
15
+ "@trackunit/date-and-time-utils": "1.11.115",
16
+ "@trackunit/shared-utils": "1.13.112",
17
+ "@trackunit/react-core-hooks": "1.15.27",
18
+ "@trackunit/react-components": "1.22.18",
19
+ "@trackunit/react-graphql-hooks": "1.22.18",
20
+ "@trackunit/iris-app-runtime-core-api": "1.14.26"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@apollo/client": "^3.13.8",
@@ -62,8 +62,18 @@ interface UseDateAndTimeReturn {
62
62
  formatShortDate: (date: Date | undefined) => string;
63
63
  }
64
64
  /**
65
- * Hook for managing date and time operations.
65
+ * Hook for locale- and timezone-aware date/time operations including formatting,
66
+ * arithmetic, comparisons, relative time, and duration formatting.
66
67
  *
68
+ * ### When to use
69
+ * Use `useDateAndTime` whenever you need to format, compare, or manipulate dates in a
70
+ * way that respects the user's locale and timezone.
71
+ *
72
+ * ### When not to use
73
+ * - For raw UTC timestamps that never reach the UI — use plain `Date` math or
74
+ * `date-and-time-utils` directly.
75
+ * - For date picker value handling — the date/time components already consume locale
76
+ * and timezone internally.
67
77
  */
68
78
  export declare const useDateAndTime: () => UseDateAndTimeReturn;
69
79
  export {};
@@ -27,7 +27,18 @@ interface TimezoneProps {
27
27
  assetId?: string;
28
28
  }
29
29
  /**
30
+ * Resolves the active timezone based on user preference, custom override, and optional asset location.
30
31
  *
32
+ * Returns `current` (browser or custom override), `preferred` (resolved per user settings
33
+ * and optional asset), and `assetTimeZone` (fetched from the asset's GPS location).
34
+ *
35
+ * **When to use:**
36
+ * - Use `useTimezone` whenever you need to display or calculate dates in the correct
37
+ * timezone — especially on asset-detail pages where the machine's timezone may differ
38
+ * from the user's browser timezone.
39
+ * - Pair with `useDateAndTime` to format dates in the resolved `preferred` timezone.
40
+ * - Do **not** rely on `Intl.DateTimeFormat().resolvedOptions().timeZone` directly —
41
+ * this hook respects the user's preference setting (browser, machine, or custom).
31
42
  */
32
43
  export declare const useTimezone: ({ assetId }?: TimezoneProps) => UseTimezoneReturn;
33
44
  export {};