@jsb188/app 1.1.10 → 1.1.12

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.
Files changed (79) hide show
  1. package/package.json +57 -45
  2. package/src/constants/agent.ts +51 -41
  3. package/src/constants/app.ts +34 -13
  4. package/src/constants/emoji.ts +9144 -8936
  5. package/src/constants/other.ts +1 -5
  6. package/src/constants/user.ts +16 -25
  7. package/src/constants/wsActions.ts +27 -0
  8. package/src/i18n/account.ts +129 -107
  9. package/src/i18n/agent.ts +331 -73
  10. package/src/i18n/agentToolBusiness.ts +196 -0
  11. package/src/i18n/agentToolGrid.ts +137 -0
  12. package/src/i18n/agentToolWorkflow.ts +101 -0
  13. package/src/i18n/agent_note.ts +109 -0
  14. package/src/i18n/app.ts +107 -91
  15. package/src/i18n/auth.ts +117 -102
  16. package/src/i18n/billing.ts +5 -92
  17. package/src/i18n/c.ts +907 -0
  18. package/src/i18n/campaign.ts +919 -0
  19. package/src/i18n/country.ts +248 -248
  20. package/src/i18n/datetime.ts +32 -26
  21. package/src/i18n/editor.ts +58 -0
  22. package/src/i18n/error.ts +577 -192
  23. package/src/i18n/field_doc_editor.ts +21 -0
  24. package/src/i18n/field_doc_programs.ts +52 -0
  25. package/src/i18n/field_docs.ts +190 -0
  26. package/src/i18n/index.ts +42 -19
  27. package/src/i18n/log.ts +272 -238
  28. package/src/i18n/memory.ts +53 -0
  29. package/src/i18n/message.ts +3 -4
  30. package/src/i18n/note.ts +19 -0
  31. package/src/i18n/org.ts +164 -109
  32. package/src/i18n/schedule.ts +209 -0
  33. package/src/i18n/sheet.ts +333 -4
  34. package/src/i18n/sheet_formula.ts +165 -0
  35. package/src/i18n/workflow.ts +109 -23
  36. package/src/main.ts +68 -64
  37. package/src/platform.ts +90 -49
  38. package/src/types/ai.d.ts +52 -23
  39. package/src/types/app.d.ts +95 -44
  40. package/src/types/auth.d.ts +66 -40
  41. package/src/types/console.d.ts +3 -0
  42. package/src/types/other.d.ts +13 -6
  43. package/src/types.d.ts +12 -14
  44. package/src/utils/account.ts +64 -58
  45. package/src/utils/api.ts +326 -77
  46. package/src/utils/authSession.ts +24 -0
  47. package/src/utils/clientIP.ts +213 -0
  48. package/src/utils/color.ts +279 -0
  49. package/src/utils/cron.ts +49 -18
  50. package/src/utils/csv.ts +19 -0
  51. package/src/utils/datetime.ts +445 -117
  52. package/src/utils/deferredSave.ts +89 -0
  53. package/src/utils/email.ts +50 -0
  54. package/src/utils/emoji.ts +107 -84
  55. package/src/utils/expression.helpers.ts +470 -0
  56. package/src/utils/expression.test.ts +793 -0
  57. package/src/utils/expression.ts +2261 -0
  58. package/src/utils/interval.ts +80 -0
  59. package/src/utils/language.ts +9 -0
  60. package/src/utils/logic.ts +141 -121
  61. package/src/utils/managedSession.ts +34 -0
  62. package/src/utils/managedSessionBff.test.ts +60 -0
  63. package/src/utils/managedSessionBff.ts +117 -0
  64. package/src/utils/number.ts +85 -38
  65. package/src/utils/object.ts +227 -30
  66. package/src/utils/promise.ts +98 -0
  67. package/src/utils/queryReset.ts +266 -0
  68. package/src/utils/recurringTask.ts +60 -0
  69. package/src/utils/schema.ts +293 -0
  70. package/src/utils/string.test.ts +205 -208
  71. package/src/utils/string.ts +426 -463
  72. package/src/utils/timeZone.ts +309 -851
  73. package/src/utils/url_client.ts +145 -72
  74. package/tsconfig.json +10 -10
  75. package/src/constants/billing.ts +0 -146
  76. package/src/i18n/form.ts +0 -376
  77. package/src/i18n/product.ts +0 -76
  78. package/src/types/form.d.ts +0 -97
  79. package/src/utils/billing.ts +0 -134
@@ -1,7 +1,11 @@
1
1
  import { DateTime } from 'luxon';
2
2
  import i18n from '../i18n/index.ts';
3
3
  import { getObject } from './object.ts';
4
- import { isValidTimeZone, parseDateInTimezone } from './timeZone.ts';
4
+ import {
5
+ DEFAULT_TIMEZONE,
6
+ isValidTimeZone,
7
+ parseDateInTimezone,
8
+ } from './timeZone.ts';
5
9
 
6
10
  /**
7
11
  * Types
@@ -46,7 +50,10 @@ function getStartOfDay(date: Date) {
46
50
  */
47
51
 
