File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments