@trackunit/react-date-and-time-hooks 0.0.1

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.
@@ -0,0 +1,134 @@
1
+ import { TypedDocumentNode as DocumentNode } from "@graphql-typed-document-node/core";
2
+ import type { PublicIrisAppManifest } from "@trackunit/iris-app-api";
3
+ export type Maybe<T> = T | null;
4
+ export type InputMaybe<T> = Maybe<T> | undefined;
5
+ export type Exact<T extends {
6
+ [key: string]: unknown;
7
+ }> = {
8
+ [K in keyof T]: T[K];
9
+ };
10
+ export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
11
+ [SubKey in K]?: Maybe<T[SubKey]>;
12
+ };
13
+ export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
14
+ [SubKey in K]: Maybe<T[SubKey]>;
15
+ };
16
+ export type MakeEmpty<T extends {
17
+ [key: string]: unknown;
18
+ }, K extends keyof T> = {
19
+ [_ in K]?: never;
20
+ };
21
+ export type Incremental<T> = T | {
22
+ [P in keyof T]?: P extends " $fragmentName" | "__typename" ? T[P] : never;
23
+ };
24
+ export type DateTimeISOString = string;
25
+ /** All built-in and custom scalars, mapped to their actual values */
26
+ export type Scalars = {
27
+ ID: {
28
+ input: string;
29
+ output: string;
30
+ };
31
+ String: {
32
+ input: string;
33
+ output: string;
34
+ };
35
+ Boolean: {
36
+ input: boolean;
37
+ output: boolean;
38
+ };
39
+ Int: {
40
+ input: number;
41
+ output: number;
42
+ };
43
+ Float: {
44
+ input: number;
45
+ output: number;
46
+ };
47
+ /** The ISO 4217 currency code of the monetary field definition. */
48
+ Currency: {
49
+ input: string;
50
+ output: string;
51
+ };
52
+ /** Cursor scalar. */
53
+ Cursor: {
54
+ input: string;
55
+ output: string;
56
+ };
57
+ /** Date without time, Eg. 2019-01-01 */
58
+ Date: {
59
+ input: DateTimeISOString;
60
+ output: DateTimeISOString;
61
+ };
62
+ /** DateTime represents a “date-time” as specified in section 5.6 of RFC 3339 */
63
+ DateTime: {
64
+ input: DateTimeISOString;
65
+ output: DateTimeISOString;
66
+ };
67
+ /** Duration represents an ISO 8601 duration */
68
+ Duration: {
69
+ input: any;
70
+ output: any;
71
+ };
72
+ /** Valid email address according to https://owasp.org/www-community/OWASP_Validation_Regex_Repository */
73
+ EmailAddress: {
74
+ input: string;
75
+ output: string;
76
+ };
77
+ /** A (possiblely multidimensional) set of coordinates following x, y, z order. */
78
+ GeoJSONCoordinates: {
79
+ input: number[] | number[][];
80
+ output: number[] | number[][];
81
+ };
82
+ /** Raw JSON object structure, not serialized to string */
83
+ JSON: {
84
+ input: any;
85
+ output: any;
86
+ };
87
+ /** Javascript `Long`. Type represents a 64 bit integer. */
88
+ Long: {
89
+ input: any;
90
+ output: any;
91
+ };
92
+ /** Phone number in E.164 format */
93
+ PhoneNumber: {
94
+ input: string;
95
+ output: string;
96
+ };
97
+ /** The `PublicIrisAppManifest` scalar type represents an Iris App Manifest as JSON */
98
+ PublicIrisAppManifest: {
99
+ input: PublicIrisAppManifest;
100
+ output: PublicIrisAppManifest;
101
+ };
102
+ /** The `Upload` scalar type represents a file upload. */
103
+ Upload: {
104
+ input: any;
105
+ output: any;
106
+ };
107
+ /** Uniform resource locator */
108
+ Url: {
109
+ input: string;
110
+ output: string;
111
+ };
112
+ };
113
+ export type GetAssetTimezoneQueryVariables = Exact<{
114
+ assetId: Scalars["ID"]["input"];
115
+ }>;
116
+ export type GetAssetTimezoneQuery = {
117
+ __typename?: "Query";
118
+ asset: {
119
+ __typename?: "Asset";
120
+ locations: {
121
+ __typename?: "Locations";
122
+ latest: {
123
+ __typename?: "GeoJSONFeatureForAsset";
124
+ properties: {
125
+ __typename?: "GeoJSONPropertiesForAsset";
126
+ timeZone: string | null;
127
+ } | null;
128
+ } | null;
129
+ } | null;
130
+ } | null;
131
+ };
132
+ export declare const GetAssetTimezoneDocument: DocumentNode<GetAssetTimezoneQuery, Exact<{
133
+ assetId: Scalars["ID"]["input"];
134
+ }>>;
@@ -0,0 +1,2 @@
1
+ export * from "./fragment-masking";
2
+ export * from "./gql";
@@ -0,0 +1,5 @@
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
+ };
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./localeUtils";
2
+ export * from "./useDateAndTime";
3
+ export * from "./useLocale";
4
+ export * from "./useTimezone";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Try to convert to ISO standard. ex. en becomes en-GB if its in United Kingdom.
3
+ * Still looking at the base id.
4
+ *
5
+ * @param userPreferenceLanguage 2 letter language code from the persisted language selection.
6
+ */
7
+ export declare const convertToLocale: (userPreferenceLanguage: string) => string;
@@ -0,0 +1 @@
1
+ export { mockAssetTimezone } from "./mocks/mockAssetTimezone";
@@ -0,0 +1,15 @@
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 {};
@@ -0,0 +1,35 @@
1
+ import { DateRange, TemporalDate, TemporalFormat, TemporalFormatStyle } from "@trackunit/date-and-time-utils";
2
+ import { Duration } from "date-fns";
3
+ type TemporalTypes = "second" | "seconds" | "minute" | "minutes" | "hour" | "hours" | "day" | "days" | "week" | "weeks" | "month" | "months" | "year" | "years";
4
+ export type TemporalArithmeticType = Extract<TemporalTypes, "hours" | "minutes" | "days" | "weeks" | "months" | "years">;
5
+ export type TemporalEdgeOfType = Extract<TemporalTypes, "hour" | "minute" | "day" | "week" | "month">;
6
+ export type TemporalDifferenceType = Extract<TemporalTypes, "minute" | "hour" | "day" | "week" | "month">;
7
+ export type TemporalSinceType = "auto" | Extract<TemporalTypes, "seconds" | "minutes" | "hours" | "days" | "months" | "years">;
8
+ export type TemporalDurationType = Extract<TemporalTypes, "days" | "hours" | "minutes">;
9
+ export type TemporalIsType = "past" | "present" | "future" | "between";
10
+ export type TemporalSameType = Extract<TemporalTypes, "day" | "week" | "month" | "year">;
11
+ export type TemporalTimeRounding = Extract<TemporalTypes, "hour" | "minute" | "second">;
12
+ /**
13
+ *
14
+ */
15
+ export declare const useDateAndTime: () => {
16
+ nowDate: Date;
17
+ formatDate: (date: TemporalDate, format?: TemporalFormat) => string;
18
+ formatDateWithTimezone: (date: TemporalDate, format?: TemporalFormat, timezone?: string, locale?: string) => string;
19
+ formatRange: (range: DateRange, format?: Intl.DateTimeFormatOptions) => string;
20
+ startOf: (date: TemporalDate, type: TemporalEdgeOfType) => Date;
21
+ endOf: (date: TemporalDate, type: TemporalEdgeOfType) => Date;
22
+ add: (date: TemporalDate, amount: number, type: TemporalArithmeticType) => Date;
23
+ subtract: (date: TemporalDate, amount: number, type: TemporalArithmeticType) => Date;
24
+ difference: (from: TemporalDate, to: TemporalDate, type: TemporalDifferenceType) => number;
25
+ since: (from: TemporalDate, to: TemporalDate, type: TemporalSinceType) => string;
26
+ same: (date: TemporalDate, type: TemporalSameType) => boolean;
27
+ duration: (from: number | Duration, type: TemporalDurationType, format?: TemporalFormat["dayFormat"], roundAt?: TemporalTimeRounding) => string;
28
+ dateIs: (date: TemporalDate, type: TemporalIsType, betweenDates?: DateRange) => boolean;
29
+ isEqual: (from: TemporalDate, to: TemporalDate) => boolean;
30
+ monthName: (date: TemporalDate, format: TemporalFormatStyle) => string;
31
+ months: (format?: TemporalFormatStyle) => string[];
32
+ dayName: (date: TemporalDate, format: TemporalFormatStyle) => string;
33
+ days: (format?: TemporalFormatStyle) => string[];
34
+ };
35
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ *
3
+ */
4
+ export declare const useLocale: () => string;
@@ -0,0 +1,27 @@
1
+ /// <reference types="react" />
2
+ interface TimezoneProps {
3
+ /** supply assetId to fetch the timezone for the given machine */
4
+ assetId?: string;
5
+ }
6
+ /**
7
+ *
8
+ */
9
+ export declare const useTimezone: ({ assetId }?: TimezoneProps) => {
10
+ current: {
11
+ id: string;
12
+ offset: string;
13
+ name: string;
14
+ };
15
+ assetTimeZone: {
16
+ id: string;
17
+ offset: string;
18
+ name: string;
19
+ } | null;
20
+ preferred: {
21
+ id: string;
22
+ offset: string;
23
+ name: string;
24
+ };
25
+ setCustomTimezone: import("react").Dispatch<import("react").SetStateAction<string | null>>;
26
+ };
27
+ export {};