Skip to content

Commit 943e902

Browse files
Update seed.ts
1 parent b4b5da1 commit 943e902

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

prisma/seed/seed.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,28 @@ const main = async () => {
151151
}))
152152
);
153153

154+
const isESTWeekday = (date: Date): boolean => {
155+
const weekdayInEST = new Intl.DateTimeFormat('en-US', {
156+
timeZone: 'America/New_York',
157+
weekday: 'short',
158+
}).format(date);
159+
160+
return !['Sat', 'Sun'].includes(weekdayInEST);
161+
};
162+
154163
const generateWeekdayFutureDate = (): Date => {
155164
let date: Date;
156165
do {
157166
date = faker.date.future({ years: 2 });
158-
// Set time to noon to avoid timezone shifts affecting the weekday
159-
date.setHours(12, 0, 0, 0);
160-
} while (date.getDay() === 0 || date.getDay() === 6);
167+
} while (!isESTWeekday(date));
161168
return date;
162169
};
163170

164171
const generateWeekdayPastDate = (): Date => {
165172
let date: Date;
166173
do {
167174
date = faker.date.past({ years: 2 });
168-
// Set time to noon to avoid timezone shifts affecting the weekday
169-
date.setHours(12, 0, 0, 0);
170-
} while (date.getDay() === 0 || date.getDay() === 6);
175+
} while (!isESTWeekday(date));
171176
return date;
172177
};
173178

0 commit comments

Comments
 (0)