This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/helpers/time/calculateNearestHours.ts
konrad c45911fd36
All checks were successful
continuous-integration/drone/push Build is passing
Fix date parsing parsing words with weekdays in them (#607)
Co-authored-by: kolaente <k@knt.li>
Reviewed-on: #607
Co-authored-by: konrad <konrad@kola-entertainments.de>
Co-committed-by: konrad <konrad@kola-entertainments.de>
2021-07-25 10:45:17 +00:00

24 lines
441 B
TypeScript

export function calculateNearestHours(currentDate: Date = new Date()): number {
if (currentDate.getHours() <= 9 || currentDate.getHours() > 21) {
return 9
}
if (currentDate.getHours() <= 12) {
return 12
}
if (currentDate.getHours() <= 15) {
return 15
}
if (currentDate.getHours() <= 18) {
return 18
}
if (currentDate.getHours() <= 21) {
return 21
}
// Same case as in the first if, will never be called
return 9
}