import { startOfDay } from "date-fns" ; import { format , utcToZonedTime , zonedTimeToUtc } from "date-fns-tz" ; import { API } from "../../types" ; import { gameQuery as query } from "./query" ; function getEstString ( date ) { const dateUTC = zonedTimeToUtc ( startOfDay ( date ) , Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ) ; const dateEST = utcToZonedTime ( dateUTC , "EST" ) ; return format ( dateEST , "yyyyMMdd" ) ; } export async function getCurrentGames ( loader ) { loader . push ( ) ; const { data } = await fetch ( "https://nba.rickyg.io/v1/graphql" , { method : "POST" , headers : { "Content-Type" : "application/json" , } , body : JSON . stringify ( { query : query ( getEstString ( new Date ( ) ) ) } ) , } ) . then ( ( res ) => res . json ( ) ) . finally ( ( ) => loader . pop ( ) ) ; return { timestamp : Date . now ( ) , games : data ? data . schedule : [ ] } ; }