@trackunit/react-date-and-time-hooks 1.7.111 → 1.7.113
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 +5 -1
- package/index.esm.js +5 -1
- package/package.json +9 -8
- package/src/localeUtils.d.ts +1 -0
- package/src/useDateAndTime.d.ts +14 -13
- package/src/useLocale.d.ts +2 -0
- package/src/useTimezone.d.ts +25 -18
- package/src/generated/graphql-api/mock.d.ts +0 -5
- package/src/test/mocks/mockAssetTimezone.d.ts +0 -15
package/index.cjs.js
CHANGED
|
@@ -5,6 +5,7 @@ var dateAndTimeUtils = require('@trackunit/date-and-time-utils');
|
|
|
5
5
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
6
6
|
var react = require('react');
|
|
7
7
|
var irisAppRuntimeCoreApi = require('@trackunit/iris-app-runtime-core-api');
|
|
8
|
+
var reactComponents = require('@trackunit/react-components');
|
|
8
9
|
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
9
10
|
var reactGraphqlHooks = require('@trackunit/react-graphql-hooks');
|
|
10
11
|
var zod = require('zod');
|
|
@@ -14,6 +15,7 @@ var zod = require('zod');
|
|
|
14
15
|
* Still looking at the base id.
|
|
15
16
|
*
|
|
16
17
|
* @param userPreferenceLanguage 2 letter language code from the persisted language selection.
|
|
18
|
+
* @returns {string} The locale string.
|
|
17
19
|
*/
|
|
18
20
|
const convertToLocale = (userPreferenceLanguage) => {
|
|
19
21
|
const browserLanguage = navigator.language;
|
|
@@ -27,7 +29,9 @@ const LANG_STORAGE_KEY = "i18nextLng";
|
|
|
27
29
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
28
30
|
const BrowserLocale = navigator.language ?? "en";
|
|
29
31
|
/**
|
|
32
|
+
* Returns the current locale.
|
|
30
33
|
*
|
|
34
|
+
* @returns {string} The current locale.
|
|
31
35
|
*/
|
|
32
36
|
const useLocale = () => {
|
|
33
37
|
const savedLanguage = localStorage.getItem(LANG_STORAGE_KEY);
|
|
@@ -112,7 +116,7 @@ const useTimezone = ({ assetId } = {}) => {
|
|
|
112
116
|
defaultState: null,
|
|
113
117
|
schema: customTimeZoneSchema,
|
|
114
118
|
}), []);
|
|
115
|
-
const [customTimezone, setCustomTimezone] =
|
|
119
|
+
const [customTimezone, setCustomTimezone] = reactComponents.useLocalStorage(localStorageProps);
|
|
116
120
|
const { data: timeZoneData } = reactGraphqlHooks.useQuery(GetAssetTimezoneDocument, {
|
|
117
121
|
variables: {
|
|
118
122
|
assetId: assetId ?? "",
|
package/index.esm.js
CHANGED
|
@@ -3,7 +3,8 @@ import { getTimeZone, toZonedDateTimeUtil, toDateUtil, formatDateUtil, formatRan
|
|
|
3
3
|
import { exhaustiveCheck } from '@trackunit/shared-utils';
|
|
4
4
|
import { useMemo, useCallback } from 'react';
|
|
5
5
|
import { TimeZonePreference } from '@trackunit/iris-app-runtime-core-api';
|
|
6
|
-
import {
|
|
6
|
+
import { useLocalStorage } from '@trackunit/react-components';
|
|
7
|
+
import { useCurrentUserTimeZonePreference } from '@trackunit/react-core-hooks';
|
|
7
8
|
import { useQuery } from '@trackunit/react-graphql-hooks';
|
|
8
9
|
import { z } from 'zod';
|
|
9
10
|
|
|
@@ -12,6 +13,7 @@ import { z } from 'zod';
|
|
|
12
13
|
* Still looking at the base id.
|
|
13
14
|
*
|
|
14
15
|
* @param userPreferenceLanguage 2 letter language code from the persisted language selection.
|
|
16
|
+
* @returns {string} The locale string.
|
|
15
17
|
*/
|
|
16
18
|
const convertToLocale = (userPreferenceLanguage) => {
|
|
17
19
|
const browserLanguage = navigator.language;
|
|
@@ -25,7 +27,9 @@ const LANG_STORAGE_KEY = "i18nextLng";
|
|
|
25
27
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
26
28
|
const BrowserLocale = navigator.language ?? "en";
|
|
27
29
|
/**
|
|
30
|
+
* Returns the current locale.
|
|
28
31
|
*
|
|
32
|
+
* @returns {string} The current locale.
|
|
29
33
|
*/
|
|
30
34
|
const useLocale = () => {
|
|
31
35
|
const savedLanguage = localStorage.getItem(LANG_STORAGE_KEY);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-date-and-time-hooks",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.113",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -13,14 +13,15 @@
|
|
|
13
13
|
"@apollo/client": "3.13.8",
|
|
14
14
|
"react": "19.0.0",
|
|
15
15
|
"zod": "^3.23.8",
|
|
16
|
-
"@trackunit/iris-app-api": "1.9.
|
|
17
|
-
"@trackunit/react-core-contexts-test": "1.7.
|
|
18
|
-
"@trackunit/date-and-time-utils": "1.7.
|
|
19
|
-
"@trackunit/shared-utils": "1.9.
|
|
20
|
-
"@trackunit/react-core-hooks": "1.7.
|
|
16
|
+
"@trackunit/iris-app-api": "1.9.20",
|
|
17
|
+
"@trackunit/react-core-contexts-test": "1.7.96",
|
|
18
|
+
"@trackunit/date-and-time-utils": "1.7.82",
|
|
19
|
+
"@trackunit/shared-utils": "1.9.82",
|
|
20
|
+
"@trackunit/react-core-hooks": "1.7.96",
|
|
21
21
|
"@js-temporal/polyfill": "^0.5.1",
|
|
22
|
-
"@trackunit/react-
|
|
23
|
-
"@trackunit/
|
|
22
|
+
"@trackunit/react-components": "1.10.57",
|
|
23
|
+
"@trackunit/react-graphql-hooks": "1.7.119",
|
|
24
|
+
"@trackunit/iris-app-runtime-core-api": "1.7.92"
|
|
24
25
|
},
|
|
25
26
|
"module": "./index.esm.js",
|
|
26
27
|
"main": "./index.cjs.js",
|
package/src/localeUtils.d.ts
CHANGED
package/src/useDateAndTime.d.ts
CHANGED
|
@@ -8,11 +8,7 @@ export type TemporalDurationType = Extract<TemporalTypes, "days" | "hours" | "mi
|
|
|
8
8
|
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
|
-
|
|
12
|
-
* Hook for managing date and time operations.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
export declare const useDateAndTime: () => {
|
|
11
|
+
interface UseDateAndTimeReturn {
|
|
16
12
|
nowDate: Date;
|
|
17
13
|
formatDate: (date: TemporalDate, format?: TemporalFormat) => string;
|
|
18
14
|
formatDateWithTimezone: (date: TemporalDate, format?: TemporalFormat, timezone?: string, locale?: string) => string;
|
|
@@ -20,18 +16,23 @@ export declare const useDateAndTime: () => {
|
|
|
20
16
|
startOf: (date: TemporalDate, type: TemporalEdgeOfType) => Date;
|
|
21
17
|
endOf: (date: TemporalDate, type: TemporalEdgeOfType) => Date;
|
|
22
18
|
add: (date: TemporalDate, amount: number, type: TemporalArithmeticType) => Date;
|
|
23
|
-
convert: (amount: number, unit: "hour" | "minute" | "second" | "millisecond", conversionType: "hour" | "minute" | "second" | "millisecond") => number;
|
|
24
19
|
subtract: (date: TemporalDate, amount: number, type: TemporalArithmeticType) => Date;
|
|
25
20
|
difference: (from: TemporalDate, to: TemporalDate, type: TemporalDifferenceType) => number;
|
|
26
|
-
|
|
21
|
+
dateIs: (date: TemporalDate, type: TemporalIsType, betweenDates?: DateRange) => boolean;
|
|
27
22
|
same: (date: TemporalDate, type: TemporalSameType) => boolean;
|
|
23
|
+
since: (from: TemporalDate, to: TemporalDate, type: TemporalSinceType) => string;
|
|
28
24
|
duration: (from: number | Intl.Duration, type: TemporalDurationType, format?: TemporalFormat["dayFormat"], roundAt?: TemporalTimeRounding) => string;
|
|
29
|
-
|
|
30
|
-
isEqual: (from: TemporalDate, to: TemporalDate) => boolean;
|
|
31
|
-
monthName: (date: TemporalDate, format: TemporalFormatStyle) => string;
|
|
32
|
-
months: (format?: TemporalFormatStyle) => string[];
|
|
25
|
+
convert: (amount: number, unit: "hour" | "minute" | "second" | "millisecond", conversionType: "hour" | "minute" | "second" | "millisecond") => number;
|
|
33
26
|
dayName: (date: TemporalDate, format: TemporalFormatStyle) => string;
|
|
34
|
-
days: (format?: TemporalFormatStyle) => string
|
|
27
|
+
days: (format?: TemporalFormatStyle) => Array<string>;
|
|
28
|
+
monthName: (date: TemporalDate, format: TemporalFormatStyle) => string;
|
|
29
|
+
months: (format?: TemporalFormatStyle) => Array<string>;
|
|
35
30
|
getUTCFromTimeZonedDate: (from: Date, timeZoneId: string) => Date;
|
|
36
|
-
|
|
31
|
+
isEqual: (date1: TemporalDate, date2: TemporalDate) => boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Hook for managing date and time operations.
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
export declare const useDateAndTime: () => UseDateAndTimeReturn;
|
|
37
38
|
export {};
|
package/src/useLocale.d.ts
CHANGED
package/src/useTimezone.d.ts
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
export interface TimeZone {
|
|
2
|
+
/**
|
|
3
|
+
* The unique id of the timezone
|
|
4
|
+
*
|
|
5
|
+
* @example "America/Denver"
|
|
6
|
+
*/
|
|
7
|
+
id: string;
|
|
8
|
+
/**
|
|
9
|
+
* The human-readable name of the timezone. Combines id and offset.
|
|
10
|
+
*
|
|
11
|
+
* @example "America/Denver (-06:00 MDT)"
|
|
12
|
+
*/
|
|
13
|
+
name: string;
|
|
14
|
+
/**
|
|
15
|
+
* @example "-06:00 MDT"
|
|
16
|
+
*/
|
|
17
|
+
offset: string;
|
|
18
|
+
}
|
|
19
|
+
interface UseTimezoneReturn {
|
|
20
|
+
current: TimeZone;
|
|
21
|
+
assetTimeZone: TimeZone | null;
|
|
22
|
+
preferred: TimeZone;
|
|
23
|
+
setCustomTimezone: (timezone: string | null) => void;
|
|
24
|
+
}
|
|
1
25
|
interface TimezoneProps {
|
|
2
26
|
/** supply assetId to fetch the timezone for the given machine */
|
|
3
27
|
assetId?: string;
|
|
@@ -5,22 +29,5 @@ interface TimezoneProps {
|
|
|
5
29
|
/**
|
|
6
30
|
*
|
|
7
31
|
*/
|
|
8
|
-
export declare const useTimezone: ({ assetId }?: TimezoneProps) =>
|
|
9
|
-
current: {
|
|
10
|
-
id: string;
|
|
11
|
-
offset: string;
|
|
12
|
-
name: string;
|
|
13
|
-
};
|
|
14
|
-
assetTimeZone: {
|
|
15
|
-
id: string;
|
|
16
|
-
offset: string;
|
|
17
|
-
name: string;
|
|
18
|
-
} | null;
|
|
19
|
-
preferred: {
|
|
20
|
-
id: string;
|
|
21
|
-
offset: string;
|
|
22
|
-
name: string;
|
|
23
|
-
};
|
|
24
|
-
setCustomTimezone: import("react").Dispatch<import("react").SetStateAction<string | null>>;
|
|
25
|
-
};
|
|
32
|
+
export declare const useTimezone: ({ assetId }?: TimezoneProps) => UseTimezoneReturn;
|
|
26
33
|
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { DeepPartialNullable } from "@trackunit/react-core-contexts-test";
|
|
2
|
-
import * as gql from "./graphql";
|
|
3
|
-
export declare const mockForGetAssetTimezoneQuery: (variables: gql.GetAssetTimezoneQueryVariables, data?: DeepPartialNullable<gql.GetAssetTimezoneQuery>) => import("@apollo/client/testing").MockedResponse<gql.GetAssetTimezoneQuery, Record<string, any>> & {
|
|
4
|
-
data: gql.GetAssetTimezoneQuery;
|
|
5
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
type AssetTimezoneMockProps = {
|
|
2
|
-
assetId: string;
|
|
3
|
-
timeZone: string;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Mocks the asset timezone query.
|
|
7
|
-
*
|
|
8
|
-
* @param { AssetTimezoneMockProps} props - The properties for the asset timezone query.
|
|
9
|
-
* @param {string} [props.assetId] - The asset id
|
|
10
|
-
* @param {string} [props.timeZone] - The timezone to mock
|
|
11
|
-
*/
|
|
12
|
-
export declare const mockAssetTimezone: ({ assetId, timeZone, }: AssetTimezoneMockProps) => import("@apollo/client/testing").MockedResponse<import("../../generated/graphql-api/graphql").GetAssetTimezoneQuery, Record<string, any>> & {
|
|
13
|
-
data: import("../../generated/graphql-api/graphql").GetAssetTimezoneQuery;
|
|
14
|
-
};
|
|
15
|
-
export {};
|