@tap-payments/os-micro-frontend-shared 0.1.224-test.4 → 0.1.224-test.6
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/build/utils/date.d.ts +1 -1
- package/build/utils/date.js +9 -8
- package/package.json +2 -2
package/build/utils/date.d.ts
CHANGED
|
@@ -40,5 +40,5 @@ export declare const generatePastYearList: (length?: number) => {
|
|
|
40
40
|
export declare function secondsToTimeString(seconds: number): string;
|
|
41
41
|
type TimeUnit = 'seconds' | 'minutes' | 'hours' | 'days';
|
|
42
42
|
export declare function isWithinTimeAgo(timestampMs: number, amount: number, unit?: TimeUnit): boolean;
|
|
43
|
-
export declare const formatRelativeTimeWithinHour: (
|
|
43
|
+
export declare const formatRelativeTimeWithinHour: (timestampMs: number) => string;
|
|
44
44
|
export {};
|
package/build/utils/date.js
CHANGED
|
@@ -227,14 +227,15 @@ export function isWithinTimeAgo(timestampMs, amount, unit = 'seconds') {
|
|
|
227
227
|
const diffSeconds = (now - timestampMs) / 1000;
|
|
228
228
|
return diffSeconds < amount * unitSeconds[unit];
|
|
229
229
|
}
|
|
230
|
-
export const formatRelativeTimeWithinHour = (
|
|
231
|
-
|
|
230
|
+
export const formatRelativeTimeWithinHour = (timestampMs) => {
|
|
231
|
+
const now = Date.now();
|
|
232
|
+
const diffSeconds = Math.floor((now - timestampMs) / 1000);
|
|
233
|
+
const diffMinutes = Math.floor(diffSeconds / 60);
|
|
234
|
+
if (isWithinTimeAgo(timestampMs, 60, 'seconds')) {
|
|
232
235
|
return 'just now';
|
|
233
|
-
if (diffSeconds < 60)
|
|
234
|
-
return `${Math.floor(diffSeconds)} seconds ago`;
|
|
235
|
-
if (diffSeconds < 3600) {
|
|
236
|
-
const minutes = Math.floor(diffSeconds / 60);
|
|
237
|
-
return `${minutes} minute${minutes !== 1 ? 's' : ''} ago`;
|
|
238
236
|
}
|
|
239
|
-
|
|
237
|
+
if (isWithinTimeAgo(timestampMs, 60, 'minutes')) {
|
|
238
|
+
return `${diffMinutes} min${diffMinutes === 1 ? '' : 's'} ago`;
|
|
239
|
+
}
|
|
240
|
+
return '1 hour ago'; // fallback for > 59 mins
|
|
240
241
|
};
|
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.224-test.
|
|
5
|
-
"testVersion":
|
|
4
|
+
"version": "0.1.224-test.6",
|
|
5
|
+
"testVersion": 6,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|