@jsb188/app 1.1.9 → 1.1.11
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/package.json +54 -45
- package/src/constants/agent.ts +58 -25
- package/src/constants/app.ts +18 -14
- package/src/constants/billing.ts +92 -92
- package/src/constants/emoji.ts +9144 -8936
- package/src/constants/other.ts +1 -5
- package/src/constants/user.ts +16 -25
- package/src/constants/wsActions.ts +35 -0
- package/src/i18n/account.ts +129 -107
- package/src/i18n/agent.ts +63 -43
- package/src/i18n/agentDoc.ts +110 -0
- package/src/i18n/app.ts +101 -91
- package/src/i18n/auth.ts +119 -102
- package/src/i18n/billing.ts +73 -78
- package/src/i18n/campaign.ts +217 -0
- package/src/i18n/country.ts +248 -248
- package/src/i18n/datetime.ts +26 -26
- package/src/i18n/error.ts +428 -182
- package/src/i18n/field_docs.ts +28 -0
- package/src/i18n/form.ts +464 -344
- package/src/i18n/index.ts +25 -18
- package/src/i18n/log.ts +53 -213
- package/src/i18n/memory.ts +39 -0
- package/src/i18n/message.ts +3 -4
- package/src/i18n/note.ts +17 -0
- package/src/i18n/org.ts +115 -109
- package/src/i18n/sheet.ts +376 -4
- package/src/i18n/workflow.ts +70 -23
- package/src/main.ts +66 -62
- package/src/platform.ts +25 -24
- package/src/types/ai.d.ts +33 -23
- package/src/types/app.d.ts +95 -37
- package/src/types/auth.d.ts +66 -40
- package/src/types/console.d.ts +3 -0
- package/src/types/form.d.ts +65 -61
- package/src/types/other.d.ts +6 -6
- package/src/types.d.ts +12 -14
- package/src/utils/account.ts +64 -58
- package/src/utils/api.ts +280 -77
- package/src/utils/authSession.ts +24 -0
- package/src/utils/billing.ts +110 -103
- package/src/utils/color.ts +202 -0
- package/src/utils/cron.ts +49 -18
- package/src/utils/datetime.ts +255 -103
- package/src/utils/emoji.ts +107 -84
- package/src/utils/expression.ts +867 -0
- package/src/utils/interval.ts +80 -0
- package/src/utils/logic.ts +209 -36
- package/src/utils/managedSession.ts +34 -0
- package/src/utils/managedSessionBff.test.ts +60 -0
- package/src/utils/managedSessionBff.ts +117 -0
- package/src/utils/number.ts +60 -32
- package/src/utils/object.ts +198 -30
- package/src/utils/promise.ts +27 -0
- package/src/utils/queryReset.ts +179 -0
- package/src/utils/recurringTask.ts +60 -0
- package/src/utils/schema.ts +293 -0
- package/src/utils/string.test.ts +220 -208
- package/src/utils/string.ts +471 -438
- package/src/utils/timeZone.ts +309 -851
- package/src/utils/url_client.ts +73 -69
- package/tsconfig.json +10 -10
- package/src/i18n/product.ts +0 -76
package/src/utils/datetime.ts
CHANGED
|
@@ -46,7 +46,10 @@ function getStartOfDay(date: Date) {
|
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
48
|
function getDaysDiff(date1: Date, date2: Date) {
|
|
49
|
-
return Math.floor(
|
|
49
|
+
return Math.floor(
|
|
50
|
+
(getStartOfDay(date1).getTime() - getStartOfDay(date2).getTime()) /
|
|
51
|
+
(1000 * 60 * 60 * 24),
|
|
52
|
+
);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
/**
|
|
@@ -62,7 +65,10 @@ function getWeeksDiff(date1: Date, date2: Date) {
|
|
|
62
65
|
*/
|
|
63
66
|
|
|
64
67
|
function getMonthsDiff(date1: Date, date2: Date) {
|
|
65
|
-
return (
|
|
68
|
+
return (
|
|
69
|
+
(date1.getFullYear() - date2.getFullYear()) * 12 +
|
|
70
|
+
(date1.getMonth() - date2.getMonth())
|
|
71
|
+
);
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
/**
|
|
@@ -71,16 +77,48 @@ function getMonthsDiff(date1: Date, date2: Date) {
|
|
|
71
77
|
|
|
72
78
|
export function getUtcWeekOfYear(date: Date) {
|
|
73
79
|
const startOfYear = Date.UTC(date.getUTCFullYear(), 0, 1);
|
|
74
|
-
const currentDay = Date.UTC(
|
|
80
|
+
const currentDay = Date.UTC(
|
|
81
|
+
date.getUTCFullYear(),
|
|
82
|
+
date.getUTCMonth(),
|
|
83
|
+
date.getUTCDate(),
|
|
84
|
+
);
|
|
75
85
|
const dayOfYear = Math.floor((currentDay - startOfYear) / 86400000) + 1;
|
|
76
86
|
return Math.floor((dayOfYear - 1) / 7) + 1;
|
|
77
87
|
}
|
|
78
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Get UTC year-month key (e.g. "2026-07"); zero-padded so keys sort correctly as strings
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
export function getUtcYearMonth(date: Date): string {
|
|
94
|
+
const year = date.getUTCFullYear();
|
|
95
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, '0');
|
|
96
|
+
return `${year}-${month}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Format a future date as a month label, showing the year only when it differs from the reference date.
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
function getFutureMonthLabel(date: Date, referenceDate: Date) {
|
|
104
|
+
return date.toLocaleDateString('en-US', {
|
|
105
|
+
month: 'long',
|
|
106
|
+
year:
|
|
107
|
+
date.getFullYear() === referenceDate.getFullYear()
|
|
108
|
+
? undefined
|
|
109
|
+
: 'numeric',
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
79
113
|
/**
|
|
80
114
|
* Get date period from date
|
|
81
115
|
*/
|
|
82
116
|
|
|
83
117
|
export function getWeeksMonthAgo(d1: Date, d2: Date, weeksThresh = 12): string {
|
|
118
|
+
if (getStartOfDay(d1).getTime() > getStartOfDay(d2).getTime()) {
|
|
119
|
+
return getFutureMonthLabel(d1, d2);
|
|
120
|
+
}
|
|
121
|
+
|
|
84
122
|
const diffWeeks = getWeeksDiff(d2, d1);
|
|
85
123
|
if (diffWeeks === 0) {
|
|
86
124
|
return i18n.t('datetime.period_THIS_WEEK');
|
|
@@ -125,7 +163,9 @@ export function getDatePeriod(d1: Date, d2: Date): DatePeriodEnum {
|
|
|
125
163
|
return 'LAST_WEEK';
|
|
126
164
|
}
|
|
127
165
|
|
|
128
|
-
const diffInMonths =
|
|
166
|
+
const diffInMonths =
|
|
167
|
+
(d2.getFullYear() - d1.getFullYear()) * 12 +
|
|
168
|
+
(d2.getMonth() - d1.getMonth());
|
|
129
169
|
if (diffInMonths === 0) {
|
|
130
170
|
return 'THIS_MONTH';
|
|
131
171
|
} else if (diffInMonths === -1) {
|
|
@@ -223,8 +263,20 @@ export function getFullDateTime(
|
|
|
223
263
|
export function checkIfSameDay(d1: Date, d2: Date, checkTime: boolean = false) {
|
|
224
264
|
let date1, date2;
|
|
225
265
|
if (checkTime) {
|
|
226
|
-
date1 = new Date(
|
|
227
|
-
|
|
266
|
+
date1 = new Date(
|
|
267
|
+
d1.getFullYear(),
|
|
268
|
+
d1.getMonth(),
|
|
269
|
+
d1.getDate(),
|
|
270
|
+
d1.getHours(),
|
|
271
|
+
d1.getMinutes(),
|
|
272
|
+
);
|
|
273
|
+
date2 = new Date(
|
|
274
|
+
d2.getFullYear(),
|
|
275
|
+
d2.getMonth(),
|
|
276
|
+
d2.getDate(),
|
|
277
|
+
d2.getHours(),
|
|
278
|
+
d2.getMinutes(),
|
|
279
|
+
);
|
|
228
280
|
} else {
|
|
229
281
|
date1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate());
|
|
230
282
|
date2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate());
|
|
@@ -233,6 +285,71 @@ export function checkIfSameDay(d1: Date, d2: Date, checkTime: boolean = false) {
|
|
|
233
285
|
return date1.getTime() === date2.getTime();
|
|
234
286
|
}
|
|
235
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Return a sortable calendar-date key in the supplied computer timezone.
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
export function getLocalCalendarDateKey(
|
|
293
|
+
date_: Date | string | number,
|
|
294
|
+
timeZone?: string,
|
|
295
|
+
) {
|
|
296
|
+
const date = date_ instanceof Date ? date_ : new Date(date_);
|
|
297
|
+
if (Number.isNaN(date.getTime())) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const parts = new Intl.DateTimeFormat('en-US', {
|
|
302
|
+
timeZone,
|
|
303
|
+
year: 'numeric',
|
|
304
|
+
month: '2-digit',
|
|
305
|
+
day: '2-digit',
|
|
306
|
+
}).formatToParts(date);
|
|
307
|
+
const year = parts.find((part) => part.type === 'year')?.value;
|
|
308
|
+
const month = parts.find((part) => part.type === 'month')?.value;
|
|
309
|
+
const day = parts.find((part) => part.type === 'day')?.value;
|
|
310
|
+
if (!year || !month || !day) {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return `${year}-${month}-${day}`;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Format date label parts in the supplied computer timezone.
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
export function getLocalDayTimeParts(
|
|
322
|
+
date_: Date | string | number,
|
|
323
|
+
timeZone: string,
|
|
324
|
+
referenceDate: Date = new Date(),
|
|
325
|
+
locales: string = 'en-US',
|
|
326
|
+
) {
|
|
327
|
+
const date = date_ instanceof Date ? date_ : new Date(date_);
|
|
328
|
+
if (Number.isNaN(date.getTime())) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const dayText =
|
|
333
|
+
getLocalCalendarDateKey(date, timeZone) ===
|
|
334
|
+
getLocalCalendarDateKey(referenceDate, timeZone)
|
|
335
|
+
? i18n.t('datetime.period_TODAY')
|
|
336
|
+
: new Intl.DateTimeFormat(locales, {
|
|
337
|
+
timeZone,
|
|
338
|
+
weekday: 'long',
|
|
339
|
+
}).format(date);
|
|
340
|
+
const timeText = new Intl.DateTimeFormat(locales, {
|
|
341
|
+
timeZone,
|
|
342
|
+
hour: 'numeric',
|
|
343
|
+
minute: '2-digit',
|
|
344
|
+
hour12: true,
|
|
345
|
+
}).format(date);
|
|
346
|
+
|
|
347
|
+
return {
|
|
348
|
+
dayText,
|
|
349
|
+
timeText,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
236
353
|
/**
|
|
237
354
|
* Get today at start of day
|
|
238
355
|
*/
|
|
@@ -283,7 +400,11 @@ export function getCalDate(d: Date, timeZone_?: string | null) {
|
|
|
283
400
|
* @returns Date - Enforced calendar date in the specified timezone
|
|
284
401
|
*/
|
|
285
402
|
|
|
286
|
-
export function getReadableCalDate(
|
|
403
|
+
export function getReadableCalDate(
|
|
404
|
+
d_: string | Date,
|
|
405
|
+
timeZone?: string | null,
|
|
406
|
+
locales?: string,
|
|
407
|
+
) {
|
|
287
408
|
let isCalDateString = false;
|
|
288
409
|
let d;
|
|
289
410
|
if (typeof d_ === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(d_)) {
|
|
@@ -319,10 +440,13 @@ export function getReadableCalDate(d_: string | Date, timeZone?: string | null,
|
|
|
319
440
|
}
|
|
320
441
|
|
|
321
442
|
/**
|
|
322
|
-
* Get
|
|
443
|
+
* Get fieldDoc period DateTime value with timezone support.
|
|
323
444
|
*/
|
|
324
445
|
|
|
325
|
-
function
|
|
446
|
+
function getFieldDocPeriodDateTime(
|
|
447
|
+
period: string | Date,
|
|
448
|
+
timeZone: string | null,
|
|
449
|
+
) {
|
|
326
450
|
const zone = timeZone || undefined;
|
|
327
451
|
|
|
328
452
|
if (typeof period === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(period)) {
|
|
@@ -343,10 +467,14 @@ function getReportPeriodDateTime(period: string | Date, timeZone: string | null)
|
|
|
343
467
|
}
|
|
344
468
|
|
|
345
469
|
/**
|
|
346
|
-
* Format
|
|
470
|
+
* Format fieldDoc period range label.
|
|
347
471
|
*/
|
|
348
472
|
|
|
349
|
-
function
|
|
473
|
+
function formatFieldDocPeriodRange(
|
|
474
|
+
start: DateTime,
|
|
475
|
+
end: DateTime,
|
|
476
|
+
separator: string,
|
|
477
|
+
) {
|
|
350
478
|
if (start.year !== end.year) {
|
|
351
479
|
return `${start.toFormat('MMM d, yyyy')}${separator}${end.toFormat('MMM d, yyyy')}`;
|
|
352
480
|
}
|
|
@@ -359,15 +487,15 @@ function formatReportPeriodRange(start: DateTime, end: DateTime, separator: stri
|
|
|
359
487
|
}
|
|
360
488
|
|
|
361
489
|
/**
|
|
362
|
-
* Get formatted
|
|
490
|
+
* Get formatted fieldDoc period label from period start and frequency.
|
|
363
491
|
*/
|
|
364
492
|
|
|
365
|
-
export function
|
|
493
|
+
export function getFieldDocPeriod(
|
|
366
494
|
period: string | Date,
|
|
367
495
|
frequency: any,
|
|
368
496
|
timeZone: string | null,
|
|
369
497
|
) {
|
|
370
|
-
const start =
|
|
498
|
+
const start = getFieldDocPeriodDateTime(period, timeZone);
|
|
371
499
|
if (!start) {
|
|
372
500
|
return null;
|
|
373
501
|
}
|
|
@@ -376,13 +504,25 @@ export function getReportPeriod(
|
|
|
376
504
|
case 'DAILY':
|
|
377
505
|
return start.toFormat('MMM d, yyyy');
|
|
378
506
|
case 'WEEKLY':
|
|
379
|
-
return
|
|
507
|
+
return formatFieldDocPeriodRange(start, start.plus({ days: 6 }), '–');
|
|
380
508
|
case 'MONTHLY':
|
|
381
|
-
return
|
|
509
|
+
return formatFieldDocPeriodRange(
|
|
510
|
+
start,
|
|
511
|
+
start.plus({ months: 1 }).minus({ days: 1 }),
|
|
512
|
+
'-',
|
|
513
|
+
);
|
|
382
514
|
case 'QUARTERLY':
|
|
383
|
-
return
|
|
515
|
+
return formatFieldDocPeriodRange(
|
|
516
|
+
start,
|
|
517
|
+
start.plus({ months: 3 }).minus({ days: 1 }),
|
|
518
|
+
'-',
|
|
519
|
+
);
|
|
384
520
|
case 'ANNUALLY':
|
|
385
|
-
return
|
|
521
|
+
return formatFieldDocPeriodRange(
|
|
522
|
+
start,
|
|
523
|
+
start.plus({ years: 1 }).minus({ days: 1 }),
|
|
524
|
+
'-',
|
|
525
|
+
);
|
|
386
526
|
default:
|
|
387
527
|
return start.toFormat('MMM d, yyyy');
|
|
388
528
|
}
|
|
@@ -394,12 +534,12 @@ export function getReportPeriod(
|
|
|
394
534
|
*/
|
|
395
535
|
|
|
396
536
|
export function getReadableCalDateFromUTC(d: string | Date) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
537
|
+
if (typeof d === 'string') {
|
|
538
|
+
return getReadableCalDate(d);
|
|
539
|
+
}
|
|
400
540
|
|
|
401
|
-
|
|
402
|
-
|
|
541
|
+
const dStr = d.toISOString().split('T')[0]; // Get date part in YYYY-MM-DD format
|
|
542
|
+
return getReadableCalDate(dStr);
|
|
403
543
|
}
|
|
404
544
|
|
|
405
545
|
/**
|
|
@@ -419,7 +559,9 @@ export function updateDate(
|
|
|
419
559
|
): Date | null {
|
|
420
560
|
if (timeZone) {
|
|
421
561
|
// Use luxon to handle timezone-aware date manipulation
|
|
422
|
-
let dt = DateTime.fromJSDate(d_ instanceof Date ? d_ : new Date(d_), {
|
|
562
|
+
let dt = DateTime.fromJSDate(d_ instanceof Date ? d_ : new Date(d_), {
|
|
563
|
+
zone: timeZone,
|
|
564
|
+
});
|
|
423
565
|
|
|
424
566
|
if (update.year !== undefined) {
|
|
425
567
|
dt = dt.set({ year: update.year });
|
|
@@ -509,7 +651,12 @@ export function isValidCalDate(
|
|
|
509
651
|
}
|
|
510
652
|
|
|
511
653
|
const value = Number(calDate);
|
|
512
|
-
if (
|
|
654
|
+
if (
|
|
655
|
+
!calDate ||
|
|
656
|
+
!Number.isInteger(value) ||
|
|
657
|
+
value < 10000000 ||
|
|
658
|
+
value > 90000000
|
|
659
|
+
) {
|
|
513
660
|
return false;
|
|
514
661
|
}
|
|
515
662
|
return !minCalDate || value >= minCalDate;
|
|
@@ -532,17 +679,14 @@ export function isFutureCalDate(
|
|
|
532
679
|
return false;
|
|
533
680
|
}
|
|
534
681
|
const today = getCalDate(new Date(), timeZone);
|
|
535
|
-
return
|
|
682
|
+
return today.calDateInt + addDays < Number(calDateVal);
|
|
536
683
|
}
|
|
537
684
|
|
|
538
685
|
/**
|
|
539
686
|
* Get timezone-aware DateTime object from one date input.
|
|
540
687
|
*/
|
|
541
688
|
|
|
542
|
-
function getDateTimeWithTimeZone(
|
|
543
|
-
date: string | Date,
|
|
544
|
-
timeZone: string | null,
|
|
545
|
-
) {
|
|
689
|
+
function getDateTimeWithTimeZone(date: string | Date, timeZone: string | null) {
|
|
546
690
|
const zone = timeZone && isValidTimeZone(timeZone) ? timeZone : undefined;
|
|
547
691
|
|
|
548
692
|
if (date instanceof Date) {
|
|
@@ -565,13 +709,11 @@ function getDateTimeWithTimeZone(
|
|
|
565
709
|
* @param timeZone - Optional timezone for time formatting
|
|
566
710
|
*/
|
|
567
711
|
|
|
568
|
-
function getTodayYesterdayTime(
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
)
|
|
572
|
-
|
|
573
|
-
? DateTime.now().setZone(timeZone)
|
|
574
|
-
: DateTime.now();
|
|
712
|
+
function getTodayYesterdayTime(dt: DateTime, timeZone: string | null) {
|
|
713
|
+
const now =
|
|
714
|
+
timeZone && isValidTimeZone(timeZone)
|
|
715
|
+
? DateTime.now().setZone(timeZone)
|
|
716
|
+
: DateTime.now();
|
|
575
717
|
const timeText = getFullDateTime(dt.toJSDate(), {
|
|
576
718
|
timeZone,
|
|
577
719
|
hideDate: true,
|
|
@@ -594,18 +736,16 @@ function getTodayYesterdayTime(
|
|
|
594
736
|
* @param timeZone - Optional timezone for day boundary checks
|
|
595
737
|
*/
|
|
596
738
|
|
|
597
|
-
export function getTimeAgo(
|
|
598
|
-
date: string | Date,
|
|
599
|
-
timeZone: string | null,
|
|
600
|
-
) {
|
|
739
|
+
export function getTimeAgo(date: string | Date, timeZone: string | null) {
|
|
601
740
|
const dt = getDateTimeWithTimeZone(date, timeZone);
|
|
602
741
|
if (!dt) {
|
|
603
742
|
return null;
|
|
604
743
|
}
|
|
605
744
|
|
|
606
|
-
const now =
|
|
607
|
-
|
|
608
|
-
|
|
745
|
+
const now =
|
|
746
|
+
timeZone && isValidTimeZone(timeZone)
|
|
747
|
+
? DateTime.now().setZone(timeZone)
|
|
748
|
+
: DateTime.now();
|
|
609
749
|
const todayYesterdayTime = getTodayYesterdayTime(dt, timeZone);
|
|
610
750
|
|
|
611
751
|
if (todayYesterdayTime) {
|
|
@@ -668,9 +808,11 @@ export function getFullDate(
|
|
|
668
808
|
// return "Monday", "Tuesday", etc.
|
|
669
809
|
const dayOfWeekText = d.toLocaleDateString(locales, {
|
|
670
810
|
timeZone: timeZone || undefined, // null is not allowed, it will throw error
|
|
671
|
-
...(outputStyle_ === 'TOMORROW_OR_NUMERIC'
|
|
672
|
-
|
|
673
|
-
|
|
811
|
+
...(outputStyle_ === 'TOMORROW_OR_NUMERIC'
|
|
812
|
+
? {}
|
|
813
|
+
: {
|
|
814
|
+
weekday: 'long',
|
|
815
|
+
}),
|
|
674
816
|
});
|
|
675
817
|
return dayOfWeekText;
|
|
676
818
|
}
|
|
@@ -681,24 +823,25 @@ export function getFullDate(
|
|
|
681
823
|
}
|
|
682
824
|
|
|
683
825
|
switch (outputStyle) {
|
|
684
|
-
|
|
826
|
+
case 'NUMERIC':
|
|
685
827
|
// Expected output: "9/1/2024"
|
|
686
828
|
return new Intl.DateTimeFormat(locales, {
|
|
687
829
|
timeZone: timeZone || undefined, // null is not allowed, it will throw error
|
|
688
830
|
}).format(d);
|
|
689
|
-
case 'NUMERIC_TIME': {
|
|
690
|
-
|
|
831
|
+
case 'NUMERIC_TIME': {
|
|
832
|
+
// Expected output: "9/1/2024, 8:30 PM"
|
|
833
|
+
const numericDate = new Intl.DateTimeFormat(locales, {
|
|
691
834
|
timeZone: timeZone || undefined, // null is not allowed, it will throw error
|
|
692
835
|
}).format(d);
|
|
693
836
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
837
|
+
const numericTime = new Intl.DateTimeFormat(locales, {
|
|
838
|
+
timeZone: timeZone || undefined, // null is not allowed, it will throw error
|
|
839
|
+
hour: 'numeric',
|
|
840
|
+
minute: '2-digit',
|
|
841
|
+
hour12: true,
|
|
842
|
+
}).format(d);
|
|
700
843
|
|
|
701
|
-
|
|
844
|
+
return `${numericDate}, ${numericTime}`;
|
|
702
845
|
|
|
703
846
|
// return new Intl.DateTimeFormat(locales, {
|
|
704
847
|
// month: '2-digit',
|
|
@@ -709,7 +852,7 @@ export function getFullDate(
|
|
|
709
852
|
// hour12: true,
|
|
710
853
|
// timeZone: timeZone || undefined, // null is not allowed, it will throw error
|
|
711
854
|
// }).format(d);
|
|
712
|
-
|
|
855
|
+
}
|
|
713
856
|
case 'MINIMAL':
|
|
714
857
|
// Expected output: "Sep 1, 2024, 6:54 PM"
|
|
715
858
|
return new Intl.DateTimeFormat(locales, {
|
|
@@ -717,7 +860,7 @@ export function getFullDate(
|
|
|
717
860
|
timeStyle: 'short', // 'full', 'long', 'medium', 'short'
|
|
718
861
|
timeZone: timeZone || undefined, // null is not allowed, it will throw error
|
|
719
862
|
}).format(d);
|
|
720
|
-
|
|
863
|
+
// return DateTime.fromJSDate(d, timeZone ? { zone: timeZone } : undefined).toFormat('MMM d yyyy, h:mm a');
|
|
721
864
|
case 'DATE_ONLY_SHORT': {
|
|
722
865
|
// Expected output: "Sep 1" (or "Sep 1, 25" if not current year)
|
|
723
866
|
const dateYear = d.getFullYear();
|
|
@@ -747,7 +890,9 @@ export function getFullDate(
|
|
|
747
890
|
month: 'short',
|
|
748
891
|
day: 'numeric',
|
|
749
892
|
timeZone: timeZone || undefined, // null is not allowed, it will throw error
|
|
750
|
-
})
|
|
893
|
+
})
|
|
894
|
+
.format(d)
|
|
895
|
+
.replace(', ', ", '");
|
|
751
896
|
}
|
|
752
897
|
case 'DATE_TEXT':
|
|
753
898
|
// Expected output: "September 1, 2024"
|
|
@@ -771,7 +916,9 @@ export function getFullDate(
|
|
|
771
916
|
timeStyle: 'long',
|
|
772
917
|
}).formatToParts(d);
|
|
773
918
|
|
|
774
|
-
const timezoneName = parts.find(
|
|
919
|
+
const timezoneName = parts.find(
|
|
920
|
+
(part) => part.type === 'timeZoneName',
|
|
921
|
+
)?.value;
|
|
775
922
|
if (timezoneName) {
|
|
776
923
|
// Doing this will make sure {date} does not include [seconds] in the time format
|
|
777
924
|
return date + ' ' + timezoneName;
|
|
@@ -801,9 +948,16 @@ export function getDayPeriod(): 'MORNING' | 'AFTERNOON' | 'EVENING' | 'NIGHT' {
|
|
|
801
948
|
* Convert YYYY-MM-DD to Date
|
|
802
949
|
*/
|
|
803
950
|
|
|
804
|
-
export function getDateFromCalDate(
|
|
805
|
-
|
|
806
|
-
|
|
951
|
+
export function getDateFromCalDate(
|
|
952
|
+
value: string | number,
|
|
953
|
+
timeZone?: string | null,
|
|
954
|
+
): Date {
|
|
955
|
+
const calDate =
|
|
956
|
+
typeof value === 'number' ? convertIntToCalDate(value) : value;
|
|
957
|
+
const dt = DateTime.fromISO(
|
|
958
|
+
calDate,
|
|
959
|
+
timeZone ? { zone: timeZone } : undefined,
|
|
960
|
+
);
|
|
807
961
|
const jsDate = dt.toJSDate();
|
|
808
962
|
// const [year, month, day] = calDate.split('-');
|
|
809
963
|
// console.log(new Date(Number(year), Number(month) - 1, Number(day)));
|
|
@@ -853,7 +1007,9 @@ export function groupByDatePeriod<T>(
|
|
|
853
1007
|
const lastItem = group[group.length - 1];
|
|
854
1008
|
const lastDatePeriod: any = lastItem?.datePeriod;
|
|
855
1009
|
const date = new Date(getObject(item, dateKey));
|
|
856
|
-
const datePeriod = groupByDate
|
|
1010
|
+
const datePeriod = groupByDate
|
|
1011
|
+
? getCalDate(date, timeZone).calDate
|
|
1012
|
+
: getDatePeriod(date, d);
|
|
857
1013
|
|
|
858
1014
|
const dateObj = {
|
|
859
1015
|
datePeriod,
|
|
@@ -913,7 +1069,9 @@ export function labelSortByDatePeriod<T>(
|
|
|
913
1069
|
const lastItem = output[output.length - 1];
|
|
914
1070
|
const lastDatePeriod: any = lastItem?.datePeriod;
|
|
915
1071
|
const date = new Date(item[dateKey]);
|
|
916
|
-
const datePeriod = groupByDate
|
|
1072
|
+
const datePeriod = groupByDate
|
|
1073
|
+
? getCalDate(date, timeZone).calDate
|
|
1074
|
+
: getDatePeriod(date, d);
|
|
917
1075
|
|
|
918
1076
|
const dateObj = {
|
|
919
1077
|
datePeriod,
|
|
@@ -921,10 +1079,7 @@ export function labelSortByDatePeriod<T>(
|
|
|
921
1079
|
item: mapFn ? mapFn(item) : item,
|
|
922
1080
|
};
|
|
923
1081
|
|
|
924
|
-
if (
|
|
925
|
-
(!output.length) ||
|
|
926
|
-
(lastDatePeriod && lastDatePeriod !== datePeriod)
|
|
927
|
-
) {
|
|
1082
|
+
if (!output.length || (lastDatePeriod && lastDatePeriod !== datePeriod)) {
|
|
928
1083
|
output.push({
|
|
929
1084
|
datePeriod,
|
|
930
1085
|
date,
|
|
@@ -1028,39 +1183,36 @@ export function timeToHHMM(timeStr: string): string {
|
|
|
1028
1183
|
*/
|
|
1029
1184
|
|
|
1030
1185
|
export function groupByDateMonth<T extends { date: Date }>(
|
|
1031
|
-
|
|
1032
|
-
|
|
1186
|
+
items: T[],
|
|
1187
|
+
timeZone: string,
|
|
1033
1188
|
): {
|
|
1034
|
-
|
|
1035
|
-
|
|
1189
|
+
byDate: Record<string, T[]>;
|
|
1190
|
+
byMonth: Record<string, T[]>;
|
|
1036
1191
|
} {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
return { byDate, byMonth };
|
|
1192
|
+
// 1. Sort by absolute time
|
|
1193
|
+
const sorted = [...items].sort((a, b) => a.date.getTime() - b.date.getTime());
|
|
1194
|
+
|
|
1195
|
+
const byDate: Record<string, T[]> = {};
|
|
1196
|
+
const byMonth: Record<string, T[]> = {};
|
|
1197
|
+
|
|
1198
|
+
for (const item of sorted) {
|
|
1199
|
+
const dt = DateTime.fromJSDate(item.date, { zone: timeZone });
|
|
1200
|
+
|
|
1201
|
+
const dateKey = dt.toFormat('yyyy-MM-dd');
|
|
1202
|
+
const monthKey = dt.toFormat('yyyy-MM');
|
|
1203
|
+
|
|
1204
|
+
// Group by day
|
|
1205
|
+
if (!byDate[dateKey]) {
|
|
1206
|
+
byDate[dateKey] = [];
|
|
1207
|
+
}
|
|
1208
|
+
byDate[dateKey].push(item);
|
|
1209
|
+
|
|
1210
|
+
// Group by month
|
|
1211
|
+
if (!byMonth[monthKey]) {
|
|
1212
|
+
byMonth[monthKey] = [];
|
|
1213
|
+
}
|
|
1214
|
+
byMonth[monthKey].push(item);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
return { byDate, byMonth };
|
|
1066
1218
|
}
|