@jsb188/app 1.1.1 → 1.1.3
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/constants/journal.ts +47 -3
- package/i18n/auth.ts +5 -1
- package/i18n/error.ts +1 -1
- package/i18n/form.ts +3 -0
- package/i18n/user.ts +2 -0
- package/package.json +4 -2
- package/types/app.d.ts +1 -1
- package/types/journal.d.ts +12 -1
- package/utils/datetime.ts +87 -47
- package/utils/journal.ts +3 -0
- package/utils/string.ts +39 -33
- package/utils/timeZone.ts +24 -454
package/constants/journal.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* Journal types
|
|
4
3
|
*/
|
|
5
4
|
|
|
6
5
|
export const JOURNAL_TYPE_ENUMS = [
|
|
6
|
+
'SEED',
|
|
7
7
|
'FIELD',
|
|
8
8
|
'HARVEST',
|
|
9
|
+
'POST_HARVEST',
|
|
10
|
+
'SALES',
|
|
9
11
|
];
|
|
10
12
|
|
|
11
13
|
export const JOURNAL_TYPES_TO_TEXT = {
|
|
14
|
+
SEED: 'seed purchases',
|
|
12
15
|
FIELD: 'field activities',
|
|
13
16
|
HARVEST: 'harvest activities',
|
|
17
|
+
POST_HARVEST: 'handling, washing, sorting, grading, packaging after harvest',
|
|
18
|
+
SALES: 'sales',
|
|
14
19
|
};
|
|
15
20
|
|
|
16
21
|
export const TEXT_TO_JOURNAL_TYPES = Object.fromEntries(
|
|
@@ -21,6 +26,12 @@ export const TEXT_TO_JOURNAL_TYPES = Object.fromEntries(
|
|
|
21
26
|
* Activities for each journal types
|
|
22
27
|
*/
|
|
23
28
|
|
|
29
|
+
export const SEED_LOG_ACTIVITY_ENUMS = [
|
|
30
|
+
'SEED_PURCHASE_INFO',
|
|
31
|
+
'SEED_COMPLIANCE_NOTE',
|
|
32
|
+
'OTHER_SEED_ACTIVITY',
|
|
33
|
+
] as const;
|
|
34
|
+
|
|
24
35
|
export const FIELD_LOG_ACTIVITY_ENUMS = [
|
|
25
36
|
'PREPARE_SOIL',
|
|
26
37
|
'PLANTING',
|
|
@@ -39,15 +50,32 @@ export const HARVEST_LOG_ACTIVITY_ENUMS = [
|
|
|
39
50
|
'HARVEST_COUNT',
|
|
40
51
|
'SORT_GRADE',
|
|
41
52
|
'YIELD_LOSS_ESTIMATE',
|
|
42
|
-
'TRANSFER_TO_STORAGE',
|
|
43
53
|
'OTHER_HARVEST_ACTIVITY',
|
|
44
54
|
] as const;
|
|
45
55
|
|
|
56
|
+
export const POST_HARVEST_LOG_ACTIVITY_ENUMS = [
|
|
57
|
+
'POST_HARVEST_HANDLING',
|
|
58
|
+
'POST_HARVEST_PACKAGING',
|
|
59
|
+
'OTHER_POST_HARVEST_ACTIVITY',
|
|
60
|
+
] as const;
|
|
61
|
+
|
|
62
|
+
export const SALES_LOG_ACTIVITY_ENUMS = [
|
|
63
|
+
'SALE_TRANSACTION',
|
|
64
|
+
'SALE_DETAILS',
|
|
65
|
+
'SALE_FEEDBACK',
|
|
66
|
+
'OTHER_SALES_ACTIVITY',
|
|
67
|
+
] as const;
|
|
68
|
+
|
|
46
69
|
/**
|
|
47
70
|
* Activity enums to text
|
|
48
71
|
*/
|
|
49
72
|
|
|
50
73
|
export const JOURNAL_ACTIVITIES_TO_TEXT = {
|
|
74
|
+
// # Seed log activities
|
|
75
|
+
SEED_PURCHASE_INFO: 'seed purchase information',
|
|
76
|
+
SEED_COMPLIANCE_NOTE: 'seed compliance notes',
|
|
77
|
+
OTHER_SEED_ACTIVITY: 'other seed purchase related notes',
|
|
78
|
+
|
|
51
79
|
// # Field log activities
|
|
52
80
|
PREPARE_SOIL: 'soil, beds preparation',
|
|
53
81
|
PLANTING: 'seeding, transplanting',
|
|
@@ -65,10 +93,26 @@ export const JOURNAL_ACTIVITIES_TO_TEXT = {
|
|
|
65
93
|
HARVEST_COUNT: 'counting, weighing harvested crops',
|
|
66
94
|
SORT_GRADE: 'sorting, grading crops',
|
|
67
95
|
YIELD_LOSS_ESTIMATE: 'estimating yield or loss',
|
|
68
|
-
TRANSFER_TO_STORAGE: 'transferring crops to storage',
|
|
69
96
|
OTHER_HARVEST_ACTIVITY: 'other harvest activities',
|
|
97
|
+
|
|
98
|
+
// # Post-harvest log activities
|
|
99
|
+
POST_HARVEST_HANDLING: 'washing, drying, trimming, sorting, or grading produce',
|
|
100
|
+
POST_HARVEST_PACKAGING: 'packaging, cooling, or moving produce to storage',
|
|
101
|
+
OTHER_POST_HARVEST_ACTIVITY: 'other post-harvest activities',
|
|
102
|
+
|
|
103
|
+
// # Sales log activities
|
|
104
|
+
SALE_TRANSACTION: 'sale transactions',
|
|
105
|
+
SALE_DETAILS: 'sale details',
|
|
106
|
+
SALE_FEEDBACK: 'sale feedback or issues',
|
|
107
|
+
OTHER_SALES_ACTIVITY: 'other sales related notes',
|
|
70
108
|
};
|
|
71
109
|
|
|
72
110
|
export const TEXT_TO_JOURNAL_ACTIVITIES = Object.fromEntries(
|
|
73
111
|
Object.entries(JOURNAL_ACTIVITIES_TO_TEXT).map(([key, value]) => [value, key]),
|
|
74
112
|
) as Record<string, string>;
|
|
113
|
+
|
|
114
|
+
// Moved to walk-in
|
|
115
|
+
// Hydrocooled immediately after harvest
|
|
116
|
+
// Bagged and labeled greens
|
|
117
|
+
// Packed in clamshells
|
|
118
|
+
// Stickered with farm logo
|
package/i18n/auth.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
en: {
|
|
3
3
|
// Login
|
|
4
|
+
welcome_back: 'Welcome back',
|
|
4
5
|
log_in_sign_up: 'Sign in / Sign up',
|
|
5
6
|
open_app: 'Open app',
|
|
6
7
|
continue_with_google: 'Continue with Google',
|
|
@@ -8,6 +9,7 @@ export default {
|
|
|
8
9
|
continue_with_apple: 'Continue with Apple',
|
|
9
10
|
login_opts: 'Continue with e-mail, ID, or @username',
|
|
10
11
|
login_opts_phone_email: 'Continue with phone number or e-mail',
|
|
12
|
+
verify_your_acc: 'Verify your account',
|
|
11
13
|
resend_verification_email: 'Send verification e-mail', // This is for title of <ModalHeader /> in <AuthSwitch />
|
|
12
14
|
reset_password: 'Reset password',
|
|
13
15
|
forgot_password_: 'Forgot password or username?',
|
|
@@ -41,6 +43,7 @@ export default {
|
|
|
41
43
|
|
|
42
44
|
// Sign up
|
|
43
45
|
sign_up: 'Sign up',
|
|
46
|
+
create_account: 'Create an account',
|
|
44
47
|
agree_and_continue: 'Agree and continue',
|
|
45
48
|
sign_up_notice_1: 'By selecting "Agree and continue", I agree to the ',
|
|
46
49
|
sign_up_notice_2: ' and acknowledge the ',
|
|
@@ -58,6 +61,7 @@ export default {
|
|
|
58
61
|
resend_verification: 'Send verification e-mail',
|
|
59
62
|
|
|
60
63
|
// Sign out
|
|
61
|
-
|
|
64
|
+
sign_out: 'Sign out',
|
|
65
|
+
signing_out_: 'Signing you out...'
|
|
62
66
|
},
|
|
63
67
|
};
|
package/i18n/error.ts
CHANGED
|
@@ -85,7 +85,7 @@ export default {
|
|
|
85
85
|
20047: 'You must enter a valid password.',
|
|
86
86
|
20048: 'This action is forbidden because you deleted your account.',
|
|
87
87
|
20049: 'You must activate your account before you can use the app.',
|
|
88
|
-
20050: '
|
|
88
|
+
20050: 'This page does not exist.',
|
|
89
89
|
20051: 'Could not find user with that phone number. (%{value})',
|
|
90
90
|
20052: 'You do not have access to this organization\'s data.',
|
|
91
91
|
|
package/i18n/form.ts
CHANGED
|
@@ -7,6 +7,8 @@ export default {
|
|
|
7
7
|
or: 'or',
|
|
8
8
|
cancel: 'Cancel',
|
|
9
9
|
continue: 'Continue',
|
|
10
|
+
apply: 'Apply',
|
|
11
|
+
apply_filters: 'Apply filters',
|
|
10
12
|
hide: 'Hide',
|
|
11
13
|
show: 'Show',
|
|
12
14
|
try_again: 'Try again',
|
|
@@ -57,6 +59,7 @@ export default {
|
|
|
57
59
|
click_here: 'Click here',
|
|
58
60
|
success: 'Success',
|
|
59
61
|
success_: 'Success!',
|
|
62
|
+
help: 'Help',
|
|
60
63
|
|
|
61
64
|
// Day periods
|
|
62
65
|
greet_MORNING: 'Good morning, %{name}.',
|
package/i18n/user.ts
CHANGED
|
@@ -64,10 +64,12 @@ export default {
|
|
|
64
64
|
copy_id: 'Copy ID',
|
|
65
65
|
|
|
66
66
|
// Profile
|
|
67
|
+
your_profile: 'Your profile',
|
|
67
68
|
open_profile: 'Open profile',
|
|
68
69
|
cards_ct: '%{smart_count} Card||||%{smart_count} Cards',
|
|
69
70
|
report_user: 'Report user',
|
|
70
71
|
profile_deactivated_desc: 'This account has been deactivated.',
|
|
72
|
+
phone_numbers: 'Phone numbers',
|
|
71
73
|
|
|
72
74
|
// Friend status
|
|
73
75
|
blocked: 'Blocked',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/app",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Contains all the basic requirements for all @jsb188 apps.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "jsb188",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"./constants/app": "./constants/app.ts",
|
|
15
15
|
"./constants/billing": "./constants/billing.ts",
|
|
16
16
|
"./constants/emoji": "./constants/emoji.ts",
|
|
17
|
+
"./constants/journal": "./constants/journal.ts",
|
|
17
18
|
"./constants/user": "./constants/user.ts",
|
|
18
19
|
"./constants/ws": "./constants/ws.ts",
|
|
19
20
|
"./utils/api": "./utils/api.ts",
|
|
@@ -36,7 +37,8 @@
|
|
|
36
37
|
"./types/user.d": "./types/user.d.ts"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"node-polyglot": "^2.6.0"
|
|
40
|
+
"node-polyglot": "^2.6.0",
|
|
41
|
+
"luxon": "^3.6.1"
|
|
40
42
|
},
|
|
41
43
|
"scripts": {
|
|
42
44
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/types/app.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface EditUserPlusModalProps extends EditIfaceModalProps {
|
|
|
24
24
|
|
|
25
25
|
export type DarkOrLightEnum = 'light' | 'dark';
|
|
26
26
|
|
|
27
|
-
export type ColorEnum = 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose' | 'slate' | 'zinc' | 'stone';
|
|
27
|
+
export type ColorEnum = 'red' | 'orange' | 'brown' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose' | 'slate' | 'zinc' | 'stone';
|
|
28
28
|
|
|
29
29
|
// Stripe types
|
|
30
30
|
|
package/types/journal.d.ts
CHANGED
|
@@ -21,4 +21,15 @@ export interface JournalEntryObj {
|
|
|
21
21
|
export type JournalTypeEnum = typeof JOURNAL_TYPE_ENUMS[number];
|
|
22
22
|
export type FieldLogActivityEnum = typeof FIELD_LOG_ACTIVITY_ENUMS[number];
|
|
23
23
|
export type HarvestLogActivityEnum = typeof HARVEST_LOG_ACTIVITY_ENUMS[number];
|
|
24
|
-
export type JournalEntryActivityEnum = FieldLogActivityEnum | HarvestLogActivityEnum;
|
|
24
|
+
export type JournalEntryActivityEnum = FieldLogActivityEnum | HarvestLogActivityEnum;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Filters for search
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export interface FilterJournalEntriesArgs {
|
|
31
|
+
type?: JournalTypeEnum | null;
|
|
32
|
+
startDate?: string | null;
|
|
33
|
+
endDate?: string | null;
|
|
34
|
+
query?: string;
|
|
35
|
+
}
|
package/utils/datetime.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
1
2
|
import i18n from '../i18n';
|
|
2
3
|
import { isValidTimeZone, parseDateInTimezone } from './timeZone';
|
|
3
4
|
|
|
@@ -17,7 +18,7 @@ export type DatePeriodEnum =
|
|
|
17
18
|
| 'OLDER';
|
|
18
19
|
|
|
19
20
|
export interface DatePeriodObj {
|
|
20
|
-
datePeriod: DatePeriodEnum
|
|
21
|
+
datePeriod: DatePeriodEnum;
|
|
21
22
|
date: Date;
|
|
22
23
|
item: any;
|
|
23
24
|
}
|
|
@@ -39,7 +40,7 @@ interface FullTimeParams {
|
|
|
39
40
|
hideTime: boolean;
|
|
40
41
|
textDateStyle: 'long' | 'short' | null;
|
|
41
42
|
alwaysShowYear: boolean;
|
|
42
|
-
|
|
43
|
+
includeWeekday: boolean;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
/**
|
|
@@ -115,7 +116,7 @@ export function getFullDateTime(
|
|
|
115
116
|
hideTime,
|
|
116
117
|
textDateStyle,
|
|
117
118
|
alwaysShowYear,
|
|
118
|
-
|
|
119
|
+
includeWeekday,
|
|
119
120
|
} = params || {};
|
|
120
121
|
|
|
121
122
|
let d;
|
|
@@ -152,7 +153,7 @@ export function getFullDateTime(
|
|
|
152
153
|
return d.toLocaleDateString(locales, {
|
|
153
154
|
timeZone,
|
|
154
155
|
day: 'numeric',
|
|
155
|
-
|
|
156
|
+
weekday: includeWeekday && textDateStyle === 'long' ? 'long' : includeWeekday ? 'short' : undefined,
|
|
156
157
|
month: textDateStyle || 'numeric',
|
|
157
158
|
year: hideYear_ ? undefined : 'numeric',
|
|
158
159
|
hour: hideTime ? undefined : 'numeric',
|
|
@@ -197,30 +198,18 @@ export function getTodayStartOfDay(timeZone?: string | null) {
|
|
|
197
198
|
*/
|
|
198
199
|
|
|
199
200
|
export function getCalDate(d: Date, timeZone_?: string | null) {
|
|
200
|
-
|
|
201
|
-
if (timeZone && !isValidTimeZone(timeZone)) {
|
|
202
|
-
timeZone = undefined;
|
|
203
|
-
}
|
|
201
|
+
const timeZone = timeZone_ || undefined;
|
|
204
202
|
|
|
205
|
-
|
|
206
|
-
timeZone,
|
|
207
|
-
year: 'numeric',
|
|
208
|
-
month: '2-digit',
|
|
209
|
-
day: '2-digit',
|
|
210
|
-
});
|
|
203
|
+
let dt = DateTime.fromJSDate(d, { zone: timeZone });
|
|
211
204
|
|
|
212
|
-
//
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
205
|
+
// If timezone is invalid, fallback to system/local
|
|
206
|
+
if (!dt.isValid) {
|
|
207
|
+
dt = DateTime.fromJSDate(d); // system default zone
|
|
208
|
+
}
|
|
216
209
|
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
minute: '2-digit',
|
|
221
|
-
second: '2-digit',
|
|
222
|
-
hour12: false,
|
|
223
|
-
});
|
|
210
|
+
const calDate = dt.toFormat('yyyy-MM-dd');
|
|
211
|
+
const calDateInt = Number(dt.toFormat('yyyyMMdd'));
|
|
212
|
+
const time = dt.toFormat('HH:mm:ss');
|
|
224
213
|
|
|
225
214
|
return {
|
|
226
215
|
calDate,
|
|
@@ -229,6 +218,57 @@ export function getCalDate(d: Date, timeZone_?: string | null) {
|
|
|
229
218
|
};
|
|
230
219
|
}
|
|
231
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Convert Int cal date to String YYYY-MM-DD format
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
export function convertIntToCalDate(calDateInt: number | string): string {
|
|
226
|
+
const value = String(calDateInt);
|
|
227
|
+
if (value.length === 8) {
|
|
228
|
+
return `${value.slice(0, 4)}-${value.slice(4, 6)}-${value.slice(6, 8)}`;
|
|
229
|
+
}
|
|
230
|
+
// If not 8 digits, return as is
|
|
231
|
+
return value;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Check if cal date is valid
|
|
236
|
+
* @param calDate - Cal date in YYYYMMDD format
|
|
237
|
+
* @param minCalDate - Optional minimum cal date to check against (default is 19500101)
|
|
238
|
+
* @returns boolean - true if valid, false otherwise
|
|
239
|
+
*/
|
|
240
|
+
|
|
241
|
+
export function isValidCalDate(
|
|
242
|
+
calDate: string | number,
|
|
243
|
+
minCalDate: number = 19500101,
|
|
244
|
+
): boolean {
|
|
245
|
+
const value = Number(calDate);
|
|
246
|
+
if (!calDate || !Number.isInteger(value) || value < 10000000 || value > 90000000) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
return !minCalDate || value >= minCalDate;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Check cal date is not a future date
|
|
254
|
+
* @param calDateVal - Cal date in YYYYMMDD format
|
|
255
|
+
* @param addDays - Optional number of days to add to the current date for comparison (default is 0)
|
|
256
|
+
* @param timeZone - Optional timezone to check against
|
|
257
|
+
* @returns boolean - true if date is in the future, false otherwise
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
export function isFutureCalDate(
|
|
261
|
+
calDateVal: number | string,
|
|
262
|
+
addDays: number = 0,
|
|
263
|
+
timeZone?: string | null,
|
|
264
|
+
): boolean {
|
|
265
|
+
if (!isValidCalDate(calDateVal)) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
const today = getCalDate(new Date(), timeZone);
|
|
269
|
+
return (today.calDateInt + addDays) < Number(calDateVal);
|
|
270
|
+
}
|
|
271
|
+
|
|
232
272
|
/**
|
|
233
273
|
* Convert date time "time" ago
|
|
234
274
|
*/
|
|
@@ -409,11 +449,11 @@ export function getDateFromCalDate(calDate: string) {
|
|
|
409
449
|
*/
|
|
410
450
|
|
|
411
451
|
export function groupByDatePeriod<T>(
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
452
|
+
items: T[],
|
|
453
|
+
dateKey: string,
|
|
454
|
+
groupByDate?: boolean,
|
|
455
|
+
timeZone?: string | null,
|
|
456
|
+
mapFn?: (item: any) => any,
|
|
417
457
|
): DatePeriodObj[][] {
|
|
418
458
|
const ordered = items.sort((a: any, b: any) => {
|
|
419
459
|
const valueA = a[dateKey];
|
|
@@ -430,7 +470,7 @@ export function groupByDatePeriod<T>(
|
|
|
430
470
|
|
|
431
471
|
const output = [];
|
|
432
472
|
const d = new Date();
|
|
433
|
-
|
|
473
|
+
// const timeZone = timeZone_; // || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
434
474
|
|
|
435
475
|
let group: any[] | null = [];
|
|
436
476
|
for (const item of ordered) {
|
|
@@ -440,7 +480,7 @@ export function groupByDatePeriod<T>(
|
|
|
440
480
|
|
|
441
481
|
const lastItem = group[group.length - 1];
|
|
442
482
|
const lastDatePeriod: any = lastItem?.datePeriod;
|
|
443
|
-
const date = new Date(
|
|
483
|
+
const date = new Date(item[dateKey]);
|
|
444
484
|
const datePeriod = groupByDate ? getCalDate(date, timeZone).calDate : getDatePeriod(date, d);
|
|
445
485
|
|
|
446
486
|
const dateObj = {
|
|
@@ -450,11 +490,11 @@ export function groupByDatePeriod<T>(
|
|
|
450
490
|
};
|
|
451
491
|
|
|
452
492
|
if (lastDatePeriod && lastDatePeriod !== datePeriod && group.length) {
|
|
453
|
-
|
|
454
|
-
|
|
493
|
+
output.push(group);
|
|
494
|
+
group = [];
|
|
455
495
|
}
|
|
456
496
|
|
|
457
|
-
|
|
497
|
+
group.push(dateObj);
|
|
458
498
|
}
|
|
459
499
|
|
|
460
500
|
if (group.length) {
|
|
@@ -475,11 +515,11 @@ export function groupByDatePeriod<T>(
|
|
|
475
515
|
*/
|
|
476
516
|
|
|
477
517
|
export function labelSortByDatePeriod<T>(
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
518
|
+
items: T[],
|
|
519
|
+
dateKey: string,
|
|
520
|
+
groupByDate?: boolean,
|
|
521
|
+
timeZone?: string | null,
|
|
522
|
+
mapFn?: (item: any) => any,
|
|
483
523
|
): DatePeriodObj[] {
|
|
484
524
|
const ordered = items.sort((a: any, b: any) => {
|
|
485
525
|
const valueA = a[dateKey];
|
|
@@ -500,7 +540,7 @@ export function labelSortByDatePeriod<T>(
|
|
|
500
540
|
for (const item of ordered) {
|
|
501
541
|
const lastItem = output[output.length - 1];
|
|
502
542
|
const lastDatePeriod: any = lastItem?.datePeriod;
|
|
503
|
-
const date = new Date(
|
|
543
|
+
const date = new Date(item[dateKey]);
|
|
504
544
|
const datePeriod = groupByDate ? getCalDate(date, timeZone).calDate : getDatePeriod(date, d);
|
|
505
545
|
|
|
506
546
|
const dateObj = {
|
|
@@ -513,14 +553,14 @@ export function labelSortByDatePeriod<T>(
|
|
|
513
553
|
(!output.length) ||
|
|
514
554
|
(lastDatePeriod && lastDatePeriod !== datePeriod)
|
|
515
555
|
) {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
556
|
+
output.push({
|
|
557
|
+
datePeriod,
|
|
558
|
+
date,
|
|
559
|
+
item: null,
|
|
560
|
+
});
|
|
521
561
|
}
|
|
522
562
|
|
|
523
|
-
|
|
563
|
+
output.push(dateObj);
|
|
524
564
|
}
|
|
525
565
|
|
|
526
566
|
return output;
|
package/utils/journal.ts
CHANGED
|
@@ -7,8 +7,11 @@ import type { JournalTypeEnum } from '../types/journal.d';
|
|
|
7
7
|
|
|
8
8
|
export function getJournalTypeColor(type: JournalTypeEnum): ColorEnum {
|
|
9
9
|
const journalTypeToColor = {
|
|
10
|
+
SEED: 'brown',
|
|
10
11
|
FIELD: 'yellow',
|
|
11
12
|
HARVEST: 'green',
|
|
13
|
+
POST_HARVEST: 'cyan',
|
|
14
|
+
SALES: 'blue',
|
|
12
15
|
} as Record<JournalTypeEnum, ColorEnum>;
|
|
13
16
|
|
|
14
17
|
// Default to zinc if type is not found
|
package/utils/string.ts
CHANGED
|
@@ -41,13 +41,19 @@ export function shortenToSpace(
|
|
|
41
41
|
* Shorten word to space, and remove article words
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
|
-
export function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
export function guessFirstName(str: string, len: number = 40): string {
|
|
45
|
+
|
|
46
|
+
let shortened = str?.replace(/^(a|an|the|da|de|that|there|this|than|then)\b/i, '')?.trim() || '';
|
|
47
|
+
const spaceIx = shortened.indexOf(' ');
|
|
48
|
+
|
|
49
|
+
if (spaceIx >= 0) {
|
|
50
|
+
shortened = shortened.substring(0, spaceIx + 1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (len < shortened.length) {
|
|
54
|
+
shortened = shortened.substring(0, len);
|
|
55
|
+
}
|
|
49
56
|
|
|
50
|
-
const shortened = shortenToSpace(articleReplacedStart, len, '');
|
|
51
57
|
const articleReplacedEnd = shortened.replace(
|
|
52
58
|
/\b(a|an|the|da|de|that|there|this|than|then)$/i,
|
|
53
59
|
'',
|
|
@@ -191,9 +197,9 @@ export function regexFromText(text: string) {
|
|
|
191
197
|
*/
|
|
192
198
|
|
|
193
199
|
export function ucFirst(str: string) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
200
|
+
if (!str) {
|
|
201
|
+
return '';
|
|
202
|
+
}
|
|
197
203
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
198
204
|
}
|
|
199
205
|
|
|
@@ -261,7 +267,7 @@ export function isInvisibleString(str: string) {
|
|
|
261
267
|
* NOTE: Userful for building AI prompts
|
|
262
268
|
*/
|
|
263
269
|
|
|
264
|
-
export function buildSingleText(lines: (string | undefined | false | null)[]) {
|
|
270
|
+
export function buildSingleText(lines: (string | undefined | false | null)[], delemiter: string = '\n') {
|
|
265
271
|
return lines
|
|
266
272
|
.reduce((acc, line_) => {
|
|
267
273
|
const line = line_ || '';
|
|
@@ -270,7 +276,7 @@ export function buildSingleText(lines: (string | undefined | false | null)[]) {
|
|
|
270
276
|
}
|
|
271
277
|
return acc;
|
|
272
278
|
}, [] as string[])
|
|
273
|
-
.join(
|
|
279
|
+
.join(delemiter)
|
|
274
280
|
.trim();
|
|
275
281
|
}
|
|
276
282
|
|
|
@@ -284,14 +290,14 @@ export function buildSingleText(lines: (string | undefined | false | null)[]) {
|
|
|
284
290
|
*/
|
|
285
291
|
|
|
286
292
|
export function joinReadable(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
293
|
+
texts: string[],
|
|
294
|
+
separator: string = ', ',
|
|
295
|
+
lastSeparator: string = ' and ',
|
|
290
296
|
) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
297
|
+
const lastIx = texts.length - 1;
|
|
298
|
+
return texts.reduce((acc, text, i) => {
|
|
299
|
+
return acc + (!acc ? '' : i === lastIx ? lastSeparator : separator) + text;
|
|
300
|
+
}, '');
|
|
295
301
|
}
|
|
296
302
|
|
|
297
303
|
/**
|
|
@@ -304,20 +310,20 @@ export function joinReadable(
|
|
|
304
310
|
*/
|
|
305
311
|
|
|
306
312
|
export function textWithBrackets(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
313
|
+
text: string,
|
|
314
|
+
bracketsText?: string | string[],
|
|
315
|
+
brackets: [string, string] = ['(', ')'],
|
|
310
316
|
) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
317
|
+
let bText;
|
|
318
|
+
if (Array.isArray(bracketsText)) {
|
|
319
|
+
bText = bracketsText.filter(Boolean).join(' ').trim();
|
|
320
|
+
} else {
|
|
321
|
+
bText = bracketsText?.trim();
|
|
322
|
+
}
|
|
323
|
+
if (!bText) {
|
|
324
|
+
return text;
|
|
325
|
+
} else if (!text) {
|
|
326
|
+
return bText;
|
|
327
|
+
}
|
|
328
|
+
return `${text} ${brackets[0].trimStart()}${bText}${brackets[1].trimEnd()}`;
|
|
323
329
|
}
|
package/utils/timeZone.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
|
|
1
3
|
// Source: https://raw.githubusercontent.com/moment/moment-timezone/refs/heads/develop/data/meta/latest.json
|
|
2
4
|
|
|
3
|
-
const DEFAULT_TIMEZONE = 'America/
|
|
5
|
+
const DEFAULT_TIMEZONE = 'America/Los_Angeles';
|
|
4
6
|
|
|
5
7
|
const TIMEZONE_DATA = {
|
|
6
8
|
AD: {
|
|
@@ -1840,427 +1842,6 @@ const TIMEZONE_DATA = {
|
|
|
1840
1842
|
list: string[];
|
|
1841
1843
|
}>;
|
|
1842
1844
|
|
|
1843
|
-
const TIMEZONES_LIST = [
|
|
1844
|
-
'Africa/Abidjan',
|
|
1845
|
-
'Africa/Accra',
|
|
1846
|
-
'Africa/Addis_Ababa',
|
|
1847
|
-
'Africa/Algiers',
|
|
1848
|
-
'Africa/Asmara',
|
|
1849
|
-
'Africa/Bamako',
|
|
1850
|
-
'Africa/Bangui',
|
|
1851
|
-
'Africa/Banjul',
|
|
1852
|
-
'Africa/Bissau',
|
|
1853
|
-
'Africa/Blantyre',
|
|
1854
|
-
'Africa/Brazzaville',
|
|
1855
|
-
'Africa/Bujumbura',
|
|
1856
|
-
'Africa/Cairo',
|
|
1857
|
-
'Africa/Casablanca',
|
|
1858
|
-
'Africa/Ceuta',
|
|
1859
|
-
'Africa/Conakry',
|
|
1860
|
-
'Africa/Dakar',
|
|
1861
|
-
'Africa/Dar_es_Salaam',
|
|
1862
|
-
'Africa/Djibouti',
|
|
1863
|
-
'Africa/Douala',
|
|
1864
|
-
'Africa/El_Aaiun',
|
|
1865
|
-
'Africa/Freetown',
|
|
1866
|
-
'Africa/Gaborone',
|
|
1867
|
-
'Africa/Harare',
|
|
1868
|
-
'Africa/Johannesburg',
|
|
1869
|
-
'Africa/Juba',
|
|
1870
|
-
'Africa/Kampala',
|
|
1871
|
-
'Africa/Khartoum',
|
|
1872
|
-
'Africa/Kigali',
|
|
1873
|
-
'Africa/Kinshasa',
|
|
1874
|
-
'Africa/Lagos',
|
|
1875
|
-
'Africa/Libreville',
|
|
1876
|
-
'Africa/Lome',
|
|
1877
|
-
'Africa/Luanda',
|
|
1878
|
-
'Africa/Lubumbashi',
|
|
1879
|
-
'Africa/Lusaka',
|
|
1880
|
-
'Africa/Malabo',
|
|
1881
|
-
'Africa/Maputo',
|
|
1882
|
-
'Africa/Maseru',
|
|
1883
|
-
'Africa/Mbabane',
|
|
1884
|
-
'Africa/Mogadishu',
|
|
1885
|
-
'Africa/Monrovia',
|
|
1886
|
-
'Africa/Nairobi',
|
|
1887
|
-
'Africa/Ndjamena',
|
|
1888
|
-
'Africa/Niamey',
|
|
1889
|
-
'Africa/Nouakchott',
|
|
1890
|
-
'Africa/Ouagadougou',
|
|
1891
|
-
'Africa/Porto-Novo',
|
|
1892
|
-
'Africa/Sao_Tome',
|
|
1893
|
-
'Africa/Tripoli',
|
|
1894
|
-
'Africa/Tunis',
|
|
1895
|
-
'Africa/Windhoek',
|
|
1896
|
-
'America/Adak',
|
|
1897
|
-
'America/Anchorage',
|
|
1898
|
-
'America/Anguilla',
|
|
1899
|
-
'America/Antigua',
|
|
1900
|
-
'America/Araguaina',
|
|
1901
|
-
'America/Argentina/Buenos_Aires',
|
|
1902
|
-
'America/Argentina/Catamarca',
|
|
1903
|
-
'America/Argentina/Cordoba',
|
|
1904
|
-
'America/Argentina/Jujuy',
|
|
1905
|
-
'America/Argentina/La_Rioja',
|
|
1906
|
-
'America/Argentina/Mendoza',
|
|
1907
|
-
'America/Argentina/Rio_Gallegos',
|
|
1908
|
-
'America/Argentina/Salta',
|
|
1909
|
-
'America/Argentina/San_Juan',
|
|
1910
|
-
'America/Argentina/San_Luis',
|
|
1911
|
-
'America/Argentina/Tucuman',
|
|
1912
|
-
'America/Argentina/Ushuaia',
|
|
1913
|
-
'America/Aruba',
|
|
1914
|
-
'America/Asuncion',
|
|
1915
|
-
'America/Atikokan',
|
|
1916
|
-
'America/Bahia',
|
|
1917
|
-
'America/Bahia_Banderas',
|
|
1918
|
-
'America/Barbados',
|
|
1919
|
-
'America/Belem',
|
|
1920
|
-
'America/Belize',
|
|
1921
|
-
'America/Blanc-Sablon',
|
|
1922
|
-
'America/Boa_Vista',
|
|
1923
|
-
'America/Bogota',
|
|
1924
|
-
'America/Boise',
|
|
1925
|
-
'America/Cambridge_Bay',
|
|
1926
|
-
'America/Campo_Grande',
|
|
1927
|
-
'America/Cancun',
|
|
1928
|
-
'America/Caracas',
|
|
1929
|
-
'America/Cayenne',
|
|
1930
|
-
'America/Cayman',
|
|
1931
|
-
'America/Chicago',
|
|
1932
|
-
'America/Chihuahua',
|
|
1933
|
-
'America/Ciudad_Juarez',
|
|
1934
|
-
'America/Costa_Rica',
|
|
1935
|
-
'America/Coyhaique',
|
|
1936
|
-
'America/Creston',
|
|
1937
|
-
'America/Cuiaba',
|
|
1938
|
-
'America/Curacao',
|
|
1939
|
-
'America/Danmarkshavn',
|
|
1940
|
-
'America/Dawson',
|
|
1941
|
-
'America/Dawson_Creek',
|
|
1942
|
-
'America/Denver',
|
|
1943
|
-
'America/Detroit',
|
|
1944
|
-
'America/Dominica',
|
|
1945
|
-
'America/Edmonton',
|
|
1946
|
-
'America/Eirunepe',
|
|
1947
|
-
'America/El_Salvador',
|
|
1948
|
-
'America/Fort_Nelson',
|
|
1949
|
-
'America/Fortaleza',
|
|
1950
|
-
'America/Glace_Bay',
|
|
1951
|
-
'America/Goose_Bay',
|
|
1952
|
-
'America/Grand_Turk',
|
|
1953
|
-
'America/Grenada',
|
|
1954
|
-
'America/Guadeloupe',
|
|
1955
|
-
'America/Guatemala',
|
|
1956
|
-
'America/Guayaquil',
|
|
1957
|
-
'America/Guyana',
|
|
1958
|
-
'America/Halifax',
|
|
1959
|
-
'America/Havana',
|
|
1960
|
-
'America/Hermosillo',
|
|
1961
|
-
'America/Indiana/Indianapolis',
|
|
1962
|
-
'America/Indiana/Knox',
|
|
1963
|
-
'America/Indiana/Marengo',
|
|
1964
|
-
'America/Indiana/Petersburg',
|
|
1965
|
-
'America/Indiana/Tell_City',
|
|
1966
|
-
'America/Indiana/Vevay',
|
|
1967
|
-
'America/Indiana/Vincennes',
|
|
1968
|
-
'America/Indiana/Winamac',
|
|
1969
|
-
'America/Inuvik',
|
|
1970
|
-
'America/Iqaluit',
|
|
1971
|
-
'America/Jamaica',
|
|
1972
|
-
'America/Juneau',
|
|
1973
|
-
'America/Kentucky/Louisville',
|
|
1974
|
-
'America/Kentucky/Monticello',
|
|
1975
|
-
'America/Kralendijk',
|
|
1976
|
-
'America/La_Paz',
|
|
1977
|
-
'America/Lima',
|
|
1978
|
-
'America/Los_Angeles',
|
|
1979
|
-
'America/Lower_Princes',
|
|
1980
|
-
'America/Maceio',
|
|
1981
|
-
'America/Managua',
|
|
1982
|
-
'America/Manaus',
|
|
1983
|
-
'America/Marigot',
|
|
1984
|
-
'America/Martinique',
|
|
1985
|
-
'America/Matamoros',
|
|
1986
|
-
'America/Mazatlan',
|
|
1987
|
-
'America/Menominee',
|
|
1988
|
-
'America/Merida',
|
|
1989
|
-
'America/Metlakatla',
|
|
1990
|
-
'America/Mexico_City',
|
|
1991
|
-
'America/Miquelon',
|
|
1992
|
-
'America/Moncton',
|
|
1993
|
-
'America/Monterrey',
|
|
1994
|
-
'America/Montevideo',
|
|
1995
|
-
'America/Montserrat',
|
|
1996
|
-
'America/Nassau',
|
|
1997
|
-
'America/New_York',
|
|
1998
|
-
'America/Nome',
|
|
1999
|
-
'America/Noronha',
|
|
2000
|
-
'America/North_Dakota/Beulah',
|
|
2001
|
-
'America/North_Dakota/Center',
|
|
2002
|
-
'America/North_Dakota/New_Salem',
|
|
2003
|
-
'America/Nuuk',
|
|
2004
|
-
'America/Ojinaga',
|
|
2005
|
-
'America/Panama',
|
|
2006
|
-
'America/Paramaribo',
|
|
2007
|
-
'America/Phoenix',
|
|
2008
|
-
'America/Port-au-Prince',
|
|
2009
|
-
'America/Port_of_Spain',
|
|
2010
|
-
'America/Porto_Velho',
|
|
2011
|
-
'America/Puerto_Rico',
|
|
2012
|
-
'America/Punta_Arenas',
|
|
2013
|
-
'America/Rankin_Inlet',
|
|
2014
|
-
'America/Recife',
|
|
2015
|
-
'America/Regina',
|
|
2016
|
-
'America/Resolute',
|
|
2017
|
-
'America/Rio_Branco',
|
|
2018
|
-
'America/Santarem',
|
|
2019
|
-
'America/Santiago',
|
|
2020
|
-
'America/Santo_Domingo',
|
|
2021
|
-
'America/Sao_Paulo',
|
|
2022
|
-
'America/Scoresbysund',
|
|
2023
|
-
'America/Sitka',
|
|
2024
|
-
'America/St_Barthelemy',
|
|
2025
|
-
'America/St_Johns',
|
|
2026
|
-
'America/St_Kitts',
|
|
2027
|
-
'America/St_Lucia',
|
|
2028
|
-
'America/St_Thomas',
|
|
2029
|
-
'America/St_Vincent',
|
|
2030
|
-
'America/Swift_Current',
|
|
2031
|
-
'America/Tegucigalpa',
|
|
2032
|
-
'America/Thule',
|
|
2033
|
-
'America/Tijuana',
|
|
2034
|
-
'America/Toronto',
|
|
2035
|
-
'America/Tortola',
|
|
2036
|
-
'America/Vancouver',
|
|
2037
|
-
'America/Whitehorse',
|
|
2038
|
-
'America/Winnipeg',
|
|
2039
|
-
'America/Yakutat',
|
|
2040
|
-
'Antarctica/Casey',
|
|
2041
|
-
'Antarctica/Davis',
|
|
2042
|
-
'Antarctica/DumontDUrville',
|
|
2043
|
-
'Antarctica/Macquarie',
|
|
2044
|
-
'Antarctica/Mawson',
|
|
2045
|
-
'Antarctica/McMurdo',
|
|
2046
|
-
'Antarctica/Palmer',
|
|
2047
|
-
'Antarctica/Rothera',
|
|
2048
|
-
'Antarctica/Syowa',
|
|
2049
|
-
'Antarctica/Troll',
|
|
2050
|
-
'Antarctica/Vostok',
|
|
2051
|
-
'Arctic/Longyearbyen',
|
|
2052
|
-
'Asia/Aden',
|
|
2053
|
-
'Asia/Almaty',
|
|
2054
|
-
'Asia/Amman',
|
|
2055
|
-
'Asia/Anadyr',
|
|
2056
|
-
'Asia/Aqtau',
|
|
2057
|
-
'Asia/Aqtobe',
|
|
2058
|
-
'Asia/Ashgabat',
|
|
2059
|
-
'Asia/Atyrau',
|
|
2060
|
-
'Asia/Baghdad',
|
|
2061
|
-
'Asia/Bahrain',
|
|
2062
|
-
'Asia/Baku',
|
|
2063
|
-
'Asia/Bangkok',
|
|
2064
|
-
'Asia/Barnaul',
|
|
2065
|
-
'Asia/Beirut',
|
|
2066
|
-
'Asia/Bishkek',
|
|
2067
|
-
'Asia/Brunei',
|
|
2068
|
-
'Asia/Chita',
|
|
2069
|
-
'Asia/Colombo',
|
|
2070
|
-
'Asia/Damascus',
|
|
2071
|
-
'Asia/Dhaka',
|
|
2072
|
-
'Asia/Dili',
|
|
2073
|
-
'Asia/Dubai',
|
|
2074
|
-
'Asia/Dushanbe',
|
|
2075
|
-
'Asia/Famagusta',
|
|
2076
|
-
'Asia/Gaza',
|
|
2077
|
-
'Asia/Hebron',
|
|
2078
|
-
'Asia/Ho_Chi_Minh',
|
|
2079
|
-
'Asia/Hong_Kong',
|
|
2080
|
-
'Asia/Hovd',
|
|
2081
|
-
'Asia/Irkutsk',
|
|
2082
|
-
'Asia/Jakarta',
|
|
2083
|
-
'Asia/Jayapura',
|
|
2084
|
-
'Asia/Jerusalem',
|
|
2085
|
-
'Asia/Kabul',
|
|
2086
|
-
'Asia/Kamchatka',
|
|
2087
|
-
'Asia/Karachi',
|
|
2088
|
-
'Asia/Kathmandu',
|
|
2089
|
-
'Asia/Khandyga',
|
|
2090
|
-
'Asia/Kolkata',
|
|
2091
|
-
'Asia/Krasnoyarsk',
|
|
2092
|
-
'Asia/Kuala_Lumpur',
|
|
2093
|
-
'Asia/Kuching',
|
|
2094
|
-
'Asia/Kuwait',
|
|
2095
|
-
'Asia/Macau',
|
|
2096
|
-
'Asia/Magadan',
|
|
2097
|
-
'Asia/Makassar',
|
|
2098
|
-
'Asia/Manila',
|
|
2099
|
-
'Asia/Muscat',
|
|
2100
|
-
'Asia/Nicosia',
|
|
2101
|
-
'Asia/Novokuznetsk',
|
|
2102
|
-
'Asia/Novosibirsk',
|
|
2103
|
-
'Asia/Omsk',
|
|
2104
|
-
'Asia/Oral',
|
|
2105
|
-
'Asia/Phnom_Penh',
|
|
2106
|
-
'Asia/Pontianak',
|
|
2107
|
-
'Asia/Pyongyang',
|
|
2108
|
-
'Asia/Qatar',
|
|
2109
|
-
'Asia/Qostanay',
|
|
2110
|
-
'Asia/Qyzylorda',
|
|
2111
|
-
'Asia/Riyadh',
|
|
2112
|
-
'Asia/Sakhalin',
|
|
2113
|
-
'Asia/Samarkand',
|
|
2114
|
-
'Asia/Seoul',
|
|
2115
|
-
'Asia/Shanghai',
|
|
2116
|
-
'Asia/Singapore',
|
|
2117
|
-
'Asia/Srednekolymsk',
|
|
2118
|
-
'Asia/Taipei',
|
|
2119
|
-
'Asia/Tashkent',
|
|
2120
|
-
'Asia/Tbilisi',
|
|
2121
|
-
'Asia/Tehran',
|
|
2122
|
-
'Asia/Thimphu',
|
|
2123
|
-
'Asia/Tokyo',
|
|
2124
|
-
'Asia/Tomsk',
|
|
2125
|
-
'Asia/Ulaanbaatar',
|
|
2126
|
-
'Asia/Urumqi',
|
|
2127
|
-
'Asia/Ust-Nera',
|
|
2128
|
-
'Asia/Vientiane',
|
|
2129
|
-
'Asia/Vladivostok',
|
|
2130
|
-
'Asia/Yakutsk',
|
|
2131
|
-
'Asia/Yangon',
|
|
2132
|
-
'Asia/Yekaterinburg',
|
|
2133
|
-
'Asia/Yerevan',
|
|
2134
|
-
'Atlantic/Azores',
|
|
2135
|
-
'Atlantic/Bermuda',
|
|
2136
|
-
'Atlantic/Canary',
|
|
2137
|
-
'Atlantic/Cape_Verde',
|
|
2138
|
-
'Atlantic/Faroe',
|
|
2139
|
-
'Atlantic/Madeira',
|
|
2140
|
-
'Atlantic/Reykjavik',
|
|
2141
|
-
'Atlantic/South_Georgia',
|
|
2142
|
-
'Atlantic/St_Helena',
|
|
2143
|
-
'Atlantic/Stanley',
|
|
2144
|
-
'Australia/Adelaide',
|
|
2145
|
-
'Australia/Brisbane',
|
|
2146
|
-
'Australia/Broken_Hill',
|
|
2147
|
-
'Australia/Darwin',
|
|
2148
|
-
'Australia/Eucla',
|
|
2149
|
-
'Australia/Hobart',
|
|
2150
|
-
'Australia/Lindeman',
|
|
2151
|
-
'Australia/Lord_Howe',
|
|
2152
|
-
'Australia/Melbourne',
|
|
2153
|
-
'Australia/Perth',
|
|
2154
|
-
'Australia/Sydney',
|
|
2155
|
-
'Europe/Amsterdam',
|
|
2156
|
-
'Europe/Andorra',
|
|
2157
|
-
'Europe/Astrakhan',
|
|
2158
|
-
'Europe/Athens',
|
|
2159
|
-
'Europe/Belgrade',
|
|
2160
|
-
'Europe/Berlin',
|
|
2161
|
-
'Europe/Bratislava',
|
|
2162
|
-
'Europe/Brussels',
|
|
2163
|
-
'Europe/Bucharest',
|
|
2164
|
-
'Europe/Budapest',
|
|
2165
|
-
'Europe/Busingen',
|
|
2166
|
-
'Europe/Chisinau',
|
|
2167
|
-
'Europe/Copenhagen',
|
|
2168
|
-
'Europe/Dublin',
|
|
2169
|
-
'Europe/Gibraltar',
|
|
2170
|
-
'Europe/Guernsey',
|
|
2171
|
-
'Europe/Helsinki',
|
|
2172
|
-
'Europe/Isle_of_Man',
|
|
2173
|
-
'Europe/Istanbul',
|
|
2174
|
-
'Europe/Jersey',
|
|
2175
|
-
'Europe/Kaliningrad',
|
|
2176
|
-
'Europe/Kirov',
|
|
2177
|
-
'Europe/Kyiv',
|
|
2178
|
-
'Europe/Lisbon',
|
|
2179
|
-
'Europe/Ljubljana',
|
|
2180
|
-
'Europe/London',
|
|
2181
|
-
'Europe/Luxembourg',
|
|
2182
|
-
'Europe/Madrid',
|
|
2183
|
-
'Europe/Malta',
|
|
2184
|
-
'Europe/Mariehamn',
|
|
2185
|
-
'Europe/Minsk',
|
|
2186
|
-
'Europe/Monaco',
|
|
2187
|
-
'Europe/Moscow',
|
|
2188
|
-
'Europe/Oslo',
|
|
2189
|
-
'Europe/Paris',
|
|
2190
|
-
'Europe/Podgorica',
|
|
2191
|
-
'Europe/Prague',
|
|
2192
|
-
'Europe/Riga',
|
|
2193
|
-
'Europe/Rome',
|
|
2194
|
-
'Europe/Samara',
|
|
2195
|
-
'Europe/San_Marino',
|
|
2196
|
-
'Europe/Sarajevo',
|
|
2197
|
-
'Europe/Saratov',
|
|
2198
|
-
'Europe/Simferopol',
|
|
2199
|
-
'Europe/Skopje',
|
|
2200
|
-
'Europe/Sofia',
|
|
2201
|
-
'Europe/Stockholm',
|
|
2202
|
-
'Europe/Tallinn',
|
|
2203
|
-
'Europe/Tirane',
|
|
2204
|
-
'Europe/Ulyanovsk',
|
|
2205
|
-
'Europe/Vaduz',
|
|
2206
|
-
'Europe/Vatican',
|
|
2207
|
-
'Europe/Vienna',
|
|
2208
|
-
'Europe/Vilnius',
|
|
2209
|
-
'Europe/Volgograd',
|
|
2210
|
-
'Europe/Warsaw',
|
|
2211
|
-
'Europe/Zagreb',
|
|
2212
|
-
'Europe/Zurich',
|
|
2213
|
-
'Indian/Antananarivo',
|
|
2214
|
-
'Indian/Chagos',
|
|
2215
|
-
'Indian/Christmas',
|
|
2216
|
-
'Indian/Cocos',
|
|
2217
|
-
'Indian/Comoro',
|
|
2218
|
-
'Indian/Kerguelen',
|
|
2219
|
-
'Indian/Mahe',
|
|
2220
|
-
'Indian/Maldives',
|
|
2221
|
-
'Indian/Mauritius',
|
|
2222
|
-
'Indian/Mayotte',
|
|
2223
|
-
'Indian/Reunion',
|
|
2224
|
-
'Pacific/Apia',
|
|
2225
|
-
'Pacific/Auckland',
|
|
2226
|
-
'Pacific/Bougainville',
|
|
2227
|
-
'Pacific/Chatham',
|
|
2228
|
-
'Pacific/Chuuk',
|
|
2229
|
-
'Pacific/Easter',
|
|
2230
|
-
'Pacific/Efate',
|
|
2231
|
-
'Pacific/Fakaofo',
|
|
2232
|
-
'Pacific/Fiji',
|
|
2233
|
-
'Pacific/Funafuti',
|
|
2234
|
-
'Pacific/Galapagos',
|
|
2235
|
-
'Pacific/Gambier',
|
|
2236
|
-
'Pacific/Guadalcanal',
|
|
2237
|
-
'Pacific/Guam',
|
|
2238
|
-
'Pacific/Honolulu',
|
|
2239
|
-
'Pacific/Kanton',
|
|
2240
|
-
'Pacific/Kiritimati',
|
|
2241
|
-
'Pacific/Kosrae',
|
|
2242
|
-
'Pacific/Kwajalein',
|
|
2243
|
-
'Pacific/Majuro',
|
|
2244
|
-
'Pacific/Marquesas',
|
|
2245
|
-
'Pacific/Midway',
|
|
2246
|
-
'Pacific/Nauru',
|
|
2247
|
-
'Pacific/Niue',
|
|
2248
|
-
'Pacific/Norfolk',
|
|
2249
|
-
'Pacific/Noumea',
|
|
2250
|
-
'Pacific/Pago_Pago',
|
|
2251
|
-
'Pacific/Palau',
|
|
2252
|
-
'Pacific/Pitcairn',
|
|
2253
|
-
'Pacific/Pohnpei',
|
|
2254
|
-
'Pacific/Port_Moresby',
|
|
2255
|
-
'Pacific/Rarotonga',
|
|
2256
|
-
'Pacific/Saipan',
|
|
2257
|
-
'Pacific/Tahiti',
|
|
2258
|
-
'Pacific/Tarawa',
|
|
2259
|
-
'Pacific/Tongatapu',
|
|
2260
|
-
'Pacific/Wake',
|
|
2261
|
-
'Pacific/Wallis',
|
|
2262
|
-
];
|
|
2263
|
-
|
|
2264
1845
|
// Object.values(TIMEZONE_DATA).forEach((item) => {
|
|
2265
1846
|
// console.log(
|
|
2266
1847
|
// item.abbr + ': {\n' +
|
|
@@ -2300,7 +1881,8 @@ const TIMEZONES_LIST = [
|
|
|
2300
1881
|
|
|
2301
1882
|
export function isValidTimeZone(tz: string) {
|
|
2302
1883
|
if (tz && tz.length > 0) {
|
|
2303
|
-
return TIMEZONES_LIST.includes(tz);
|
|
1884
|
+
// return TIMEZONES_LIST.includes(tz);
|
|
1885
|
+
return DateTime.now().setZone(tz).isValid;
|
|
2304
1886
|
}
|
|
2305
1887
|
return false;
|
|
2306
1888
|
}
|
|
@@ -2330,40 +1912,28 @@ export function getTimeZone(country: string, state: string, _city?: string) {
|
|
|
2330
1912
|
* Parse date in timezone
|
|
2331
1913
|
*/
|
|
2332
1914
|
|
|
2333
|
-
export function parseDateInTimezone(
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
/^\d{4}-\d{2}-\d{2}$/.test(input)
|
|
2339
|
-
) {
|
|
2340
|
-
const [year, month, day] = input.split('-').map(Number);
|
|
2341
|
-
d_ = `${month}/${day}/${year}`;
|
|
2342
|
-
}
|
|
2343
|
-
|
|
2344
|
-
const d = typeof d_ === 'string' ? new Date(d_) : d_;
|
|
1915
|
+
export function parseDateInTimezone(
|
|
1916
|
+
input: Date | string,
|
|
1917
|
+
tz?: string | null,
|
|
1918
|
+
addDay?: number, // Use this for start/end of day
|
|
1919
|
+
): Date {
|
|
2345
1920
|
const timeZone = tz || DEFAULT_TIMEZONE;
|
|
2346
1921
|
|
|
2347
|
-
|
|
2348
|
-
const options: Intl.DateTimeFormatOptions = {
|
|
2349
|
-
timeZone,
|
|
2350
|
-
year: 'numeric',
|
|
2351
|
-
month: '2-digit',
|
|
2352
|
-
day: '2-digit',
|
|
2353
|
-
hour: '2-digit',
|
|
2354
|
-
minute: '2-digit',
|
|
2355
|
-
second: '2-digit',
|
|
2356
|
-
hour12: false,
|
|
2357
|
-
};
|
|
1922
|
+
let dt: DateTime;
|
|
2358
1923
|
|
|
2359
|
-
|
|
1924
|
+
// If input is a string in "YYYY-MM-DD" format
|
|
1925
|
+
if (typeof input === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(input)) {
|
|
1926
|
+
dt = DateTime.fromISO(input, { zone: timeZone });
|
|
1927
|
+
} else if (typeof input === 'string') {
|
|
1928
|
+
dt = DateTime.fromJSDate(new Date(input), { zone: timeZone });
|
|
1929
|
+
} else {
|
|
1930
|
+
dt = DateTime.fromJSDate(input, { zone: timeZone });
|
|
1931
|
+
}
|
|
2360
1932
|
|
|
2361
|
-
//
|
|
2362
|
-
|
|
2363
|
-
.
|
|
2364
|
-
|
|
2365
|
-
.map(Number);
|
|
1933
|
+
// Add day offset if needed
|
|
1934
|
+
if (addDay !== 0) {
|
|
1935
|
+
dt = dt.plus({ days: addDay });
|
|
1936
|
+
}
|
|
2366
1937
|
|
|
2367
|
-
|
|
2368
|
-
return new Date(yyyy, mm - 1, dd, hh, min, ss);
|
|
1938
|
+
return dt.toJSDate();
|
|
2369
1939
|
}
|