@umituz/react-native-design-system 4.25.111 → 4.25.113
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/dist/timezone/domain/entities/TimezoneCapabilities.d.ts +11 -0
- package/dist/timezone/infrastructure/services/DateFormatter.d.ts +31 -0
- package/dist/timezone/infrastructure/services/TimezoneService.d.ts +8 -0
- package/dist/timezone/presentation/hooks/useTimezone.d.ts +8 -0
- package/package.json +6 -2
- package/src/tanstack/infrastructure/config/PersisterConfig.ts +12 -4
- package/src/timezone/domain/entities/TimezoneCapabilities.ts +18 -0
- package/src/timezone/infrastructure/services/DateFormatter.ts +109 -0
- package/src/timezone/infrastructure/services/TimezoneService.ts +19 -0
- package/src/timezone/presentation/hooks/useTimezone.ts +21 -0
|
@@ -36,6 +36,17 @@ export interface ITimezoneFormatting {
|
|
|
36
36
|
formatToISOString(date: Date | string | number): string;
|
|
37
37
|
/** Format duration in milliseconds to human readable string */
|
|
38
38
|
formatDuration(milliseconds: number): string;
|
|
39
|
+
/** Format time as minutes:seconds (e.g., "3:45", "12:05") */
|
|
40
|
+
formatTimeShort(seconds: number): string;
|
|
41
|
+
/** Format date with relative time labels (Today, Yesterday, X days ago, X weeks ago) */
|
|
42
|
+
formatRelativeDate(date: Date | string | number, locale: string, translations?: {
|
|
43
|
+
today?: string;
|
|
44
|
+
yesterday?: string;
|
|
45
|
+
daysAgo?: string;
|
|
46
|
+
weeksAgo?: string;
|
|
47
|
+
}): string;
|
|
48
|
+
/** Format date in short format (Jan 1, 2024) */
|
|
49
|
+
formatShortDate(date: Date | string | number, locale: string): string;
|
|
39
50
|
/** Get relative time from now ("5 minutes ago", "in 2 hours") */
|
|
40
51
|
fromNow(date: Date | string | number, locale?: string): string;
|
|
41
52
|
}
|
|
@@ -9,4 +9,35 @@ export declare class DateFormatter {
|
|
|
9
9
|
formatRelativeTime(date: Date | string | number, locale: string): string;
|
|
10
10
|
parse(date: Date | string | number): Date;
|
|
11
11
|
formatDuration(milliseconds: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* Format time as minutes:seconds (e.g., "3:45", "12:05")
|
|
14
|
+
* @param seconds - Time in seconds
|
|
15
|
+
* @returns Formatted time string
|
|
16
|
+
*/
|
|
17
|
+
formatTimeShort(seconds: number): string;
|
|
18
|
+
/**
|
|
19
|
+
* Format date with relative time labels (Today, Yesterday, X days ago, X weeks ago)
|
|
20
|
+
* @param date - Date to format
|
|
21
|
+
* @param locale - Locale code
|
|
22
|
+
* @param translations - Optional translations for "Today", "Yesterday", "days ago", "weeks ago"
|
|
23
|
+
* @returns Formatted relative date string
|
|
24
|
+
*/
|
|
25
|
+
formatRelativeDate(date: Date | string | number, locale: string, translations?: {
|
|
26
|
+
today?: string;
|
|
27
|
+
yesterday?: string;
|
|
28
|
+
daysAgo?: string;
|
|
29
|
+
weeksAgo?: string;
|
|
30
|
+
}): string;
|
|
31
|
+
/**
|
|
32
|
+
* Get default translation for relative time keys
|
|
33
|
+
*/
|
|
34
|
+
private getDefaultTranslation;
|
|
35
|
+
/**
|
|
36
|
+
* Format date in short format (Jan 1, 2024)
|
|
37
|
+
*/
|
|
38
|
+
formatShortDate(date: Date | string | number, locale: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Alias for formatRelativeTime - more semantic name for "time ago" formatting
|
|
41
|
+
*/
|
|
42
|
+
fromNow(date: Date | string | number, locale: string): string;
|
|
12
43
|
}
|
|
@@ -45,6 +45,14 @@ export declare class TimezoneService implements ITimezoneService {
|
|
|
45
45
|
getTimezoneOffsetFor(timezone: string, date?: Date | string | number): number;
|
|
46
46
|
convertTimezone(date: Date | string | number, fromTimezone: string, toTimezone: string): Date;
|
|
47
47
|
formatDuration(milliseconds: number): string;
|
|
48
|
+
formatTimeShort(seconds: number): string;
|
|
49
|
+
formatRelativeDate(date: Date | string | number, locale: string, translations?: {
|
|
50
|
+
today?: string;
|
|
51
|
+
yesterday?: string;
|
|
52
|
+
daysAgo?: string;
|
|
53
|
+
weeksAgo?: string;
|
|
54
|
+
}): string;
|
|
55
|
+
formatShortDate(date: Date | string | number, locale: string): string;
|
|
48
56
|
isWeekend(date: Date | string | number): boolean;
|
|
49
57
|
addBusinessDays(date: Date | string | number, days: number): Date;
|
|
50
58
|
isFirstDayOfMonth(date: Date | string | number): boolean;
|
|
@@ -15,6 +15,14 @@ export interface UseTimezoneReturn {
|
|
|
15
15
|
formatToISOString: (date: Date) => string;
|
|
16
16
|
formatRelativeTime: (date: Date) => string;
|
|
17
17
|
formatDateTime: (date: Date, options?: Intl.DateTimeFormatOptions) => string;
|
|
18
|
+
formatTimeShort: (seconds: number) => string;
|
|
19
|
+
formatRelativeDate: (date: Date, translations?: {
|
|
20
|
+
today?: string;
|
|
21
|
+
yesterday?: string;
|
|
22
|
+
daysAgo?: string;
|
|
23
|
+
weeksAgo?: string;
|
|
24
|
+
}) => string;
|
|
25
|
+
formatShortDate: (date: Date) => string;
|
|
18
26
|
getTimezones: () => TimezoneInfo[];
|
|
19
27
|
isValid: (date: Date) => boolean;
|
|
20
28
|
getAge: (birthDate: Date) => number;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-design-system",
|
|
3
|
-
"version": "4.25.
|
|
4
|
-
"description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive, safe area, exception, infinite scroll, UUID, image, timezone, offline, onboarding, and loading utilities",
|
|
3
|
+
"version": "4.25.113",
|
|
4
|
+
"description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive, safe area, exception, infinite scroll, UUID, image, timezone, offline, onboarding, and loading utilities - TanStack persistence now lazy loaded",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -172,6 +172,10 @@
|
|
|
172
172
|
"react-native-svg": "^15.12.1",
|
|
173
173
|
"rn-emoji-keyboard": "^1.7.0"
|
|
174
174
|
},
|
|
175
|
+
"optionalDependencies": {
|
|
176
|
+
"@tanstack/query-async-storage-persister": "^5.0.0",
|
|
177
|
+
"@tanstack/react-query-persist-client": "^5.0.0"
|
|
178
|
+
},
|
|
175
179
|
"keywords": [
|
|
176
180
|
"react-native",
|
|
177
181
|
"design-system",
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
* Infrastructure layer - AsyncStorage persistence setup
|
|
4
4
|
*
|
|
5
5
|
* General-purpose persistence configuration for any React Native app
|
|
6
|
+
* Lazy loads TanStack persistence packages to reduce bundle size
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
|
-
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister';
|
|
9
9
|
import { storageService } from '../../../storage';
|
|
10
10
|
import { DEFAULT_GC_TIME } from '../../domain/constants/CacheDefaults';
|
|
11
|
-
import type { Persister } from '@tanstack/react-query-persist-client';
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Persister factory options
|
|
@@ -44,6 +43,7 @@ export interface PersisterFactoryOptions {
|
|
|
44
43
|
|
|
45
44
|
/**
|
|
46
45
|
* Create an AsyncStorage persister for TanStack Query
|
|
46
|
+
* Lazy loads the persistence packages to reduce initial bundle size
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
49
49
|
* ```typescript
|
|
@@ -54,7 +54,15 @@ export interface PersisterFactoryOptions {
|
|
|
54
54
|
* });
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
|
-
export function createPersister(options: PersisterFactoryOptions = {})
|
|
57
|
+
export async function createPersister(options: PersisterFactoryOptions = {}) {
|
|
58
|
+
// Lazy load TanStack persistence packages
|
|
59
|
+
const [{ createAsyncStoragePersister }, { default: { PersistQueryClient }] = await Promise.all([
|
|
60
|
+
import('@tanstack/query-async-storage-persister'),
|
|
61
|
+
import('@tanstack/react-query-persist-client'),
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
type Persister = ReturnType<typeof createAsyncStoragePersister>;
|
|
65
|
+
|
|
58
66
|
const {
|
|
59
67
|
keyPrefix = 'tanstack-query',
|
|
60
68
|
maxAge = DEFAULT_GC_TIME.LONG,
|
|
@@ -106,7 +114,7 @@ export function createPersister(options: PersisterFactoryOptions = {}): Persiste
|
|
|
106
114
|
return undefined;
|
|
107
115
|
}
|
|
108
116
|
},
|
|
109
|
-
});
|
|
117
|
+
}) as Persister;
|
|
110
118
|
}
|
|
111
119
|
|
|
112
120
|
/**
|
|
@@ -59,6 +59,24 @@ export interface ITimezoneFormatting {
|
|
|
59
59
|
/** Format duration in milliseconds to human readable string */
|
|
60
60
|
formatDuration(milliseconds: number): string;
|
|
61
61
|
|
|
62
|
+
/** Format time as minutes:seconds (e.g., "3:45", "12:05") */
|
|
63
|
+
formatTimeShort(seconds: number): string;
|
|
64
|
+
|
|
65
|
+
/** Format date with relative time labels (Today, Yesterday, X days ago, X weeks ago) */
|
|
66
|
+
formatRelativeDate(
|
|
67
|
+
date: Date | string | number,
|
|
68
|
+
locale: string,
|
|
69
|
+
translations?: {
|
|
70
|
+
today?: string;
|
|
71
|
+
yesterday?: string;
|
|
72
|
+
daysAgo?: string;
|
|
73
|
+
weeksAgo?: string;
|
|
74
|
+
}
|
|
75
|
+
): string;
|
|
76
|
+
|
|
77
|
+
/** Format date in short format (Jan 1, 2024) */
|
|
78
|
+
formatShortDate(date: Date | string | number, locale: string): string;
|
|
79
|
+
|
|
62
80
|
/** Get relative time from now ("5 minutes ago", "in 2 hours") */
|
|
63
81
|
fromNow(date: Date | string | number, locale?: string): string;
|
|
64
82
|
}
|
|
@@ -131,4 +131,113 @@ export class DateFormatter {
|
|
|
131
131
|
|
|
132
132
|
return parts.join(' ');
|
|
133
133
|
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Format time as minutes:seconds (e.g., "3:45", "12:05")
|
|
137
|
+
* @param seconds - Time in seconds
|
|
138
|
+
* @returns Formatted time string
|
|
139
|
+
*/
|
|
140
|
+
formatTimeShort(seconds: number): string {
|
|
141
|
+
const mins = Math.floor(seconds / 60);
|
|
142
|
+
const secs = seconds % 60;
|
|
143
|
+
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Format date with relative time labels (Today, Yesterday, X days ago, X weeks ago)
|
|
148
|
+
* @param date - Date to format
|
|
149
|
+
* @param locale - Locale code
|
|
150
|
+
* @param translations - Optional translations for "Today", "Yesterday", "days ago", "weeks ago"
|
|
151
|
+
* @returns Formatted relative date string
|
|
152
|
+
*/
|
|
153
|
+
formatRelativeDate(
|
|
154
|
+
date: Date | string | number,
|
|
155
|
+
locale: string,
|
|
156
|
+
translations?: {
|
|
157
|
+
today?: string;
|
|
158
|
+
yesterday?: string;
|
|
159
|
+
daysAgo?: string;
|
|
160
|
+
weeksAgo?: string;
|
|
161
|
+
}
|
|
162
|
+
): string {
|
|
163
|
+
const d = this.parse(date);
|
|
164
|
+
const now = new Date();
|
|
165
|
+
const diffInMs = now.getTime() - d.getTime();
|
|
166
|
+
const diffInDays = Math.floor(diffInMs / (1000 * 60 * 60 * 24));
|
|
167
|
+
|
|
168
|
+
// Check for today (today at midnight vs date at midnight)
|
|
169
|
+
const todayDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
170
|
+
const targetDate = new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
171
|
+
const daysDiff = Math.floor((todayDate.getTime() - targetDate.getTime()) / (1000 * 60 * 60 * 24));
|
|
172
|
+
|
|
173
|
+
if (daysDiff === 0) {
|
|
174
|
+
return translations?.today || this.getDefaultTranslation('today', locale);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (daysDiff === 1) {
|
|
178
|
+
return translations?.yesterday || this.getDefaultTranslation('yesterday', locale);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (daysDiff > 0 && daysDiff < 7) {
|
|
182
|
+
const template = translations?.daysAgo || this.getDefaultTranslation('daysAgo', locale);
|
|
183
|
+
return template.replace('{{days}}', daysDiff.toString());
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (daysDiff >= 7 && daysDiff < 30) {
|
|
187
|
+
const weeks = Math.floor(daysDiff / 7);
|
|
188
|
+
const template = translations?.weeksAgo || this.getDefaultTranslation('weeksAgo', locale);
|
|
189
|
+
return template.replace('{{weeks}}', weeks.toString());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Fall back to regular date format for older dates
|
|
193
|
+
return this.formatDate(d, locale, {
|
|
194
|
+
year: 'numeric',
|
|
195
|
+
month: 'short',
|
|
196
|
+
day: 'numeric',
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Get default translation for relative time keys
|
|
202
|
+
*/
|
|
203
|
+
private getDefaultTranslation(key: string, locale: string): string {
|
|
204
|
+
const translations: Record<string, Record<string, string>> = {
|
|
205
|
+
today: {
|
|
206
|
+
en: 'Today',
|
|
207
|
+
tr: 'Bugün',
|
|
208
|
+
},
|
|
209
|
+
yesterday: {
|
|
210
|
+
en: 'Yesterday',
|
|
211
|
+
tr: 'Dün',
|
|
212
|
+
},
|
|
213
|
+
daysAgo: {
|
|
214
|
+
en: '{{days}} days ago',
|
|
215
|
+
tr: '{{days}} gün önce',
|
|
216
|
+
},
|
|
217
|
+
weeksAgo: {
|
|
218
|
+
en: '{{weeks}} weeks ago',
|
|
219
|
+
tr: '{{weeks}} hafta önce',
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
return translations[key]?.[locale] || translations[key]?.en || key;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Format date in short format (Jan 1, 2024)
|
|
228
|
+
*/
|
|
229
|
+
formatShortDate(date: Date | string | number, locale: string): string {
|
|
230
|
+
return this.formatDate(date, locale, {
|
|
231
|
+
year: 'numeric',
|
|
232
|
+
month: 'short',
|
|
233
|
+
day: 'numeric',
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Alias for formatRelativeTime - more semantic name for "time ago" formatting
|
|
239
|
+
*/
|
|
240
|
+
fromNow(date: Date | string | number, locale: string): string {
|
|
241
|
+
return this.formatRelativeTime(date, locale);
|
|
242
|
+
}
|
|
134
243
|
}
|
|
@@ -99,6 +99,25 @@ export class TimezoneService implements ITimezoneService {
|
|
|
99
99
|
|
|
100
100
|
formatDuration(milliseconds: number): string { return this.formatter.formatDuration(milliseconds); }
|
|
101
101
|
|
|
102
|
+
formatTimeShort(seconds: number): string { return this.formatter.formatTimeShort(seconds); }
|
|
103
|
+
|
|
104
|
+
formatRelativeDate(
|
|
105
|
+
date: Date | string | number,
|
|
106
|
+
locale: string,
|
|
107
|
+
translations?: {
|
|
108
|
+
today?: string;
|
|
109
|
+
yesterday?: string;
|
|
110
|
+
daysAgo?: string;
|
|
111
|
+
weeksAgo?: string;
|
|
112
|
+
}
|
|
113
|
+
): string {
|
|
114
|
+
return this.formatter.formatRelativeDate(date, locale, translations);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
formatShortDate(date: Date | string | number, locale: string): string {
|
|
118
|
+
return this.formatter.formatShortDate(date, locale);
|
|
119
|
+
}
|
|
120
|
+
|
|
102
121
|
isWeekend(date: Date | string | number): boolean { return this.businessCalendar.isWeekend(date); }
|
|
103
122
|
|
|
104
123
|
addBusinessDays(date: Date | string | number, days: number): Date {
|
|
@@ -18,6 +18,17 @@ export interface UseTimezoneReturn {
|
|
|
18
18
|
formatToISOString: (date: Date) => string;
|
|
19
19
|
formatRelativeTime: (date: Date) => string;
|
|
20
20
|
formatDateTime: (date: Date, options?: Intl.DateTimeFormatOptions) => string;
|
|
21
|
+
formatTimeShort: (seconds: number) => string;
|
|
22
|
+
formatRelativeDate: (
|
|
23
|
+
date: Date,
|
|
24
|
+
translations?: {
|
|
25
|
+
today?: string;
|
|
26
|
+
yesterday?: string;
|
|
27
|
+
daysAgo?: string;
|
|
28
|
+
weeksAgo?: string;
|
|
29
|
+
}
|
|
30
|
+
) => string;
|
|
31
|
+
formatShortDate: (date: Date) => string;
|
|
21
32
|
getTimezones: () => TimezoneInfo[];
|
|
22
33
|
isValid: (date: Date) => boolean;
|
|
23
34
|
getAge: (birthDate: Date) => number;
|
|
@@ -66,9 +77,19 @@ export const useTimezone = (options?: UseTimezoneOptions): UseTimezoneReturn =>
|
|
|
66
77
|
timezoneService.formatDateTime(date, locale, opts),
|
|
67
78
|
formatRelativeTime: (date: Date) =>
|
|
68
79
|
timezoneService.formatRelativeTime(date, locale),
|
|
80
|
+
formatShortDate: (date: Date) =>
|
|
81
|
+
timezoneService.formatShortDate(date, locale),
|
|
82
|
+
formatRelativeDate: (date: Date, translations?: {
|
|
83
|
+
today?: string;
|
|
84
|
+
yesterday?: string;
|
|
85
|
+
daysAgo?: string;
|
|
86
|
+
weeksAgo?: string;
|
|
87
|
+
}) =>
|
|
88
|
+
timezoneService.formatRelativeDate(date, locale, translations),
|
|
69
89
|
fromNow: (date: Date) =>
|
|
70
90
|
timezoneService.fromNow(date, locale),
|
|
71
91
|
// Locale-independent delegates
|
|
92
|
+
formatTimeShort: (seconds: number) => timezoneService.formatTimeShort(seconds),
|
|
72
93
|
getCalendarDays: (year: number, month: number) => timezoneService.getCalendarDays(year, month),
|
|
73
94
|
isToday: (date: Date) => timezoneService.isToday(date),
|
|
74
95
|
isSameDay: (date1: Date, date2: Date) => timezoneService.isSameDay(date1, date2),
|