48
52
  function getDaysDiff(date1: Date, date2: Date) {
49
- return Math.floor((getStartOfDay(date1).getTime() - getStartOfDay(date2).getTime()) / (1000 * 60 * 60 * 24));
53
+ return Math.floor(
54
+ (getStartOfDay(date1).getTime() - getStartOfDay(date2).getTime()) /
55
+ (1000 * 60 * 60 * 24),
56
+ );
50
57
  }
51
58
 
52
59
  /**
@@ -62,7 +69,10 @@ function getWeeksDiff(date1: Date, date2: Date) {
62
69
  */
63
70
 
64
71
  function getMonthsDiff(date1: Date, date2: Date) {
65
- return (date1.getFullYear() - date2.getFullYear()) * 12 + (date1.getMonth() - date2.getMonth());
72
+ return (
73
+ (date1.getFullYear() - date2.getFullYear()) * 12 +
74
+ (date1.getMonth() - date2.getMonth())
75
+ );
66
76
  }
67
77
 
68
78
  /**
@@ -71,16 +81,48 @@ function getMonthsDiff(date1: Date, date2: Date) {
71
81
 
72
82
  export function getUtcWeekOfYear(date: Date) {
73
83
  const startOfYear = Date.UTC(date.getUTCFullYear(), 0, 1);
74
- const currentDay = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
84
+ const currentDay = Date.UTC(
85
+ date.getUTCFullYear(),
86
+ date.getUTCMonth(),
87
+ date.getUTCDate(),
88
+ );
75
89
  const dayOfYear = Math.floor((currentDay - startOfYear) / 86400000) + 1;
76
90
  return Math.floor((dayOfYear - 1) / 7) + 1;
77
91
  }
78
92
 
93
+ /**
94
+ * Get UTC year-month key (e.g. "2026-07"); zero-padded so keys sort correctly as strings
95
+ */
96
+
97
+ export function getUtcYearMonth(date: Date): string {
98
+ const year = date.getUTCFullYear();
99
+ const month = String(date.getUTCMonth() + 1).padStart(2, '0');
100
+ return `${year}-${month}`;
101
+ }
102
+
103
+ /**
104
+ * Format a future date as a month label, showing the year only when it differs from the reference date.
105
+ */
106
+
107
+ function getFutureMonthLabel(date: Date, referenceDate: Date) {
108
+ return date.toLocaleDateString('en-US', {
109
+ month: 'long',
110
+ year:
111
+ date.getFullYear() === referenceDate.getFullYear()
112
+ ? undefined
113
+ : 'numeric',
114
+ });
115
+ }
116
+
79
117
  /**
80
118
  * Get date period from date
81
119
  */
82
120
 
83
121
  export function getWeeksMonthAgo(d1: Date, d2: Date, weeksThresh = 12): string {
122
+ if (getStartOfDay(d1).getTime() > getStartOfDay(d2).getTime()) {
123
+ return getFutureMonthLabel(d1, d2);
124
+ }
125
+
84
126
  const diffWeeks = getWeeksDiff(d2, d1);
85
127
  if (diffWeeks === 0) {
86
128
  return i18n.t('datetime.period_THIS_WEEK');
@@ -125,7 +167,9 @@ export function getDatePeriod(d1: Date, d2: Date): DatePeriodEnum {
125
167
  return 'LAST_WEEK';
126
168
  }
127
169
 
128
- const diffInMonths = (d2.getFullYear() - d1.getFullYear()) * 12 + (d2.getMonth() - d1.getMonth());
170
+ const diffInMonths =
171
+ (d2.getFullYear() - d1.getFullYear()) * 12 +
172
+ (d2.getMonth() - d1.getMonth());
129
173
  if (diffInMonths === 0) {
130
174
  return 'THIS_MONTH';
131
175
  } else if (diffInMonths === -1) {
@@ -135,6 +179,27 @@ export function getDatePeriod(d1: Date, d2: Date): DatePeriodEnum {
135
179
  return 'OLDER';
136
180
  }
137
181
 
182
+ /*
183
+ * Format compact display dates consistently, showing the year only outside the current year.
184
+ * Calendar dates use UTC so timezone conversion cannot change their day.
185
+ */
186
+
187
+ export function formatDisplayDate(value: string | Date, timeZone?: string | null): string {
188
+ const dateOnly = typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value);
189
+ const date = value instanceof Date ? value : new Date(value);
190
+ const zone = dateOnly ? 'UTC' : timeZone || undefined;
191
+ const yearFormat = new Intl.DateTimeFormat('en-US', { timeZone: zone, year: 'numeric' });
192
+ return new Intl.DateTimeFormat('en-US', {
193
+ timeZone: zone,
194
+ month: 'numeric',
195
+ day: '2-digit',
196
+ year: yearFormat.format(date) === yearFormat.format(new Date()) ? undefined : 'numeric',
197
+ hour: dateOnly ? undefined : 'numeric',
198
+ minute: dateOnly ? undefined : '2-digit',
199
+ hour12: true,
200
+ }).format(date);
201
+ }
202
+
138
203
  /**
139
204
  * Get full date with time
140
205
  */
@@ -216,6 +281,60 @@ export function getFullDateTime(
216
281
  });
217
282
  }
218
283
 
