Skip to content

Commit

Permalink
Display the queue 1 hour before a canteen opens
Browse files Browse the repository at this point in the history
  • Loading branch information
marinovl7 committed Feb 1, 2023
1 parent adec7c2 commit 2427e4b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pages/[locale]/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ export default function CanteenPage({
}

const isCanteenOpen = (foodPlaces: FoodPlace[], id: string) => {
const now = dayjs()
// because now is with english locale and its one hour earlier as the german time
const now = dayjs().add(1, 'hour')
if (now.get('day') === 6 || now.get('day') === 0) return false
const foodPlace = foodPlaces.find((canteen) => canteen.canteen_id === id)
const foodPlaceOpeningHoursNow =
// eslint-disable-next-line no-unsafe-optional-chaining
foodPlace?.open_hours[`${daysArr[now?.get('day')! - 1]}` as keyof OpeningHoursType]
const foodPlaceOpens = foodPlaceOpeningHoursNow?.start
const foodPlaceCloses = foodPlaceOpeningHoursNow?.end
if (now.format('HH:mm') >= foodPlaceOpens! && now.format('HH:mm') < foodPlaceCloses!) {
const foodPlaceOpens = foodPlaceOpeningHoursNow?.start!
const foodPlaceCloses = foodPlaceOpeningHoursNow?.end!
const time = foodPlaceOpens.split(':')
const hour = (parseInt(time[0], 10) - 1 + 24) % 24
const foodPlaceOpensMinusOne = `${hour < 10 ? `0${hour}` : hour}:${time[1]}`
if (now.format('HH:mm') >= foodPlaceOpensMinusOne && now.format('HH:mm') < foodPlaceCloses) {
return true
}
return false
Expand Down

0 comments on commit 2427e4b

Please sign in to comment.