@trackunit/react-date-and-time-hooks 1.0.6 → 1.0.8
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 +7 -10
- package/index.esm.js +7 -10
- package/package.json +3 -3
package/index.cjs.js
CHANGED
|
@@ -23,10 +23,9 @@ const convertToLocale = (userPreferenceLanguage) => {
|
|
|
23
23
|
return userPreferenceLanguage;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
var _a;
|
|
27
26
|
const LANG_STORAGE_KEY = "i18nextLng";
|
|
28
27
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
29
|
-
const BrowserLocale =
|
|
28
|
+
const BrowserLocale = navigator.language ?? "en";
|
|
30
29
|
/**
|
|
31
30
|
*
|
|
32
31
|
*/
|
|
@@ -106,7 +105,6 @@ const GetAssetTimezoneDocument = {
|
|
|
106
105
|
*
|
|
107
106
|
*/
|
|
108
107
|
const useTimezone = ({ assetId } = {}) => {
|
|
109
|
-
var _a, _b, _c, _d;
|
|
110
108
|
const { timeZonePreference } = reactCoreHooks.useCurrentUserTimeZonePreference();
|
|
111
109
|
const [customTimezone, setCustomTimezone] = reactCoreHooks.useLocalStorage({
|
|
112
110
|
key: "customTimeZone",
|
|
@@ -122,13 +120,12 @@ const useTimezone = ({ assetId } = {}) => {
|
|
|
122
120
|
fetchPolicy: "cache-first",
|
|
123
121
|
});
|
|
124
122
|
const assetTimeZone = react.useMemo(() => {
|
|
125
|
-
|
|
126
|
-
const timezone = (_d = (_c = (_b = (_a = timeZoneData === null || timeZoneData === void 0 ? void 0 : timeZoneData.asset) === null || _a === void 0 ? void 0 : _a.locations) === null || _b === void 0 ? void 0 : _b.latest) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.timeZone;
|
|
123
|
+
const timezone = timeZoneData?.asset?.locations?.latest?.properties?.timeZone;
|
|
127
124
|
if (!timezone) {
|
|
128
125
|
return null;
|
|
129
126
|
}
|
|
130
127
|
return dateAndTimeUtils.getTimeZone(timezone);
|
|
131
|
-
}, [
|
|
128
|
+
}, [timeZoneData?.asset?.locations?.latest?.properties?.timeZone]);
|
|
132
129
|
const current = react.useMemo(() => {
|
|
133
130
|
const id = polyfill.Temporal.Now.timeZoneId();
|
|
134
131
|
if (timeZonePreference === reactCoreContextsApi.TimeZonePreference.CustomTimeZone && customTimezone) {
|
|
@@ -157,7 +154,7 @@ const useTimezone = ({ assetId } = {}) => {
|
|
|
157
154
|
const useDateAndTime = () => {
|
|
158
155
|
const currentLocale = useLocale();
|
|
159
156
|
const { current, assetTimeZone, preferred } = useTimezone();
|
|
160
|
-
const currentTimeZone = react.useMemo(() => current.id || preferred.id ||
|
|
157
|
+
const currentTimeZone = react.useMemo(() => current.id || preferred.id || assetTimeZone?.id, [current, assetTimeZone, preferred]);
|
|
161
158
|
const currentDate = react.useMemo(() => dateAndTimeUtils.toZonedDateTimeUtil(polyfill.Temporal.Now.instant(), currentTimeZone), [currentTimeZone]);
|
|
162
159
|
/**
|
|
163
160
|
* Returns the current date and time.
|
|
@@ -185,7 +182,7 @@ const useDateAndTime = () => {
|
|
|
185
182
|
* @returns {string}
|
|
186
183
|
*/
|
|
187
184
|
const formatDateWithTimezone = react.useCallback((date, format, timezone, locale) => {
|
|
188
|
-
return dateAndTimeUtils.formatDateUtil(date, format, timezone
|
|
185
|
+
return dateAndTimeUtils.formatDateUtil(date, format, timezone ?? currentTimeZone, locale ?? currentLocale);
|
|
189
186
|
}, [currentLocale, currentTimeZone]);
|
|
190
187
|
/**
|
|
191
188
|
* Formats a date range using the current locale and time zone.
|
|
@@ -367,7 +364,7 @@ const useDateAndTime = () => {
|
|
|
367
364
|
case "present":
|
|
368
365
|
return dateAndTimeUtils.isTodayUtil(date);
|
|
369
366
|
case "between":
|
|
370
|
-
return dateAndTimeUtils.isBetweenUtil(date, betweenDates
|
|
367
|
+
return dateAndTimeUtils.isBetweenUtil(date, betweenDates?.start, betweenDates?.end);
|
|
371
368
|
default:
|
|
372
369
|
return sharedUtils.exhaustiveCheck(type);
|
|
373
370
|
}
|
|
@@ -434,7 +431,7 @@ const useDateAndTime = () => {
|
|
|
434
431
|
const duration = react.useCallback((from, type, format, roundAt) => {
|
|
435
432
|
const durationValue = typeof from === "number"
|
|
436
433
|
? dateAndTimeUtils.toDuration(from, type, roundAt)
|
|
437
|
-
: polyfill.Temporal.Duration.from(from).round({ smallestUnit: roundAt
|
|
434
|
+
: polyfill.Temporal.Duration.from(from).round({ smallestUnit: roundAt ?? "minute" });
|
|
438
435
|
return dateAndTimeUtils.getDurationFormat(durationValue, currentLocale, format);
|
|
439
436
|
}, [currentLocale]);
|
|
440
437
|
/**
|
package/index.esm.js
CHANGED
|
@@ -21,10 +21,9 @@ const convertToLocale = (userPreferenceLanguage) => {
|
|
|
21
21
|
return userPreferenceLanguage;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
var _a;
|
|
25
24
|
const LANG_STORAGE_KEY = "i18nextLng";
|
|
26
25
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
27
|
-
const BrowserLocale =
|
|
26
|
+
const BrowserLocale = navigator.language ?? "en";
|
|
28
27
|
/**
|
|
29
28
|
*
|
|
30
29
|
*/
|
|
@@ -104,7 +103,6 @@ const GetAssetTimezoneDocument = {
|
|
|
104
103
|
*
|
|
105
104
|
*/
|
|
106
105
|
const useTimezone = ({ assetId } = {}) => {
|
|
107
|
-
var _a, _b, _c, _d;
|
|
108
106
|
const { timeZonePreference } = useCurrentUserTimeZonePreference();
|
|
109
107
|
const [customTimezone, setCustomTimezone] = useLocalStorage({
|
|
110
108
|
key: "customTimeZone",
|
|
@@ -120,13 +118,12 @@ const useTimezone = ({ assetId } = {}) => {
|
|
|
120
118
|
fetchPolicy: "cache-first",
|
|
121
119
|
});
|
|
122
120
|
const assetTimeZone = useMemo(() => {
|
|
123
|
-
|
|
124
|
-
const timezone = (_d = (_c = (_b = (_a = timeZoneData === null || timeZoneData === void 0 ? void 0 : timeZoneData.asset) === null || _a === void 0 ? void 0 : _a.locations) === null || _b === void 0 ? void 0 : _b.latest) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.timeZone;
|
|
121
|
+
const timezone = timeZoneData?.asset?.locations?.latest?.properties?.timeZone;
|
|
125
122
|
if (!timezone) {
|
|
126
123
|
return null;
|
|
127
124
|
}
|
|
128
125
|
return getTimeZone(timezone);
|
|
129
|
-
}, [
|
|
126
|
+
}, [timeZoneData?.asset?.locations?.latest?.properties?.timeZone]);
|
|
130
127
|
const current = useMemo(() => {
|
|
131
128
|
const id = Temporal.Now.timeZoneId();
|
|
132
129
|
if (timeZonePreference === TimeZonePreference.CustomTimeZone && customTimezone) {
|
|
@@ -155,7 +152,7 @@ const useTimezone = ({ assetId } = {}) => {
|
|
|
155
152
|
const useDateAndTime = () => {
|
|
156
153
|
const currentLocale = useLocale();
|
|
157
154
|
const { current, assetTimeZone, preferred } = useTimezone();
|
|
158
|
-
const currentTimeZone = useMemo(() => current.id || preferred.id ||
|
|
155
|
+
const currentTimeZone = useMemo(() => current.id || preferred.id || assetTimeZone?.id, [current, assetTimeZone, preferred]);
|
|
159
156
|
const currentDate = useMemo(() => toZonedDateTimeUtil(Temporal.Now.instant(), currentTimeZone), [currentTimeZone]);
|
|
160
157
|
/**
|
|
161
158
|
* Returns the current date and time.
|
|
@@ -183,7 +180,7 @@ const useDateAndTime = () => {
|
|
|
183
180
|
* @returns {string}
|
|
184
181
|
*/
|
|
185
182
|
const formatDateWithTimezone = useCallback((date, format, timezone, locale) => {
|
|
186
|
-
return formatDateUtil(date, format, timezone
|
|
183
|
+
return formatDateUtil(date, format, timezone ?? currentTimeZone, locale ?? currentLocale);
|
|
187
184
|
}, [currentLocale, currentTimeZone]);
|
|
188
185
|
/**
|
|
189
186
|
* Formats a date range using the current locale and time zone.
|
|
@@ -365,7 +362,7 @@ const useDateAndTime = () => {
|
|
|
365
362
|
case "present":
|
|
366
363
|
return isTodayUtil(date);
|
|
367
364
|
case "between":
|
|
368
|
-
return isBetweenUtil(date, betweenDates
|
|
365
|
+
return isBetweenUtil(date, betweenDates?.start, betweenDates?.end);
|
|
369
366
|
default:
|
|
370
367
|
return exhaustiveCheck(type);
|
|
371
368
|
}
|
|
@@ -432,7 +429,7 @@ const useDateAndTime = () => {
|
|
|
432
429
|
const duration = useCallback((from, type, format, roundAt) => {
|
|
433
430
|
const durationValue = typeof from === "number"
|
|
434
431
|
? toDuration(from, type, roundAt)
|
|
435
|
-
: Temporal.Duration.from(from).round({ smallestUnit: roundAt
|
|
432
|
+
: Temporal.Duration.from(from).round({ smallestUnit: roundAt ?? "minute" });
|
|
436
433
|
return getDurationFormat(durationValue, currentLocale, format);
|
|
437
434
|
}, [currentLocale]);
|
|
438
435
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-date-and-time-hooks",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"@js-temporal/polyfill": "^0.4.4",
|
|
15
15
|
"react": "18.3.1",
|
|
16
16
|
"zod": "3.22.4",
|
|
17
|
-
"@trackunit/iris-app-build-utilities": "^1.0.
|
|
18
|
-
"@trackunit/iris-app-api": "^1.0.
|
|
17
|
+
"@trackunit/iris-app-build-utilities": "^1.0.5",
|
|
18
|
+
"@trackunit/iris-app-api": "^1.0.4",
|
|
19
19
|
"@trackunit/react-core-contexts-test": "^1.0.5",
|
|
20
20
|
"@trackunit/date-and-time-utils": "^1.0.1",
|
|
21
21
|
"@trackunit/shared-utils": "^1.0.3",
|