fix: account for am/pm

This commit is contained in:
Cory Dransfeldt 2023-11-01 09:27:30 -07:00
parent 3316e17dff
commit aed45ed1bb

View file

@ -106,11 +106,16 @@ export default async () => {
const endTime = new Date(endDate).toLocaleString('en-US', {
timeZone: 'America/Los_Angeles',
})
const now = new Date().toLocaleString('en-US', {
const nowDate = new Date()
const now = nowDate.toLocaleString('en-US', {
timeZone: 'America/Los_Angeles',
})
const startAmPm = startDate.getHours() >= 12 ? 'pm' : 'am'
const nowAmPm = nowDate.getHours() >= 12 ? 'pm' : 'am'
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] &&
startAmPm === nowAmPm
const nowHour = parseInt(now.split(',')[1].split(':')[0].trim())
const startHour = parseInt(startTime.split(',')[1].split(':')[0].trim())
const endHour = parseInt(endTime.split(',')[1].split(':')[0].trim())