284
+ /*
285
+ * Convert one canonical instant into the local value required by a
286
+ * datetime-local input in the requested scheduling timezone.
287
+ */
288
+ export function getDateTimeLocalInputValue(
289
+ value?: Date | string | number | null,
290
+ timeZone?: string | null,
291
+ ): string | null {
292
+ const date = value ? new Date(value) : null;
293
+ if (!date || !Number.isFinite(date.getTime())) {
294
+ return null;
295
+ }
296
+
297
+ const inputTimeZone =
298
+ timeZone && isValidTimeZone(timeZone) ? timeZone : DEFAULT_TIMEZONE;
299
+ const { calDate, time } = getCalDate(date, inputTimeZone);
300
+ return `${calDate}T${time.slice(0, 5)}`;
301
+ }
302
+
303
+ /*
304
+ * Convert a datetime-local input value into its canonical ISO instant in the
305
+ * requested scheduling timezone.
306
+ */
307
+ export function normalizeDateTimeLocalInputValue(
308
+ value?: string | null,
309
+ timeZone?: string | null,
310
+ ): string | null {
311
+ const trimmedValue = String(value || '').trim();
312
+ if (
313
+ !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?$/.test(
314
+ trimmedValue,
315
+ )
316
+ ) {
317
+ return null;
318
+ }
319
+
320
+ const inputTimeZone =
321
+ timeZone && isValidTimeZone(timeZone) ? timeZone : DEFAULT_TIMEZONE;
322
+ const parsedDate = parseDateInTimezone(trimmedValue, inputTimeZone, 0, true);
323
+ if (!Number.isFinite(parsedDate.getTime())) {
324
+ return null;
325
+ }
326
+
327
+ // Luxon advances nonexistent wall-clock times through daylight-saving gaps.
328
+ // A scheduler must reject that silent time change rather than save a
329
+ // different local time from the one the user entered.
330
+ const { calDate, time } = getCalDate(parsedDate, inputTimeZone);
331
+ if (`${calDate}T${time.slice(0, 5)}` !== trimmedValue.slice(0, 16)) {
332
+ return null;
333
+ }
334
+
335
+ return parsedDate.toISOString();
336
+ }
337
+
219
338
  /**
220
339
  * Check if date is same day
221
340
  */
@@ -223,8 +342,20 @@ export function getFullDateTime(
223
342
  export function checkIfSameDay(d1: Date, d2: Date, checkTime: boolean = false) {
224
343
  let date1, date2;
225
344
  if (checkTime) {
226
- date1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate(), d1.getHours(), d1.getMinutes());
227
- date2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate(), d2.getHours(), d2.getMinutes());
345
+ date1 = new Date(
346
+ d1.getFullYear(),
347
+ d1.getMonth(),
348
+ d1.getDate(),
349
+ d1.getHours(),
350
+ d1.getMinutes(),
351
+ );
352
+ date2 = new Date(
353
+ d2.getFullYear(),
354
+ d2.getMonth(),
355
+ d2.getDate(),
356
+ d2.getHours(),
357
+ d2.getMinutes(),
358
+ );
228
359
  } else {
229
360
  date1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate());
230
361
  date2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate());
@@ -233,6 +364,71 @@ export function checkIfSameDay(d1: Date, d2: Date, checkTime: boolean = false) {
233
364
  return date1.getTime() === date2.getTime();
234
365
  }
235
366
 
367
+ /**
368
+ * Return a sortable calendar-date key in the supplied computer timezone.
369
+ */
370
+
371
+ export function getLocalCalendarDateKey(
372
+ date_: Date | string | number,
373
+ timeZone?: string,
374
+ ) {
375
+ const date = date_ instanceof Date ? date_ : new Date(date_);
376
+ if (Number.isNaN(date.getTime())) {
377
+ return null;
378
+ }
379
+
380
+ const parts = new Intl.DateTimeFormat('en-US', {
381
+ timeZone,
382
+ year: 'numeric',
383
+ month: '2-digit',
384
+ day: '2-digit',
385
+ }).formatToParts(date);
386
+ const year = parts.find((part) => part.type === 'year')?.value;
387
+ const month = parts.find((part) => part.type === 'month')?.value;
388
+ const day = parts.find((part) => part.type === 'day')?.value;
389
+ if (!year || !month || !day) {
390
+ return null;
391
+ }
392
+
393
+ return `${year}-${month}-${day}`;
394
+ }
395
+
396
+ /**
397
+ * Format date label parts in the supplied computer timezone.
398
+ */
399
+
400
+ export function getLocalDayTimeParts(
401
+ date_: Date | string | number,
402
+ timeZone: string,
403
+ referenceDate: Date = new Date(),
404
+ locales: string = 'en-US',
405
+ ) {
406
+ const date = date_ instanceof Date ? date_ : new Date(date_);
407
+ if (Number.isNaN(date.getTime())) {
408
+ return null;
409
+ }
410
+
411
+ const dayText =
412
+ getLocalCalendarDateKey(date, timeZone) ===
413
+ getLocalCalendarDateKey(referenceDate, timeZone)
414
+ ? i18n.t('datetime.period_TODAY')
415
+ : new Intl.DateTimeFormat(locales, {
416
+ timeZone,
417
+ weekday: 'long',
418
+ }).format(date);
419
+ const timeText = new Intl.DateTimeFormat(locales, {
420
+ timeZone,
421
+ hour: 'numeric',
422
+ minute: '2-digit',
423
+ hour12: true,
424
+ }).format(date);
425
+
426
+ return {
427
+ dayText,
428
+ timeText,
429
+ };
430
+ }
431
+
236
432
  /**
237
433
  * Get today at start of day
238
434
  */
