@umituz/react-native-firebase 2.4.72 → 2.4.73
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.73",
|
|
4
4
|
"description": "Unified Firebase package for React Native apps - Auth and Firestore services using Firebase JS SDK (no native modules).",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -51,3 +51,49 @@ export function timestampToDate(timestamp: Timestamp | null | undefined): Date |
|
|
|
51
51
|
export function getCurrentISOString(): string {
|
|
52
52
|
return new Date().toISOString();
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Labels for relative time formatting.
|
|
57
|
+
* Pass localized strings to support i18n.
|
|
58
|
+
*/
|
|
59
|
+
export interface RelativeTimeLabels {
|
|
60
|
+
now: string;
|
|
61
|
+
minutes: string;
|
|
62
|
+
hours: string;
|
|
63
|
+
days: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const DEFAULT_LABELS: RelativeTimeLabels = {
|
|
67
|
+
now: "now",
|
|
68
|
+
minutes: "m",
|
|
69
|
+
hours: "h",
|
|
70
|
+
days: "d",
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Format a Date (or Firestore Timestamp) as a short relative time string.
|
|
75
|
+
*
|
|
76
|
+
* Examples: "now", "5m", "2h", "3d", or a localized date for older values.
|
|
77
|
+
*
|
|
78
|
+
* @param date The date to format (typically from `timestampToDate()` or `Timestamp.toDate()`)
|
|
79
|
+
* @param labels Optional localized labels — defaults to English abbreviations
|
|
80
|
+
*/
|
|
81
|
+
export function formatRelativeTime(
|
|
82
|
+
date: Date,
|
|
83
|
+
labels: RelativeTimeLabels = DEFAULT_LABELS,
|
|
84
|
+
): string {
|
|
85
|
+
const now = new Date();
|
|
86
|
+
const diffMs = now.getTime() - date.getTime();
|
|
87
|
+
const diffMins = Math.floor(diffMs / 60_000);
|
|
88
|
+
|
|
89
|
+
if (diffMins < 1) return labels.now;
|
|
90
|
+
if (diffMins < 60) return `${diffMins}${labels.minutes}`;
|
|
91
|
+
|
|
92
|
+
const diffHours = Math.floor(diffMins / 60);
|
|
93
|
+
if (diffHours < 24) return `${diffHours}${labels.hours}`;
|
|
94
|
+
|
|
95
|
+
const diffDays = Math.floor(diffHours / 24);
|
|
96
|
+
if (diffDays < 7) return `${diffDays}${labels.days}`;
|
|
97
|
+
|
|
98
|
+
return date.toLocaleDateString();
|
|
99
|
+
}
|