@tap-payments/os-micro-frontend-shared 0.1.365-test.20 → 0.1.365-test.22

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.
@@ -59,7 +59,7 @@ function RangeCalender({ defaultDate, onDateChange, mode = 'gregorian', onCalend
59
59
  };
60
60
  const getSelectedDate = () => {
61
61
  const nowYear = dayjs().year();
62
- const formatDate = (date) => (date.year === nowYear ? date.format('MMM D') : date.format('MMM D, YYYY'));
62
+ const formatDate = (date) => (date.year === nowYear ? date.format('MMM D') : date.format('MMM D YYYY'));
63
63
  const startSelectedTime = formatDate(dates[0]);
64
64
  const endSelectedTime = dates[1] ? formatDate(dates[1]) : formatDate(dates[0]);
65
65
  return startSelectedTime === endSelectedTime && !noTimezone ? startSelectedTime : `${startSelectedTime} - ${endSelectedTime}`;
@@ -32,3 +32,4 @@ export * from './filter';
32
32
  export * from './utilities';
33
33
  export * from './reports';
34
34
  export * from './document';
35
+ export * from './toggleOptions';
@@ -32,3 +32,4 @@ export * from './filter';
32
32
  export * from './utilities';
33
33
  export * from './reports';
34
34
  export * from './document';
35
+ export * from './toggleOptions';
@@ -0,0 +1,2 @@
1
+ import { DATA_KEY } from '../constants/index.js';
2
+ export type DataKey = (typeof DATA_KEY)[keyof typeof DATA_KEY];
@@ -0,0 +1 @@
1
+ export {};
@@ -43,4 +43,9 @@ export declare function isWithinTimeAgo(timestampMs: number, amount: number, uni
43
43
  export declare const formatRelativeTimeWithinHour: (timestampMs: number) => string;
44
44
  export declare const isTodayDate: (date: string | Date) => boolean;
45
45
  export declare const isYesterdayDate: (date: string | Date) => boolean;
46
+ export interface InsightDateLabelResult {
47
+ label: string;
48
+ isCustom: boolean;
49
+ }
50
+ export declare const getDateLabel: (from: Date, to: Date) => InsightDateLabelResult;
46
51
  export {};
@@ -243,3 +243,32 @@ export const formatRelativeTimeWithinHour = (timestampMs) => {
243
243
  };
244
244
  export const isTodayDate = (date) => dayjs(date).isToday();
245
245
  export const isYesterdayDate = (date) => dayjs(date).isYesterday();
246
+ export const getDateLabel = (from, to) => {
247
+ const start = dayjs(from).startOf('day');
248
+ const end = dayjs(to).endOf('day');
249
+ const today = dayjs().startOf('day');
250
+ const currentYear = today.year();
251
+ const diffDays = end.diff(start, 'day') + 1;
252
+ if (start.isToday() && end.isToday())
253
+ return { label: 'Today', isCustom: false };
254
+ if (start.isYesterday() && end.isYesterday())
255
+ return { label: 'Yesterday', isCustom: false };
256
+ if (diffDays === 7 && end.isSame(today, 'day')) {
257
+ return { label: 'Last 7 days', isCustom: false };
258
+ }
259
+ // Last 30 days (inclusive)
260
+ if (diffDays === 31 && end.isSame(today, 'day'))
261
+ return { label: 'Last 30 days', isCustom: false };
262
+ if (start.date() === 1 && end.date() === end.daysInMonth() && start.month() === end.month()) {
263
+ const monthLabel = start.year() === currentYear ? start.format('MMMM') : start.format('MMMM YYYY');
264
+ return { label: monthLabel, isCustom: false };
265
+ }
266
+ const showStartYear = start.year() !== currentYear;
267
+ const showEndYear = end.year() !== currentYear;
268
+ const startLabel = start.format(`MMM D${showStartYear ? ', YYYY' : ''}`);
269
+ const endLabel = end.format(`MMM D${showEndYear ? ', YYYY' : ''}`);
270
+ return {
271
+ label: `${startLabel} – ${endLabel}`,
272
+ isCustom: true,
273
+ };
274
+ };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@tap-payments/os-micro-frontend-shared",
3
3
  "description": "Shared components and utilities for Tap Payments micro frontends",
4
- "version": "0.1.365-test.20",
5
- "testVersion": 20,
4
+ "version": "0.1.365-test.22",
5
+ "testVersion": 22,
6
6
  "type": "module",
7
7
  "main": "build/index.js",
8
8
  "module": "build/index.js",