chore: more timing precision

This commit is contained in:
Cory Dransfeldt 2023-10-30 16:30:19 -07:00
parent 6272964888
commit a069db8671

View file

@ -113,16 +113,21 @@ export default async () => {
}) })
const isCorrectDate = const isCorrectDate =
now.split(',')[0] === startTime.split(',')[0] && now.split(',')[0] === endTime.split(',')[0] now.split(',')[0] === startTime.split(',')[0] && now.split(',')[0] === endTime.split(',')[0]
const nowHour = parseInt(now.split(',')[1].split(':')[0].trim()) const nowHour = parseInt(now.split(',')[1].split(':')[0].trim())
const startHour = parseInt(startTime.split(',')[1].split(':')[0].trim()) const startHour = parseInt(startTime.split(',')[1].split(':')[0].trim())
const endHour = parseInt(endTime.split(',')[1].split(':')[0].trim()) const endHour = parseInt(endTime.split(',')[1].split(':')[0].trim())
const nowMinutes = parseInt(now.split(',')[1].split(':')[1].trim())
if (isCorrectDate && nowHour >= startHour && nowHour <= endHour) { const startMinutes = parseInt(startTime.split(',')[1].split(':')[1].trim())
return Response.json({ const endMinutes = parseInt(endTime.split(',')[1].split(':')[1].trim())
const res = {
text: `🏀 ${game['awayTeam']['teamName']} (${game['awayTeam']['wins']}-${game['awayTeam']['losses']}) @ ${game['homeTeam']['teamName']} (${game['homeTeam']['wins']}-${game['homeTeam']['losses']})`, text: `🏀 ${game['awayTeam']['teamName']} (${game['awayTeam']['wins']}-${game['awayTeam']['losses']}) @ ${game['homeTeam']['teamName']} (${game['homeTeam']['wins']}-${game['homeTeam']['losses']})`,
html: `🏀 ${game['awayTeam']['teamName']} (${game['awayTeam']['wins']}-${game['awayTeam']['losses']}) @ ${game['homeTeam']['teamName']} (${game['homeTeam']['wins']}-${game['homeTeam']['losses']})`, html: `🏀 ${game['awayTeam']['teamName']} (${game['awayTeam']['wins']}-${game['awayTeam']['losses']}) @ ${game['homeTeam']['teamName']} (${game['homeTeam']['wins']}-${game['homeTeam']['losses']})`,
}) }
if (isCorrectDate) {
if (nowHour === startHour && nowMinutes >= startMinutes && nowHour < endHour) return Response.json(res)
if (nowHour > startHour && nowHour < endHour) return Response.json(res)
if (nowHour > startHour && nowMinutes <= endMinutes && nowHour == endHour) return Response.json(res)
} }
} }
} }