@@ -283,7 +479,11 @@ export function getCalDate(d: Date, timeZone_?: string | null) {
283
479
  * @returns Date - Enforced calendar date in the specified timezone
284
480
  */
285
481
 
286
- export function getReadableCalDate(d_: string | Date, timeZone?: string | null, locales?: string) {
482
+ export function getReadableCalDate(
483
+ d_: string | Date,
484
+ timeZone?: string | null,
485
+ locales?: string,
486
+ ) {
287
487
  let isCalDateString = false;
288
488
  let d;
289
489
  if (typeof d_ === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(d_)) {
@@ -319,10 +519,13 @@ export function getReadableCalDate(d_: string | Date, timeZone?: string | null,
319
519
  }
320
520
 
321
521
  /**
322
- * Get report period DateTime value with timezone support.
522
+ * Get fieldDoc period DateTime value with timezone support.
323
523
  */
324
524
 
325
- function getReportPeriodDateTime(period: string | Date, timeZone: string | null) {
525
+ function getFieldDocPeriodDateTime(
526
+ period: string | Date,
527
+ timeZone: string | null,
528
+ ) {
326
529
  const zone = timeZone || undefined;
327
530
 
328
531
  if (typeof period === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(period)) {
@@ -343,10 +546,14 @@ function getReportPeriodDateTime(period: string | Date, timeZone: string | null)
343
546
  }
344
547
 
345
548
  /**
346
- * Format report period range label.
549
+ * Format fieldDoc period range label.
347
550
  */
348
551
 
349
- function formatReportPeriodRange(start: DateTime, end: DateTime, separator: string) {
552
+ function formatFieldDocPeriodRange(
553
+ start: DateTime,
554
+ end: DateTime,
555
+ separator: string,
556
+ ) {
350
557
  if (start.year !== end.year) {
351
558
  return `${start.toFormat('MMM d, yyyy')}${separator}${end.toFormat('MMM d, yyyy')}`;
352
559
  }
@@ -359,15 +566,15 @@ function formatReportPeriodRange(start: DateTime, end: DateTime, separator: stri
359
566
  }
360
567
 
361
568
  /**
362
- * Get formatted report period label from period start and frequency.
569
+ * Get formatted fieldDoc period label from period start and frequency.
363
570
  */
364
571
 
365
- export function getReportPeriod(
572
+ export function getFieldDocPeriod(
366
573
  period: string | Date,
367
574
  frequency: any,
368
575
  timeZone: string | null,
369
576
  ) {
370
- const start = getReportPeriodDateTime(period, timeZone);
577
+ const start = getFieldDocPeriodDateTime(period, timeZone);
371
578
  if (!start) {
372
579
  return null;
373
580
  }
@@ -376,13 +583,25 @@ export function getReportPeriod(
376
583
  case 'DAILY':
377
584
  return start.toFormat('MMM d, yyyy');
378
585
  case 'WEEKLY':
379
- return formatReportPeriodRange(start, start.plus({ days: 6 }), '–');
586
+ return formatFieldDocPeriodRange(start, start.plus({ days: 6 }), '–');
380
587
  case 'MONTHLY':
381
- return formatReportPeriodRange(start, start.plus({ months: 1 }).minus({ days: 1 }), '-');
588
+ return formatFieldDocPeriodRange(
589
+ start,
590
+ start.plus({ months: 1 }).minus({ days: 1 }),
591
+ '-',
592
+ );
382
593
  case 'QUARTERLY':
383
- return formatReportPeriodRange(start, start.plus({ months: 3 }).minus({ days: 1 }), '-');
594
+ return formatFieldDocPeriodRange(
595
+ start,
596
+ start.plus({ months: 3 }).minus({ days: 1 }),
597
+ '-',
598
+ );
384
599
  case 'ANNUALLY':
385
- return formatReportPeriodRange(start, start.plus({ years: 1 }).minus({ days: 1 }), '-');
600
+ return formatFieldDocPeriodRange(
601
+ start,
602
+ start.plus({ years: 1 }).minus({ days: 1 }),
603
+ '-',
604
+ );
386
605
  default:
387
606
  return start.toFormat('MMM d, yyyy');
388
607
  }
@@ -394,12 +613,12 @@ export function getReportPeriod(
394
613
  */
395
614
 
396
615
  export function getReadableCalDateFromUTC(d: string | Date) {
397
- if (typeof d === 'string') {
398
- return getReadableCalDate(d);
399
- }
616
+ if (typeof d === 'string') {
617
+ return getReadableCalDate(d);
618
+ }
400
619
 
401
- const dStr = d.toISOString().split('T')[0]; // Get date part in YYYY-MM-DD format
402
- return getReadableCalDate(dStr);
620
+ const dStr = d.toISOString().split('T')[0]; // Get date part in YYYY-MM-DD format
621
+ return getReadableCalDate(dStr);
403
622
  }
404
623
 
405
624
  /**
@@ -419,7 +638,9 @@ export function updateDate(
419
638
  ): Date | null {
420
639
  if (timeZone) {
421
640
  // Use luxon to handle timezone-aware date manipulation
422
- let dt = DateTime.fromJSDate(d_ instanceof Date ? d_ : new Date(d_), { zone: timeZone });
641
+ let dt = DateTime.fromJSDate(d_ instanceof Date ? d_ : new Date(d_), {
642
+ zone: timeZone,
643
+ });
423
644
 
424
645
  if (update.year !== undefined) {
425
646
  dt = dt.set({ year: update.year });
@@ -509,7 +730,12 @@ export function isValidCalDate(
509
730
  }
510
731
 
511
732
  const value = Number(calDate);
512
- if (!calDate || !Number.isInteger(value) || value < 10000000 || value > 90000000) {
733
+ if (
734
+ !calDate ||
735
+ !Number.isInteger(value) ||
736
+ value < 10000000 ||
737
+ value > 90000000
738
+ ) {
513
739
  return false;
514
740
  }
515
741
  return !minCalDate || value >= minCalDate;
@@ -532,17 +758,14 @@ export function isFutureCalDate(
532
758
  return false;
533
759
  }
534
760
  const today = getCalDate(new Date(), timeZone);
535
- return (today.calDateInt + addDays) < Number(calDateVal);
761
+ return today.calDateInt + addDays < Number(calDateVal);
536
762
  }
537
763
 
538
764
  /**
539
765
  * Get timezone-aware DateTime object from one date input.
540
766
  */
541
767
 
542
- function getDateTimeWithTimeZone(
543
- date: string | Date,
544
- timeZone: string | null,
545
- ) {
768
+ function getDateTimeWithTimeZone(date: string | Date, timeZone: string | null) {
546
769
  const zone = timeZone && isValidTimeZone(timeZone) ? timeZone : undefined;
547
770
 
548
771
  if (date instanceof Date) {
@@ -560,73 +783,161 @@ function getDateTimeWithTimeZone(
560
783
  }
561
784
 
562
785
  /**
563
- * Convert today/yesterday date time into a label with time
786
+ * Convert today/yesterday date time into a label, with the time unless hidden
564
787
  * @param dt - Parsed Luxon date time
565
788
  * @param timeZone - Optional timezone for time formatting
789
+ * @param hideTime - Return only the day label
566
790
  */
567
791
 
568
792
  function getTodayYesterdayTime(
569
793
  dt: DateTime,
794
+ now: DateTime,
570
795
  timeZone: string | null,
796
+ hideTime?: boolean,
571
797
  ) {
572
- const now = timeZone && isValidTimeZone(timeZone)
573
- ? DateTime.now().setZone(timeZone)
574
- : DateTime.now();
798
+ const dayKey = dt.hasSame(now, 'day')
799
+ ? 'datetime.period_TODAY'
800
+ : dt.hasSame(now.minus({ days: 1 }), 'day')
801
+ ? 'datetime.period_YESTERDAY'
802
+ : null;
803
+
804
+ if (!dayKey) {
805
+ return null;
806
+ }
807
+
808
+ if (hideTime) {
809
+ return i18n.t(dayKey);
810
+ }
811
+
575
812
  const timeText = getFullDateTime(dt.toJSDate(), {
576
813
  timeZone,
577
814
  hideDate: true,
578
815
  });
816
+ return `${i18n.t(dayKey)}, ${timeText}`;
817
+ }
818
+
819
+ /**
820
+ * Format a date time with a numeric month and day, adding a two-digit year only when it differs from the reference year.
821
+ * @param dt - Parsed Luxon date time
822
+ * @param now - Reference date time used to decide whether to show the year
823
+ * @param timeZone - Optional timezone for date and time formatting
824
+ * @param hideTime - Omit the hour and minute
825
+ */
826
+
827
+ function getCompactDateTime(
828
+ dt: DateTime,
829
+ now: DateTime,
830
+ timeZone: string | null,
831
+ hideTime?: boolean,
832
+ ) {
833
+ return new Intl.DateTimeFormat('en-US', {
834
+ day: 'numeric',
835
+ month: 'numeric',
836
+ timeZone: timeZone && isValidTimeZone(timeZone) ? timeZone : undefined,
837
+ year: dt.year === now.year ? undefined : '2-digit',
838
+ ...(hideTime ? {} : { hour: 'numeric', hour12: true, minute: '2-digit' }),
839
+ }).format(dt.toJSDate());
840
+ }
841
+
842
+ /**
843
+ * Format an edited timestamp as a compact or expanded relative label, falling back to YYYY/MM/DD.
844
+ * @param date - Date to format
845
+ * @param timeZone - Optional timezone for calendar-day comparisons
846
+ * @param longer - Return expanded relative units when true
847
+ */
848
+
849
+ export function getEditedTimeAgo(
850
+ date: string | Date,
851
+ timeZone?: string | null,
852
+ longer?: boolean,
853
+ ) {
854
+ const dt = getDateTimeWithTimeZone(date, timeZone || null);
855
+ if (!dt) {
856
+ return null;
857
+ }
858
+
859
+ const now =
860
+ timeZone && isValidTimeZone(timeZone)
861
+ ? DateTime.now().setZone(timeZone)
862
+ : DateTime.now();
863
+ const diffMinutes = now.diff(dt, 'minutes').minutes;
864
+
865
+ if (diffMinutes < 0) {
866
+ return dt.toFormat('yyyy/MM/dd');
867
+ }
868
+
869
+ if (diffMinutes <= 4) {
870
+ return i18n.t('datetime.just_now');
871
+ }
872
+
873
+ if (diffMinutes < 60) {
874
+ return i18n.t(
875
+ longer ? 'datetime.minutes_ago_ct' : 'datetime.minutes_ago_short_ct',
876
+ {
877
+ smart_count: Math.floor(diffMinutes),
878
+ },
879
+ );
880
+ }
881
+
882
+ const diffHours = diffMinutes / 60;
883
+ if (diffHours < 9) {
884
+ return i18n.t(
885
+ longer ? 'datetime.hours_ago_ct' : 'datetime.hours_ago_short_ct',
886
+ {
887
+ smart_count: Math.floor(diffHours),
888
+ },
889
+ );
890
+ }
579
891
 
580
892
  if (dt.hasSame(now, 'day')) {
581
- return `${i18n.t('datetime.period_TODAY')}, ${timeText}`;
893
+ return i18n.t('datetime.today');
582
894
  }
583
895
 
584
896
  if (dt.hasSame(now.minus({ days: 1 }), 'day')) {
585
- return `${i18n.t('datetime.period_YESTERDAY')}, ${timeText}`;
897
+ return i18n.t('datetime.yesterday');
586
898
  }
587
899
 
588
- return null;
900
+ const diffDays = now.startOf('day').diff(dt.startOf('day'), 'days').days;
901
+ if (diffDays < 7) {
902
+ return i18n.t(
903
+ longer ? 'datetime.days_ago_ct' : 'datetime.days_ago_short_ct',
904
+ {
905
+ smart_count: Math.floor(diffDays),
906
+ },
907
+ );
908
+ }
909
+
910
+ return dt.toFormat('yyyy/MM/dd');
589
911
  }
590
912
 
591
913
  /**
592
- * Convert date time "time" ago
914
+ * Convert date time "time" ago: "Today, 10:21 PM", "Yesterday, 10:21 PM", or "9/14, 10:21 PM"
593
915
  * @param date - Date to convert
594
916
  * @param timeZone - Optional timezone for day boundary checks
917
+ * @param hideTime - Return only the day part ("Today", "Yesterday", "9/14") for narrow table cells
595
918
  */
596
919
 
597
920
  export function getTimeAgo(
598
921
  date: string | Date,
599
922
  timeZone: string | null,
923
+ hideTime?: boolean,
600
924
  ) {
601
925
  const dt = getDateTimeWithTimeZone(date, timeZone);
602
926
  if (!dt) {
603
927
  return null;
604
928
  }
605
929
 
606
- const now = timeZone && isValidTimeZone(timeZone)
607
- ? DateTime.now().setZone(timeZone)
608
- : DateTime.now();
609
- const todayYesterdayTime = getTodayYesterdayTime(dt, timeZone);
930
+ const now =
931
+ timeZone && isValidTimeZone(timeZone)
932
+ ? DateTime.now().setZone(timeZone)
933
+ : DateTime.now();
934
+ const todayYesterdayTime = getTodayYesterdayTime(dt, now, timeZone, hideTime);
610
935
 
611
936
  if (todayYesterdayTime) {
612
937
  return todayYesterdayTime;
613
938
  }
614
939
 
615
- const diffMs = now.toMillis() - dt.toMillis();
616
-
617
- if (diffMs < 0) {
618
- return getFullDateTime(dt.toJSDate(), {
619
- timeZone,
620
- alwaysShowYear: true,
621
- textDateStyle: 'short',
622
- });
623
- }
624
-
625
- return getFullDateTime(dt.toJSDate(), {
626
- timeZone,
627
- alwaysShowYear: true,
628
- textDateStyle: 'short',
629
- });
940
+ return getCompactDateTime(dt, now, timeZone, hideTime);
630
941
  }
631
942
 
632
943
  /**
@@ -639,6 +950,7 @@ export function getFullDate(
639
950
  outputStyle_:
640
951
  | 'NUMERIC'
641
952
  | 'NUMERIC_TIME'
953
+ | 'NUMERIC_TIME_COMPACT'
642
954
  | 'DATE_ONLY_SHORT'
643
955
  | 'DAY_IF_WEEK'
644
956
  | 'TOMORROW_OR_NUMERIC'
@@ -668,9 +980,11 @@ export function getFullDate(
668
980
  // return "Monday", "Tuesday", etc.
669
981
  const dayOfWeekText = d.toLocaleDateString(locales, {
670
982
  timeZone: timeZone || undefined, // null is not allowed, it will throw error
671
- ...(outputStyle_ === 'TOMORROW_OR_NUMERIC' ? {} : {
672
- weekday: 'long',
673
- }),
983
+ ...(outputStyle_ === 'TOMORROW_OR_NUMERIC'
984
+ ? {}
985
+ : {
986
+ weekday: 'long',
987
+ }),
674
988
  });
675
989
  return dayOfWeekText;
676
990
  }
@@ -681,24 +995,29 @@ export function getFullDate(
681
995
  }
682
996
 
683
997
  switch (outputStyle) {
684
- case 'NUMERIC':
998
+ case 'NUMERIC':
685
999
  // Expected output: "9/1/2024"
686
1000
  return new Intl.DateTimeFormat(locales, {
687
1001
  timeZone: timeZone || undefined, // null is not allowed, it will throw error
688
1002
  }).format(d);
689
- case 'NUMERIC_TIME': { // Expected output: "9/1/2024, 8:30 PM"
690
- const numericDate = new Intl.DateTimeFormat(locales, {
1003
+ case 'NUMERIC_TIME':
1004
+ case 'NUMERIC_TIME_COMPACT': {
1005
+ // Compact output: "9/01/2024, 8:30 PM"; default output: "9/1/2024, 8:30 PM".
1006
+ const compact = outputStyle === 'NUMERIC_TIME_COMPACT';
1007
+ const numericDate = new Intl.DateTimeFormat(locales, {
691
1008
  timeZone: timeZone || undefined, // null is not allowed, it will throw error
1009
+ ...(compact ? ({ month: 'numeric', day: '2-digit', year: 'numeric' } as const) : {}),
692
1010
  }).format(d);
693
1011
 
694
- const numericTime = new Intl.DateTimeFormat(locales, {
695
- timeZone: timeZone || undefined, // null is not allowed, it will throw error
696
- hour: 'numeric',
697
- minute: '2-digit',
698
- hour12: true,
699
- }).format(d);
1012
+ const numericTime = new Intl.DateTimeFormat(locales, {
1013
+ timeZone: timeZone || undefined, // null is not allowed, it will throw error
1014
+ hour: 'numeric',
1015
+ minute: '2-digit',
1016
+ hour12: true,
1017
+ }).format(d);
700
1018
 
701
- return `${numericDate}, ${numericTime}`;
1019
+ const numericDateTime = `${numericDate}, ${numericTime}`;
1020
+ return compact ? numericDateTime.toUpperCase() : numericDateTime;
702
1021
 
703
1022
  // return new Intl.DateTimeFormat(locales, {
704
1023
  // month: '2-digit',
@@ -709,7 +1028,7 @@ export function getFullDate(
709
1028
  // hour12: true,
710
1029
  // timeZone: timeZone || undefined, // null is not allowed, it will throw error
711
1030
  // }).format(d);
712
- }
1031
+ }
713
1032
  case 'MINIMAL':
714
1033
  // Expected output: "Sep 1, 2024, 6:54 PM"
715
1034
  return new Intl.DateTimeFormat(locales, {
@@ -717,7 +1036,7 @@ export function getFullDate(
717
1036
  timeStyle: 'short', // 'full', 'long', 'medium', 'short'
718
1037
  timeZone: timeZone || undefined, // null is not allowed, it will throw error
719
1038
  }).format(d);
720
- // return DateTime.fromJSDate(d, timeZone ? { zone: timeZone } : undefined).toFormat('MMM d yyyy, h:mm a');
1039
+ // return DateTime.fromJSDate(d, timeZone ? { zone: timeZone } : undefined).toFormat('MMM d yyyy, h:mm a');
721
1040
  case 'DATE_ONLY_SHORT': {
722
1041
  // Expected output: "Sep 1" (or "Sep 1, 25" if not current year)
723
1042
  const dateYear = d.getFullYear();
@@ -747,7 +1066,9 @@ export function getFullDate(
747
1066
  month: 'short',
748
1067
  day: 'numeric',
749
1068
  timeZone: timeZone || undefined, // null is not allowed, it will throw error
750
- }).format(d).replace(', ', ", '");
1069
+ })
1070
+ .format(d)
1071
+ .replace(', ', ", '");
751
1072
  }
752
1073
  case 'DATE_TEXT':
753
1074
  // Expected output: "September 1, 2024"
@@ -771,7 +1092,9 @@ export function getFullDate(
771
1092
  timeStyle: 'long',
772
1093
  }).formatToParts(d);
773
1094
 
774
- const timezoneName = parts.find((part) => part.type === 'timeZoneName')?.value;
1095
+ const timezoneName = parts.find(
1096
+ (part) => part.type === 'timeZoneName',
1097
+ )?.value;
775
1098
  if (timezoneName) {
776
1099
  // Doing this will make sure {date} does not include [seconds] in the time format
777
1100
  return date + ' ' + timezoneName;
@@ -801,9 +1124,16 @@ export function getDayPeriod(): 'MORNING' | 'AFTERNOON' | 'EVENING' | 'NIGHT' {
801
1124
  * Convert YYYY-MM-DD to Date
802
1125
  */
803
1126
 
804
- export function getDateFromCalDate(value: string | number, timeZone?: string | null): Date {
805
- const calDate = typeof value === 'number' ? convertIntToCalDate(value) : value;
806
- const dt = DateTime.fromISO(calDate, timeZone ? { zone: timeZone } : undefined);
1127
+ export function getDateFromCalDate(
1128
+ value: string | number,
1129
+ timeZone?: string | null,
1130
+ ): Date {
1131
+ const calDate =
1132
+ typeof value === 'number' ? convertIntToCalDate(value) : value;
1133
+ const dt = DateTime.fromISO(
1134
+ calDate,
1135
+ timeZone ? { zone: timeZone } : undefined,
1136
+ );
807
1137
  const jsDate = dt.toJSDate();
808
1138
  // const [year, month, day] = calDate.split('-');
809
1139
  // console.log(new Date(Number(year), Number(month) - 1, Number(day)));
@@ -853,7 +1183,9 @@ export function groupByDatePeriod<T>(
853
1183
  const lastItem = group[group.length - 1];
854
1184
  const lastDatePeriod: any = lastItem?.datePeriod;
855
1185
  const date = new Date(getObject(item, dateKey));
856
- const datePeriod = groupByDate ? getCalDate(date, timeZone).calDate : getDatePeriod(date, d);
1186
+ const datePeriod = groupByDate
1187
+ ? getCalDate(date, timeZone).calDate
1188
+ : getDatePeriod(date, d);
857
1189
 
858
1190
  const dateObj = {
859
1191
  datePeriod,
@@ -913,7 +1245,9 @@ export function labelSortByDatePeriod<T>(
913
1245
  const lastItem = output[output.length - 1];
914
1246
  const lastDatePeriod: any = lastItem?.datePeriod;
915
1247
  const date = new Date(item[dateKey]);
916
- const datePeriod = groupByDate ? getCalDate(date, timeZone).calDate : getDatePeriod(date, d);
1248
+ const datePeriod = groupByDate
1249
+ ? getCalDate(date, timeZone).calDate
1250
+ : getDatePeriod(date, d);
917
1251
 
918
1252
  const dateObj = {
919
1253
  datePeriod,
@@ -921,10 +1255,7 @@ export function labelSortByDatePeriod<T>(
921
1255
  item: mapFn ? mapFn(item) : item,
922
1256
  };
923
1257
 
924
- if (
925
- (!output.length) ||
926
- (lastDatePeriod && lastDatePeriod !== datePeriod)
927
- ) {
1258
+ if (!output.length || (lastDatePeriod && lastDatePeriod !== datePeriod)) {
928
1259
  output.push({
929
1260
  datePeriod,
930
1261
  date,
@@ -1028,39 +1359,36 @@ export function timeToHHMM(timeStr: string): string {
1028
1359
  */
1029
1360
 
1030
1361
  export function groupByDateMonth<T extends { date: Date }>(
1031
- items: T[],
1032
- timeZone: string
1362
+ items: T[],
1363
+ timeZone: string,
1033
1364
  ): {
1034
- byDate: Record<string, T[]>;
1035
- byMonth: Record<string, T[]>;
1365
+ byDate: Record<string, T[]>;
1366
+ byMonth: Record<string, T[]>;
1036
1367
  } {
1037
- // 1. Sort by absolute time
1038
- const sorted = [...items].sort(
1039
- (a, b) => a.date.getTime() - b.date.getTime()
1040
- );
1041
-
1042
- const byDate: Record<string, T[]> = {};
1043
- const byMonth: Record<string, T[]> = {};
1044
-
1045
- for (const item of sorted) {
1046
- const dt = DateTime
1047
- .fromJSDate(item.date, { zone: timeZone });
1048
-
1049
- const dateKey = dt.toFormat('yyyy-MM-dd');
1050
- const monthKey = dt.toFormat('yyyy-MM');
1051
-
1052
- // Group by day
1053
- if (!byDate[dateKey]) {
1054
- byDate[dateKey] = [];
1055
- }
1056
- byDate[dateKey].push(item);
1057
-
1058
- // Group by month
1059
- if (!byMonth[monthKey]) {
1060
- byMonth[monthKey] = [];
1061
- }
1062
- byMonth[monthKey].push(item);
1063
- }
1064
-
1065
- return { byDate, byMonth };
1368
+ // 1. Sort by absolute time
1369
+ const sorted = [...items].sort((a, b) => a.date.getTime() - b.date.getTime());
1370
+
1371
+ const byDate: Record<string, T[]> = {};
1372
+ const byMonth: Record<string, T[]> = {};
1373
+
1374
+ for (const item of sorted) {
1375
+ const dt = DateTime.fromJSDate(item.date, { zone: timeZone });
1376
+
1377
+ const dateKey = dt.toFormat('yyyy-MM-dd');
1378
+ const monthKey = dt.toFormat('yyyy-MM');
1379
+
1380
+ // Group by day
1381
+ if (!byDate[dateKey]) {
1382
+ byDate[dateKey] = [];
1383
+ }
1384
+ byDate[dateKey].push(item);
1385
+
1386
+ // Group by month
1387
+ if (!byMonth[monthKey]) {
1388
+ byMonth[monthKey] = [];
1389
+ }
1390
+ byMonth[monthKey].push(item);
1391
+ }
1392
+
1393
+ return { byDate, byMonth };
1066
1394
  }