Skip to content

Commit ccb9a5d

Browse files
committed
fix(ci): add all required ESLint plugins and fix formatting
- Add eslint-plugin-react, eslint-plugin-react-hooks, eslint-plugin-react-native - Add @typescript-eslint/parser, @typescript-eslint/eslint-plugin - Add eslint-plugin-jest, eslint-plugin-ft-flow - Fix prettier formatting issues
1 parent 5f97c2d commit ccb9a5d

6 files changed

Lines changed: 329 additions & 31 deletions

File tree

packages/native-date/__tests__/__mocks__/react-native-nitro-modules.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,8 @@ const mockNativeDate = {
900900
getTimezone: () => 'America/New_York',
901901
getTimezoneOffset: () => new Date().getTimezoneOffset(),
902902
getTimezoneOffsetForTimestamp: () => new Date().getTimezoneOffset(),
903-
getOffsetInTimezone: (ts: number, tz: string) => getTimezoneOffsetForDate(tz, ts),
903+
getOffsetInTimezone: (ts: number, tz: string) =>
904+
getTimezoneOffsetForDate(tz, ts),
904905
toTimezone: (ts: number, _tz: string) => ts, // Simplified
905906
formatInTimezone: (ts: number, pattern: string, tz: string) => {
906907
// Apply timezone offset for proper formatting
@@ -914,45 +915,63 @@ const mockNativeDate = {
914915
// Timezone-aware predicates (InTz)
915916
isTodayInTz: (ts: number, tz: string) => {
916917
const dateStr = mockNativeDate.formatInTimezone(ts, 'yyyy-MM-dd', tz);
917-
const todayStr = mockNativeDate.formatInTimezone(Date.now(), 'yyyy-MM-dd', tz);
918+
const todayStr = mockNativeDate.formatInTimezone(
919+
Date.now(),
920+
'yyyy-MM-dd',
921+
tz
922+
);
918923
return dateStr === todayStr;
919924
},
920925
isTomorrowInTz: (ts: number, tz: string) => {
921926
const dateStr = mockNativeDate.formatInTimezone(ts, 'yyyy-MM-dd', tz);
922927
const tomorrowTs = addToDate(Date.now(), 1, 'day');
923-
const tomorrowStr = mockNativeDate.formatInTimezone(tomorrowTs, 'yyyy-MM-dd', tz);
928+
const tomorrowStr = mockNativeDate.formatInTimezone(
929+
tomorrowTs,
930+
'yyyy-MM-dd',
931+
tz
932+
);
924933
return dateStr === tomorrowStr;
925934
},
926935
isYesterdayInTz: (ts: number, tz: string) => {
927936
const dateStr = mockNativeDate.formatInTimezone(ts, 'yyyy-MM-dd', tz);
928937
const yesterdayTs = addToDate(Date.now(), -1, 'day');
929-
const yesterdayStr = mockNativeDate.formatInTimezone(yesterdayTs, 'yyyy-MM-dd', tz);
938+
const yesterdayStr = mockNativeDate.formatInTimezone(
939+
yesterdayTs,
940+
'yyyy-MM-dd',
941+
tz
942+
);
930943
return dateStr === yesterdayStr;
931944
},
932945
isSameDayInTz: (ts1: number, ts2: number, tz: string) => {
933-
return mockNativeDate.formatInTimezone(ts1, 'yyyy-MM-dd', tz) ===
934-
mockNativeDate.formatInTimezone(ts2, 'yyyy-MM-dd', tz);
946+
return (
947+
mockNativeDate.formatInTimezone(ts1, 'yyyy-MM-dd', tz) ===
948+
mockNativeDate.formatInTimezone(ts2, 'yyyy-MM-dd', tz)
949+
);
935950
},
936951
isSameMonthInTz: (ts1: number, ts2: number, tz: string) => {
937-
return mockNativeDate.formatInTimezone(ts1, 'yyyy-MM', tz) ===
938-
mockNativeDate.formatInTimezone(ts2, 'yyyy-MM', tz);
952+
return (
953+
mockNativeDate.formatInTimezone(ts1, 'yyyy-MM', tz) ===
954+
mockNativeDate.formatInTimezone(ts2, 'yyyy-MM', tz)
955+
);
939956
},
940957
isSameYearInTz: (ts1: number, ts2: number, tz: string) => {
941-
return mockNativeDate.formatInTimezone(ts1, 'yyyy', tz) ===
942-
mockNativeDate.formatInTimezone(ts2, 'yyyy', tz);
958+
return (
959+
mockNativeDate.formatInTimezone(ts1, 'yyyy', tz) ===
960+
mockNativeDate.formatInTimezone(ts2, 'yyyy', tz)
961+
);
943962
},
944963
startOfDayInTz: (ts: number, tz: string) => {
945964
const dateStr = mockNativeDate.formatInTimezone(ts, 'yyyy-MM-dd', tz);
946965
const utcMidnight = parseISO8601(dateStr + 'T00:00:00Z');
947966
const offsetMinutes = getTimezoneOffsetForDate(tz, utcMidnight);
948-
return utcMidnight - (offsetMinutes * 60 * 1000);
967+
return utcMidnight - offsetMinutes * 60 * 1000;
949968
},
950969
endOfDayInTz: (ts: number, tz: string) => {
951970
const nextDay = addToDate(ts, 1, 'day');
952971
const dateStr = mockNativeDate.formatInTimezone(nextDay, 'yyyy-MM-dd', tz);
953972
const utcMidnight = parseISO8601(dateStr + 'T00:00:00Z');
954973
const offsetMinutes = getTimezoneOffsetForDate(tz, utcMidnight);
955-
return utcMidnight - (offsetMinutes * 60 * 1000) - 1;
974+
return utcMidnight - offsetMinutes * 60 * 1000 - 1;
956975
},
957976

958977
// Async batch operations

packages/native-date/__tests__/timezone.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ describe('Timezone-Aware Predicates (InTz)', () => {
226226
it('should return midnight UTC for UTC timezone', () => {
227227
const date = parse('2024-06-15T14:30:00Z');
228228
const startOfDay = startOfDayInTz(date, 'UTC');
229-
const formatted = formatInTimezone(startOfDay, 'yyyy-MM-dd HH:mm:ss', 'UTC');
229+
const formatted = formatInTimezone(
230+
startOfDay,
231+
'yyyy-MM-dd HH:mm:ss',
232+
'UTC'
233+
);
230234
expect(formatted).toBe('2024-06-15 00:00:00');
231235
});
232236

@@ -254,7 +258,11 @@ describe('Timezone-Aware Predicates (InTz)', () => {
254258
it('should return end of day in specified timezone', () => {
255259
const date = parse('2024-06-15T14:30:00Z');
256260
const endOfDay = endOfDayInTz(date, 'UTC');
257-
const formatted = formatInTimezone(endOfDay, 'yyyy-MM-dd HH:mm:ss', 'UTC');
261+
const formatted = formatInTimezone(
262+
endOfDay,
263+
'yyyy-MM-dd HH:mm:ss',
264+
'UTC'
265+
);
258266
expect(formatted).toBe('2024-06-15 23:59:59');
259267
});
260268

packages/native-date/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,19 @@
8989
"@react-native/babel-preset": "0.81.1",
9090
"@react-native/eslint-config": "^0.81.1",
9191
"@types/react": "^19.1.0",
92+
"@typescript-eslint/eslint-plugin": "^8.53.1",
93+
"@typescript-eslint/parser": "^8.53.1",
9294
"commitlint": "^19.8.1",
9395
"del-cli": "^6.0.0",
9496
"eslint": "^9.35.0",
9597
"eslint-config-prettier": "^10.1.8",
9698
"eslint-plugin-eslint-comments": "^3.2.0",
99+
"eslint-plugin-ft-flow": "^3.0.11",
100+
"eslint-plugin-jest": "^29.12.1",
97101
"eslint-plugin-prettier": "^5.5.4",
102+
"eslint-plugin-react": "^7.37.5",
103+
"eslint-plugin-react-hooks": "^7.0.1",
104+
"eslint-plugin-react-native": "^5.0.0",
98105
"lefthook": "^2.0.3",
99106
"nitrogen": "^0.31.10",
100107
"prettier": "^2.8.8",

packages/native-date/src/NativeDate.nitro.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,21 @@ export interface NativeDate
129129
isTodayInTz(timestamp: number, timezone: string): boolean;
130130
isTomorrowInTz(timestamp: number, timezone: string): boolean;
131131
isYesterdayInTz(timestamp: number, timezone: string): boolean;
132-
isSameDayInTz(timestamp1: number, timestamp2: number, timezone: string): boolean;
133-
isSameMonthInTz(timestamp1: number, timestamp2: number, timezone: string): boolean;
134-
isSameYearInTz(timestamp1: number, timestamp2: number, timezone: string): boolean;
132+
isSameDayInTz(
133+
timestamp1: number,
134+
timestamp2: number,
135+
timezone: string
136+
): boolean;
137+
isSameMonthInTz(
138+
timestamp1: number,
139+
timestamp2: number,
140+
timezone: string
141+
): boolean;
142+
isSameYearInTz(
143+
timestamp1: number,
144+
timestamp2: number,
145+
timezone: string
146+
): boolean;
135147
startOfDayInTz(timestamp: number, timezone: string): number;
136148
endOfDayInTz(timestamp: number, timezone: string): number;
137149

packages/native-date/src/index.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,10 @@ export function getTimezoneOffsetForTimestamp(date: DateInput): number {
757757
return NativeDateModule.getTimezoneOffsetForTimestamp(toTimestamp(date));
758758
}
759759

760-
export function getOffsetInTimezone(date: DateInput, timezone: Timezone): number {
760+
export function getOffsetInTimezone(
761+
date: DateInput,
762+
timezone: Timezone
763+
): number {
761764
return NativeDateModule.getOffsetInTimezone(toTimestamp(date), timezone);
762765
}
763766

@@ -1149,13 +1152,21 @@ export function isToday(date: DateInput): boolean {
11491152
export function isTomorrow(date: DateInput): boolean {
11501153
const d = getComponents(date);
11511154
const tomorrow = getComponents(addDays(now(), 1));
1152-
return d.year === tomorrow.year && d.month === tomorrow.month && d.day === tomorrow.day;
1155+
return (
1156+
d.year === tomorrow.year &&
1157+
d.month === tomorrow.month &&
1158+
d.day === tomorrow.day
1159+
);
11531160
}
11541161

11551162
export function isYesterday(date: DateInput): boolean {
11561163
const d = getComponents(date);
11571164
const yesterday = getComponents(subDays(now(), 1));
1158-
return d.year === yesterday.year && d.month === yesterday.month && d.day === yesterday.day;
1165+
return (
1166+
d.year === yesterday.year &&
1167+
d.month === yesterday.month &&
1168+
d.day === yesterday.day
1169+
);
11591170
}
11601171

11611172
export function isPast(date: DateInput): boolean {
@@ -1320,7 +1331,15 @@ function fromComponentsLocal(components: {
13201331
millisecond = 0,
13211332
} = components;
13221333
// Use new Date() constructor which interprets as local time (month is 0-indexed)
1323-
return new Date(year, month - 1, day, hour, minute, second, millisecond).getTime();
1334+
return new Date(
1335+
year,
1336+
month - 1,
1337+
day,
1338+
hour,
1339+
minute,
1340+
second,
1341+
millisecond
1342+
).getTime();
13241343
}
13251344

13261345
// Setters (immutable - return new timestamp)

0 commit comments

Comments
 (0)