@applicaster/zapp-react-native-utils 14.0.23-alpha.3038517325 → 14.0.23
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.
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
ifEmptyUseFallback,
|
|
4
4
|
textTransform,
|
|
5
5
|
getKeyForLabel,
|
|
6
|
+
getDataTransformForLabel,
|
|
6
7
|
getLabel,
|
|
7
8
|
getAspectRatio,
|
|
8
9
|
getCellWidth,
|
|
@@ -56,6 +57,44 @@ describe("getKeyForLabel", () => {
|
|
|
56
57
|
});
|
|
57
58
|
});
|
|
58
59
|
|
|
60
|
+
describe("getDataTransformForLabel", () => {
|
|
61
|
+
it("returns dataKey when dataKey is not other", () => {
|
|
62
|
+
expect(getDataTransformForLabel(VAL.dataKey, VAL.customKey)).toEqual(
|
|
63
|
+
VAL.dataKey
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("returns customKey when dataKey is other", () => {
|
|
68
|
+
expect(getDataTransformForLabel(VAL.other, VAL.customKey)).toEqual(
|
|
69
|
+
VAL.customKey
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("preserves full date formats containing dots", () => {
|
|
74
|
+
expect(getDataTransformForLabel(VAL.other, "DD.MM.YYYY")).toEqual(
|
|
75
|
+
"DD.MM.YYYY"
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("returns default date format when selected key is null or undefined", () => {
|
|
80
|
+
expect(getDataTransformForLabel(EMPTY.nulls, VAL.customKey)).toEqual(
|
|
81
|
+
"DD/MM/YYYY"
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(getDataTransformForLabel(EMPTY.undef, VAL.customKey)).toEqual(
|
|
85
|
+
"DD/MM/YYYY"
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
expect(getDataTransformForLabel(VAL.other, EMPTY.nulls)).toEqual(
|
|
89
|
+
"DD/MM/YYYY"
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
expect(getDataTransformForLabel(VAL.other, EMPTY.undef)).toEqual(
|
|
93
|
+
"DD/MM/YYYY"
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
59
98
|
describe("getLabel", () => {
|
|
60
99
|
it("returns a string from dataKey's path", () => {
|
|
61
100
|
expect(getLabel(VAL.dataKey, VAL.customKey)(entry)).toEqual(entry.id);
|
package/cellUtils/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
|
-
import dayjs from "
|
|
2
|
+
import { dayjs } from "../dateUtils";
|
|
3
3
|
import validateColor from "validate-color";
|
|
4
4
|
|
|
5
5
|
import { transformColorCode as fixColorHexCode } from "@applicaster/zapp-react-native-utils/transform";
|
|
@@ -31,6 +31,16 @@ export const getKeyForLabel = (dataKey, customKey) => {
|
|
|
31
31
|
return keyToUse.split(".");
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Provides `format` for date formatting. Returns customKey if dataKey is "other", otherwise it returns dataKey.
|
|
36
|
+
* Should consist of valid dayjs tokens - https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
37
|
+
*/
|
|
38
|
+
export const getDataTransformForLabel = (dataKey, customKey) => {
|
|
39
|
+
const keyToUse = dataKey === CUSTOM_KEY ? customKey : dataKey;
|
|
40
|
+
|
|
41
|
+
return keyToUse ?? "DD/MM/YYYY";
|
|
42
|
+
};
|
|
43
|
+
|
|
34
44
|
/**
|
|
35
45
|
* This method will return true if the argument passed to it is either empty or nil
|
|
36
46
|
* The method prevents zero from being evaluated as falsey in an || condition
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { dayjs } from "../index";
|
|
2
|
+
|
|
3
|
+
describe("dayjs", () => {
|
|
4
|
+
describe("basic functionality", () => {
|
|
5
|
+
it("should be defined and be a function", () => {
|
|
6
|
+
expect(dayjs).toBeDefined();
|
|
7
|
+
expect(typeof dayjs).toBe("function");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should create dayjs object from date string", () => {
|
|
11
|
+
const date = dayjs("2023-01-01");
|
|
12
|
+
|
|
13
|
+
expect(date.isValid()).toBe(true);
|
|
14
|
+
expect(date.year()).toBe(2023);
|
|
15
|
+
expect(date.month()).toBe(0); // January is 0
|
|
16
|
+
expect(date.date()).toBe(1);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should create dayjs object from timestamp", () => {
|
|
20
|
+
const timestamp = 1672531200000; // 2023-01-01 00:00:00 UTC
|
|
21
|
+
const date = dayjs(timestamp);
|
|
22
|
+
|
|
23
|
+
expect(date.isValid()).toBe(true);
|
|
24
|
+
expect(date.valueOf()).toBe(timestamp);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should get current date when called without arguments", () => {
|
|
28
|
+
const now = dayjs();
|
|
29
|
+
|
|
30
|
+
expect(now.isValid()).toBe(true);
|
|
31
|
+
expect(now.year()).toBeGreaterThan(2020);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("utc plugin", () => {
|
|
36
|
+
it("should support UTC conversion", () => {
|
|
37
|
+
const date = dayjs("2023-01-01T12:00:00");
|
|
38
|
+
const utcDate = date.utc();
|
|
39
|
+
|
|
40
|
+
expect(utcDate).toBeDefined();
|
|
41
|
+
expect(utcDate.isValid()).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should create UTC date", () => {
|
|
45
|
+
const utcDate = dayjs.utc("2023-01-01");
|
|
46
|
+
|
|
47
|
+
expect(utcDate.isValid()).toBe(true);
|
|
48
|
+
expect(utcDate.utcOffset()).toBe(0);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should handle UTC offset correctly", () => {
|
|
52
|
+
const date = dayjs.utc();
|
|
53
|
+
|
|
54
|
+
expect(date.utcOffset()).toBe(0);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("timezone plugin", () => {
|
|
59
|
+
it("should support timezone conversion", () => {
|
|
60
|
+
const date = dayjs("2023-01-01T12:00:00");
|
|
61
|
+
const tzDate = date.tz("America/New_York");
|
|
62
|
+
|
|
63
|
+
expect(tzDate).toBeDefined();
|
|
64
|
+
expect(tzDate.isValid()).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should create date in specific timezone", () => {
|
|
68
|
+
const date = dayjs.tz("2023-01-01", "America/New_York");
|
|
69
|
+
|
|
70
|
+
expect(date.isValid()).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should handle timezone method", () => {
|
|
74
|
+
const date = dayjs();
|
|
75
|
+
|
|
76
|
+
// Just verify the method exists and doesn't throw
|
|
77
|
+
expect(() => date.tz("UTC")).not.toThrow();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("isoWeek plugin", () => {
|
|
82
|
+
it("should get ISO week of year", () => {
|
|
83
|
+
const date = dayjs("2023-01-01");
|
|
84
|
+
const isoWeek = date.isoWeek();
|
|
85
|
+
|
|
86
|
+
expect(typeof isoWeek).toBe("number");
|
|
87
|
+
expect(isoWeek).toBeGreaterThan(0);
|
|
88
|
+
expect(isoWeek).toBeLessThanOrEqual(53);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should get ISO weekday", () => {
|
|
92
|
+
const date = dayjs("2023-01-02"); // Monday
|
|
93
|
+
const isoWeekday = date.isoWeekday();
|
|
94
|
+
|
|
95
|
+
expect(isoWeekday).toBe(1); // Monday is 1 in ISO weekday
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should set ISO week", () => {
|
|
99
|
+
const date = dayjs("2023-01-01");
|
|
100
|
+
const newDate = date.isoWeek(10);
|
|
101
|
+
|
|
102
|
+
expect(newDate.isoWeek()).toBe(10);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("duration plugin", () => {
|
|
107
|
+
it("should create duration from milliseconds", () => {
|
|
108
|
+
const duration = dayjs.duration(1000);
|
|
109
|
+
|
|
110
|
+
expect(duration.asSeconds()).toBe(1);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("should create duration with object", () => {
|
|
114
|
+
const duration = dayjs.duration({
|
|
115
|
+
hours: 1,
|
|
116
|
+
minutes: 30,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(duration.asMinutes()).toBe(90);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("should format duration", () => {
|
|
123
|
+
const duration = dayjs.duration(3661, "seconds");
|
|
124
|
+
|
|
125
|
+
expect(duration.hours()).toBe(1);
|
|
126
|
+
expect(duration.minutes()).toBe(1);
|
|
127
|
+
expect(duration.seconds()).toBe(1);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("should add duration to date", () => {
|
|
131
|
+
const date = dayjs("2023-01-01");
|
|
132
|
+
const duration = dayjs.duration(1, "day");
|
|
133
|
+
const newDate = date.add(duration);
|
|
134
|
+
|
|
135
|
+
expect(newDate.date()).toBe(2);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should subtract duration from date", () => {
|
|
139
|
+
const date = dayjs("2023-01-02");
|
|
140
|
+
const duration = dayjs.duration(1, "day");
|
|
141
|
+
const newDate = date.subtract(duration);
|
|
142
|
+
|
|
143
|
+
expect(newDate.date()).toBe(1);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("relativeTime plugin", () => {
|
|
148
|
+
it("should get time from now", () => {
|
|
149
|
+
const pastDate = dayjs().subtract(1, "hour");
|
|
150
|
+
const relative = pastDate.fromNow();
|
|
151
|
+
|
|
152
|
+
expect(typeof relative).toBe("string");
|
|
153
|
+
expect(relative).toContain("hour");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("should get time to now", () => {
|
|
157
|
+
const futureDate = dayjs().add(1, "hour");
|
|
158
|
+
const relative = futureDate.toNow();
|
|
159
|
+
|
|
160
|
+
expect(typeof relative).toBe("string");
|
|
161
|
+
expect(relative).toContain("hour");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("should get time from specific date", () => {
|
|
165
|
+
const date1 = dayjs("2023-01-01");
|
|
166
|
+
const date2 = dayjs("2023-01-02");
|
|
167
|
+
const relative = date1.from(date2);
|
|
168
|
+
|
|
169
|
+
expect(typeof relative).toBe("string");
|
|
170
|
+
expect(relative).toContain("day");
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("should get time to specific date", () => {
|
|
174
|
+
const date1 = dayjs("2023-01-01");
|
|
175
|
+
const date2 = dayjs("2023-01-02");
|
|
176
|
+
const relative = date2.to(date1);
|
|
177
|
+
|
|
178
|
+
expect(typeof relative).toBe("string");
|
|
179
|
+
expect(relative).toContain("day");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("should handle relative time for minutes", () => {
|
|
183
|
+
const pastDate = dayjs().subtract(30, "minutes");
|
|
184
|
+
const relative = pastDate.fromNow();
|
|
185
|
+
|
|
186
|
+
expect(relative).toContain("minute");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("should handle relative time for days", () => {
|
|
190
|
+
const pastDate = dayjs().subtract(5, "days");
|
|
191
|
+
const relative = pastDate.fromNow();
|
|
192
|
+
|
|
193
|
+
expect(relative).toContain("day");
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("should handle relative time for months", () => {
|
|
197
|
+
const pastDate = dayjs().subtract(2, "months");
|
|
198
|
+
const relative = pastDate.fromNow();
|
|
199
|
+
|
|
200
|
+
expect(relative).toContain("month");
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("should handle relative time for years", () => {
|
|
204
|
+
const pastDate = dayjs().subtract(2, "years");
|
|
205
|
+
const relative = pastDate.fromNow();
|
|
206
|
+
|
|
207
|
+
expect(relative).toContain("year");
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe("custom relativeTime thresholds", () => {
|
|
212
|
+
it("should respect custom threshold configuration", () => {
|
|
213
|
+
// Our custom config has 59 minutes threshold for 'mm'
|
|
214
|
+
const date = dayjs().subtract(45, "minutes");
|
|
215
|
+
const relative = date.fromNow();
|
|
216
|
+
|
|
217
|
+
// Should show minutes, not hours
|
|
218
|
+
expect(relative).toContain("minute");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("should handle edge case at day threshold", () => {
|
|
222
|
+
const date = dayjs().subtract(29, "days");
|
|
223
|
+
const relative = date.fromNow();
|
|
224
|
+
|
|
225
|
+
// With custom threshold of 29 days, should still show days
|
|
226
|
+
expect(relative).toContain("day");
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("date manipulation", () => {
|
|
231
|
+
it("should add time units", () => {
|
|
232
|
+
const date = dayjs("2023-01-01");
|
|
233
|
+
|
|
234
|
+
expect(date.add(1, "day").date()).toBe(2);
|
|
235
|
+
expect(date.add(1, "month").month()).toBe(1);
|
|
236
|
+
expect(date.add(1, "year").year()).toBe(2024);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("should subtract time units", () => {
|
|
240
|
+
const date = dayjs("2023-01-02");
|
|
241
|
+
|
|
242
|
+
expect(date.subtract(1, "day").date()).toBe(1);
|
|
243
|
+
expect(date.subtract(1, "month").month()).toBe(11); // December of previous year
|
|
244
|
+
expect(date.subtract(1, "year").year()).toBe(2022);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("should start of time unit", () => {
|
|
248
|
+
const date = dayjs("2023-06-15T14:30:45");
|
|
249
|
+
|
|
250
|
+
expect(date.startOf("day").hour()).toBe(0);
|
|
251
|
+
expect(date.startOf("month").date()).toBe(1);
|
|
252
|
+
expect(date.startOf("year").month()).toBe(0);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("should end of time unit", () => {
|
|
256
|
+
const date = dayjs("2023-06-15T14:30:45");
|
|
257
|
+
|
|
258
|
+
expect(date.endOf("day").hour()).toBe(23);
|
|
259
|
+
expect(date.endOf("month").date()).toBe(30); // June has 30 days
|
|
260
|
+
expect(date.endOf("year").month()).toBe(11); // December
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe("formatting", () => {
|
|
265
|
+
it("should format date", () => {
|
|
266
|
+
const date = dayjs("2023-01-01T12:30:45");
|
|
267
|
+
|
|
268
|
+
expect(date.format("YYYY-MM-DD")).toBe("2023-01-01");
|
|
269
|
+
expect(date.format("YYYY/MM/DD HH:mm:ss")).toContain("2023/01/01");
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("should convert to ISO string", () => {
|
|
273
|
+
const date = dayjs("2023-01-01");
|
|
274
|
+
const iso = date.toISOString();
|
|
275
|
+
|
|
276
|
+
expect(iso).toContain("2023-01-01");
|
|
277
|
+
expect(iso).toContain("T");
|
|
278
|
+
expect(iso).toContain("Z");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("should convert to Date object", () => {
|
|
282
|
+
const dayjsDate = dayjs("2023-01-01");
|
|
283
|
+
const jsDate = dayjsDate.toDate();
|
|
284
|
+
|
|
285
|
+
expect(jsDate).toBeInstanceOf(Date);
|
|
286
|
+
expect(jsDate.getFullYear()).toBe(2023);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("comparison", () => {
|
|
291
|
+
it("should check if date is before another", () => {
|
|
292
|
+
const date1 = dayjs("2023-01-01");
|
|
293
|
+
const date2 = dayjs("2023-01-02");
|
|
294
|
+
|
|
295
|
+
expect(date1.isBefore(date2)).toBe(true);
|
|
296
|
+
expect(date2.isBefore(date1)).toBe(false);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("should check if date is after another", () => {
|
|
300
|
+
const date1 = dayjs("2023-01-01");
|
|
301
|
+
const date2 = dayjs("2023-01-02");
|
|
302
|
+
|
|
303
|
+
expect(date2.isAfter(date1)).toBe(true);
|
|
304
|
+
expect(date1.isAfter(date2)).toBe(false);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("should check if date is same as another", () => {
|
|
308
|
+
const date1 = dayjs("2023-01-01");
|
|
309
|
+
const date2 = dayjs("2023-01-01");
|
|
310
|
+
|
|
311
|
+
expect(date1.isSame(date2)).toBe(true);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe("validation", () => {
|
|
316
|
+
it("should validate valid dates", () => {
|
|
317
|
+
expect(dayjs("2023-01-01").isValid()).toBe(true);
|
|
318
|
+
expect(dayjs(new Date()).isValid()).toBe(true);
|
|
319
|
+
expect(dayjs(Date.now()).isValid()).toBe(true);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("should detect invalid dates", () => {
|
|
323
|
+
expect(dayjs("invalid").isValid()).toBe(false);
|
|
324
|
+
expect(dayjs("2023-13-01", "YYYY-MM-DD", true).isValid()).toBe(false);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
});
|
package/dateUtils/index.ts
CHANGED
|
@@ -4,12 +4,14 @@ import timezone from "dayjs/plugin/timezone";
|
|
|
4
4
|
import isoWeek from "dayjs/plugin/isoWeek";
|
|
5
5
|
import duration from "dayjs/plugin/duration";
|
|
6
6
|
import relativeTime from "dayjs/plugin/relativeTime";
|
|
7
|
+
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
7
8
|
|
|
8
9
|
// Extend dayjs with plugins
|
|
9
10
|
dayjs.extend(utc);
|
|
10
11
|
dayjs.extend(timezone);
|
|
11
12
|
dayjs.extend(isoWeek);
|
|
12
13
|
dayjs.extend(duration);
|
|
14
|
+
dayjs.extend(customParseFormat);
|
|
13
15
|
|
|
14
16
|
dayjs.extend(relativeTime, {
|
|
15
17
|
thresholds: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "14.0.23
|
|
3
|
+
"version": "14.0.23",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@applicaster/applicaster-types": "14.0.23
|
|
30
|
+
"@applicaster/applicaster-types": "14.0.23",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|